diff options
Diffstat (limited to 'public/admin/controller/extension')
160 files changed, 43387 insertions, 0 deletions
diff --git a/public/admin/controller/extension/advertise/google.php b/public/admin/controller/extension/advertise/google.php new file mode 100644 index 0000000..fa24904 --- /dev/null +++ b/public/admin/controller/extension/advertise/google.php @@ -0,0 +1,2089 @@ +<?php + +use \googleshopping\exception\Connection as ConnectionException; +use \googleshopping\Googleshopping; +use \googleshopping\traits\LibraryLoader; +use \googleshopping\traits\StoreLoader; + +class ControllerExtensionAdvertiseGoogle extends Controller { + use StoreLoader; + use LibraryLoader; + + private $error = array(); + private $store_id = 0; + + public function __construct($registry) { + parent::__construct($registry); + + $this->store_id = isset($this->request->get['store_id']) ? (int)$this->request->get['store_id'] : 0; + + $this->loadStore($this->store_id); + + $this->loadLibrary($this->store_id); + } + + public function index() { + $this->load->language('extension/advertise/google'); + + $this->load->model('extension/advertise/google'); + + $this->load->config('googleshopping/googleshopping'); + + // Fix clashes with third-party extension table names + $this->model_extension_advertise_google->renameTables(); + + // Even though this should be ran during install, there are known cases of webstores which do not trigger the install method. This is why we run createTables here explicitly. + $this->model_extension_advertise_google->createTables(); + + // Fix a missing AUTO_INCREMENT + $this->model_extension_advertise_google->fixColumns(); + + // Redirect to the preliminary check-list + if (!$this->setting->get('advertise_google_checklist_confirmed')) { + $this->response->redirect($this->url->link('extension/advertise/google/checklist', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + try { + // If we have not connected, navigate to connect screen + if (!$this->setting->has('advertise_google_access_token')) { + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (!$this->setting->has('advertise_google_gmc_account_selected')) { + // In case the merchant has made no decision about which GMC account to use, redirect to the form for connection + $this->response->redirect($this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (!$this->googleshopping->isStoreUrlClaimed()) { + if (empty($this->session->data['error'])) { + $this->session->data['error'] = $this->language->get('error_store_url_claim'); + } + + // In case the merchant has made no decision about which GMC account to use, redirect to the form for connection + $this->response->redirect($this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (count($this->googleshopping->getTargets($this->store_id)) == 0) { + $this->response->redirect($this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (!$this->setting->has('advertise_google_gmc_shipping_taxes_configured')) { + // In case the merchant has not set up shipping and taxes, redirect them to the form for shipping and taxes + $this->response->redirect($this->url->link('extension/advertise/google/shipping_taxes', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else if (count($this->model_extension_advertise_google->getMapping($this->store_id)) == 0) { + // In case the merchant has not set up mapping, redirect them to the form for mapping + $this->response->redirect($this->url->link('extension/advertise/google/mapping', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + // Pull the campaign reports + $this->googleshopping->getCampaignReports(); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateSettings()) { + $this->applyNewSettings($this->request->post); + + try { + // Profilactic target push, as sometimes targets are not initialized properly + $this->googleshopping->pushTargets(); + $this->googleshopping->pushCampaignStatus(); + + $this->session->data['success'] = $this->language->get('success_index'); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + $this->document->setTitle($this->language->get('heading_title')); + + $data = array(); + + $data['text_connected'] = sprintf($this->language->get('text_connected'), $this->setting->get('advertise_google_gmc_account_id')); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['error_cron_email'] = $this->getValidationError('cron_email'); + $data['error_cron_acknowledge'] = $this->getValidationError('cron_acknowledge'); + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $advertised_count = $this->model_extension_advertise_google->getAdvertisedCount($this->store_id); + $last_cron_executed = (int)$this->setting->get('advertise_google_cron_last_executed'); + + $data['warning'] = ''; + + if (!$this->setting->get('advertise_google_status') && $this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $data['warning'] = $this->language->get('warning_disabled'); + } else if (!$this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $data['warning'] = sprintf($this->language->get('warning_no_active_campaigns'), $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true)); + } else if ($advertised_count == 0) { + $data['warning'] = sprintf($this->language->get("warning_no_advertised_products"), $this->language->get("text_video_tutorial_url_advertise")); + } else if ($last_cron_executed + 24 * 60 * 60 <= time()) { + $data['warning'] = sprintf($this->language->get("warning_last_cron_executed"), $this->language->get("text_tutorial_cron")); + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + $reporting_intervals = $this->config->get('advertise_google_reporting_intervals'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + $data['action'] = $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + $data['shipping_taxes'] = $this->url->link('extension/advertise/google/shipping_taxes', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true); + $data['campaign'] = $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true); + $data['mapping'] = $this->url->link('extension/advertise/google/mapping', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true); + $data['disconnect'] = $this->url->link('extension/advertise/google/disconnect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + $data['list_ads'] = html_entity_decode($this->url->link('extension/advertise/google/list_ads', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['advertise'] = html_entity_decode($this->url->link('extension/advertise/google/advertise', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_popup'] = html_entity_decode($this->url->link('extension/advertise/google/popup_product', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_category_autocomplete'] = html_entity_decode($this->url->link('extension/advertise/google/category_autocomplete', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_debug_log_download'] = html_entity_decode($this->url->link('extension/advertise/google/debug_log_download', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + + $data['advertise_google_status'] = $this->getSettingValue('advertise_google_status', 0); + $data['advertise_google_debug_log'] = $this->getSettingValue('advertise_google_debug_log', 0); + $data['advertise_google_cron_email_status'] = $this->getSettingValue('advertise_google_cron_email_status'); + $data['advertise_google_cron_email'] = $this->getSettingValue('advertise_google_cron_email', $this->config->get('config_email')); + $data['advertise_google_cron_token'] = $this->getSettingValue('advertise_google_cron_token'); + $data['advertise_google_cron_acknowledge'] = $this->getSettingValue('advertise_google_cron_acknowledge', null, true); + + if (isset($this->request->post['advertise_google_reporting_interval'])) { + $data['advertise_google_reporting_interval'] = $this->request->post['advertise_google_reporting_interval']; + } else if ($this->setting->has('advertise_google_reporting_interval') && in_array($this->setting->get('advertise_google_reporting_interval'), $reporting_intervals)) { + $data['advertise_google_reporting_interval'] = $this->setting->get('advertise_google_reporting_interval'); + } else { + $data['advertise_google_reporting_interval'] = $this->config->get('advertise_google_reporting_intervals_default'); + } + + $server = $this->googleshopping->getStoreUrl(); + + $data['advertise_google_cron_command'] = 'export CUSTOM_SERVER_NAME=' . parse_url($server, PHP_URL_HOST) . '; export CUSTOM_SERVER_PORT=443; export ADVERTISE_GOOGLE_CRON=1; export ADVERTISE_GOOGLE_STORE_ID=' . $this->store_id . '; ' . PHP_BINDIR . '/php -d session.save_path=' . session_save_path() . ' -d memory_limit=256M ' . DIR_SYSTEM . 'library/googleshopping/cron.php > /dev/null 2> /dev/null'; + + if (!$this->setting->get('advertise_google_cron_token')) { + $data['advertise_google_cron_token'] = md5(mt_rand()); + } + + $host_and_uri = parse_url($server, PHP_URL_HOST) . parse_url($server, PHP_URL_PATH); + + $data['advertise_google_cron_url'] = 'https://' . rtrim($host_and_uri, '/') . '/index.php?route=extension/advertise/google/cron&cron_token={CRON_TOKEN}'; + + $data['reporting_intervals'] = array(); + + foreach ($reporting_intervals as $interval) { + $data['reporting_intervals'][$interval] = $this->language->get('text_reporting_interval_' . $interval); + } + + $campaign_reports = $this->setting->get('advertise_google_report_campaigns'); + + $data['campaigns'] = $this->googleshopping->getTargets($this->store_id); + + $data['text_report_date_range'] = sprintf($this->language->get('text_report_date_range'), $campaign_reports['date_range']); + $data['text_ads_intro'] = sprintf($this->language->get('text_ads_intro'), $data['shipping_taxes']); + $data['advertise_google_report_campaigns'] = $campaign_reports['reports']; + $data['text_panel_heading'] = sprintf($this->language->get('text_panel_heading'), $this->googleshopping->getStoreName()); + + $data['text_selection_all'] = str_replace("'", "\\'", $this->language->get('text_selection_all')); + $data['text_selection_page'] = str_replace("'", "\\'", $this->language->get('text_selection_page')); + + $data['tab_settings'] = $this->load->view('extension/advertise/google_settings', $data); + $data['tab_ads'] = $this->load->view('extension/advertise/google_ads', $data); + $data['tab_reports'] = $this->load->view('extension/advertise/google_reports', $data); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/advertise/google', $data)); + } + + public function debug_log_download() { + $filename = sprintf(Googleshopping::DEBUG_LOG_FILENAME, $this->store_id); + + header('Pragma: no-cache'); + header('Expires: 0'); + header('Content-Description: File Transfer'); + header('Content-Type: plain/text'); + header('Content-Disposition: attachment; filename="' . $filename . '"'); + header('Content-Transfer-Encoding: binary'); + + $file = DIR_LOGS . $filename; + + if (file_exists($file)) { + readfile($file); + } + + exit; + } + + public function advertise() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'success' => null, + 'redirect' => null, + 'error' => null, + 'warning' => null + ); + + if ($this->validatePermission()) { + $this->load->model('extension/advertise/google'); + + $select = array(); + $filter_data = array(); + + if (!empty($this->request->post['all_pages'])) { + $filter_data = $this->getFilter($this->request->post['filter']); + } else if (isset($this->request->post['select']) && is_array($this->request->post['select'])) { + $select = $this->request->post['select']; + } + + if (!empty($select) || !empty($filter_data)) { + $target_ids = !empty($this->request->post['target_ids']) ? $this->request->post['target_ids'] : array(); + + if (!empty($select)) { + $this->model_extension_advertise_google->setAdvertisingBySelect($select, $target_ids, $this->store_id); + } else if (!empty($filter_data)) { + $this->model_extension_advertise_google->setAdvertisingByFilter($filter_data, $target_ids, $this->store_id); + } + + if (!empty($target_ids)) { + $json['success'] = $this->language->get('success_advertise_listed'); + } else { + $json['success'] = $this->language->get('success_advertise_unlisted'); + } + } + } else { + $json['error'] = $this->error['warning']; + } + + // Refresh warnings + $advertised_count = $this->model_extension_advertise_google->getAdvertisedCount($this->store_id); + $last_cron_executed = (int)$this->setting->get('advertise_google_cron_last_executed'); + + if (!$this->setting->get('advertise_google_status') && $this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $json['warning'] = $this->language->get('warning_disabled'); + } else if (!$this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $json['warning'] = sprintf($this->language->get('warning_no_active_campaigns'), $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true)); + } else if ($advertised_count == 0) { + $json['warning'] = sprintf($this->language->get("warning_no_advertised_products"), $this->language->get("text_video_tutorial_url_advertise")); + } else if ($last_cron_executed + 24 * 60 * 60 <= time()) { + $json['warning'] = sprintf($this->language->get("warning_last_cron_executed"), $this->language->get("text_tutorial_cron")); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function list_ads() { + $json = array(); + + $this->load->model('extension/advertise/google'); + + $this->model_extension_advertise_google->insertNewProducts(array(), $this->store_id); + + $this->load->language('extension/advertise/google'); + + $page = (int)$this->request->post['page']; + + $filter_data = array( + 'sort' => $this->request->post['sort'], + 'order' => $this->request->post['order'], + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $filter_data = array_merge($filter_data, $this->getFilter($this->request->post['filter'])); + + $products = $this->googleshopping->getProducts($filter_data, $this->store_id); + + $json['products'] = array_map(array($this, 'product'), $products); + + $product_total = $this->googleshopping->getTotalProducts($filter_data, $this->store_id); + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $this->request->post['page']; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = '{page}'; + + $pages = ceil($product_total / $this->config->get('config_limit_admin')); + + $json['showing'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, $pages); + + $json['pagination'] = $pagination->render(); + $json['total'] = (int)$product_total; + $json['pages'] = (int)$pages; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function merchant() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_merchant')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validatePermission()) { + try { + $redirect_uri = html_entity_decode($this->url->link('extension/advertise/google/callback_merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $state = md5(microtime(true) . $redirect_uri . microtime(true)); + + $auth_url_data = array( + 'account_type' => $this->request->post['advertise_google_gmc_account_type'], + 'redirect_uri' => $redirect_uri . '&state=' . $state + ); + + $this->session->data['advertise_google'] = $auth_url_data; + $this->session->data['advertise_google']['state'] = $state; + + $this->response->redirect($this->googleshopping->getMerchantAuthUrl($auth_url_data)); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + $data['action'] = $this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['advertise_google_gmc_account_type'])) { + $data['advertise_google_gmc_account_type'] = $this->request->post['advertise_google_gmc_account_type']; + } else { + $data['advertise_google_gmc_account_type'] = 'api'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['current_step'] = 2; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_merchant', $data)); + } + + public function shipping_taxes() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_shipping_taxes')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + $this->load->config('googleshopping/googleshopping'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateShippingAndTaxes()) { + try { + $this->applyNewSettings($this->request->post); + + $this->googleshopping->pushShippingAndTaxes(); + + $this->applyNewSettings(array( + 'advertise_google_gmc_shipping_taxes_configured' => '1' + )); + + $this->session->data['success'] = $this->language->get('success_shipping_taxes'); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + $available_carriers = array(); + + try { + $available_carriers = $this->googleshopping->getAvailableCarriers(); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + if (isset($this->error['min_transit_time'])) { + $data['error_min_transit_time'] = $this->error['min_transit_time']; + } else { + $data['error_min_transit_time'] = ''; + } + + if (isset($this->error['max_transit_time'])) { + $data['error_max_transit_time'] = $this->error['max_transit_time']; + } else { + $data['error_max_transit_time'] = ''; + } + + if (isset($this->error['flat_rate'])) { + $data['error_flat_rate'] = $this->error['flat_rate']; + } else { + $data['error_flat_rate'] = ''; + } + + if (isset($this->error['carrier_postcode'])) { + $data['error_carrier_postcode'] = $this->error['carrier_postcode']; + } else { + $data['error_carrier_postcode'] = ''; + } + + if (isset($this->error['carrier_price_percentage'])) { + $data['error_carrier_price_percentage'] = $this->error['carrier_price_percentage']; + } else { + $data['error_carrier_price_percentage'] = ''; + } + + if (isset($this->error['carrier'])) { + $data['error_carrier'] = $this->error['carrier']; + } else { + $data['error_carrier'] = ''; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['from_dashboard'] = isset($this->request->get['from_dashboard']); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + if ($data['from_dashboard']) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_shipping_taxes'), + 'href' => $this->url->link('extension/advertise/google/shipping_taxes', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true), + ); + } + + if ($data['from_dashboard']) { + $data['cancel'] = $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + } else { + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + } + + $data['action'] = $this->url->link('extension/advertise/google/shipping_taxes', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['advertise_google_shipping_taxes'])) { + $data['advertise_google_shipping_taxes'] = $this->request->post['advertise_google_shipping_taxes']; + } else if ($this->setting->has('advertise_google_shipping_taxes')) { + $data['advertise_google_shipping_taxes'] = $this->setting->get('advertise_google_shipping_taxes'); + } else { + $data['advertise_google_shipping_taxes'] = array( + 'shipping_type' => 'flat', + 'flat_rate' => $this->config->get('shipping_flat_cost'), + 'min_transit_time' => 1, + 'max_transit_time' => 14, + 'carrier_price_percentage' => 5, + 'tax_type' => $this->config->get('config_country_id') == 223 ? 'usa' : 'not_usa' + ); + } + + $data['available_carriers'] = $available_carriers; + + $data['states'] = $this->config->get('advertise_google_tax_usa_states'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['current_step'] = 4; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_shipping_taxes', $data)); + } + + public function mapping() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_mapping')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateMapping()) { + try { + foreach ($this->request->post['advertise_google_mapping'] as $google_product_category => $category_id) { + $this->model_extension_advertise_google->setCategoryMapping($google_product_category, $this->store_id, $category_id); + } + + if (!empty($this->request->post['advertise_google_modify_existing'])) { + $this->model_extension_advertise_google->updateGoogleProductCategoryMapping($this->store_id); + } + + $this->session->data['success'] = $this->language->get('success_mapping'); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->error['warning'] = $e->getMessage(); + } + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['from_dashboard'] = isset($this->request->get['from_dashboard']); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + if ($data['from_dashboard']) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_shipping_taxes'), + 'href' => $this->url->link('extension/advertise/google/mapping', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true), + ); + } + + $this->load->config('googleshopping/googleshopping'); + + $data['mapping'] = array(); + + foreach ($this->config->get('advertise_google_google_product_categories') as $google_product_category_id => $google_product_category_name) { + if ($google_product_category_id == 0) continue; + + $category_id = ''; + $name = ''; + + if (null !== $category = $this->model_extension_advertise_google->getMappedCategory($google_product_category_id, $this->store_id)) { + $category_id = $category['category_id']; + $name = $category['name']; + } + + $map = array( + 'google_product_category' => array( + 'id' => $google_product_category_id, + 'name' => $google_product_category_name + ), + 'oc_category' => array( + 'category_id' => $category_id, + 'name' => $name + ) + ); + + $data['mapping'][] = $map; + } + + $data['mapping_json'] = json_encode($data['mapping']); + + if ($data['from_dashboard']) { + $data['cancel'] = $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + } else { + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + } + + $data['action'] = $this->url->link('extension/advertise/google/mapping', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['url_mapping_verify'] = html_entity_decode($this->url->link('extension/advertise/google/mapping_verify', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_category_autocomplete'] = html_entity_decode($this->url->link('extension/advertise/google/category_autocomplete', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['current_step'] = 5; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_mapping', $data)); + } + + public function mapping_verify() { + $this->load->language('extension/advertise/google'); + + $this->load->model('extension/advertise/google'); + + $data = array(); + + $json = array( + 'submit_directly' => !$this->model_extension_advertise_google->isAnyProductCategoryModified($this->store_id), + 'modal_confirmation' => $this->load->view('extension/advertise/google_mapping_verify', $data) + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function campaign_test() { + $json = array( + 'status' => false, + 'redirect' => null, + 'error' => null + ); + + if ($this->validatePermission()) { + try { + $json['status'] = $this->googleshopping->testCampaigns(); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $json['redirect'] = html_entity_decode($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + } catch (\RuntimeException $e) { + $json['status'] = false; + $json['error'] = $e->getMessage(); + } + + $this->applyNewSettings(array( + 'advertise_google_can_edit_campaigns' => (int)$json['status'] + )); + } else { + $json['error'] = $this->error['warning']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function campaign() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_campaign')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateCampaign()) { + $this->applyNewSettings($this->request->post); + + // If there is no redirect from the push of targets, go back to the extension dashboard + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['warning'] = ''; + + if (!$this->setting->get('advertise_google_status') && $this->model_extension_advertise_google->hasActiveTarget($this->store_id)) { + $data['warning'] = $this->language->get('warning_paused_targets'); + } + + $data['from_dashboard'] = isset($this->request->get['from_dashboard']); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + if ($data['from_dashboard']) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_campaign'), + 'href' => $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&from_dashboard=true', true), + ); + } + + if (isset($this->request->post['advertise_google_auto_advertise'])) { + $data['advertise_google_auto_advertise'] = $this->request->post['advertise_google_auto_advertise']; + } else if ($this->setting->has('advertise_google_auto_advertise')) { + $data['advertise_google_auto_advertise'] = $this->setting->get('advertise_google_auto_advertise'); + } else { + $data['advertise_google_auto_advertise'] = '0'; + } + + if ($data['from_dashboard']) { + $data['cancel'] = $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + } else { + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + } + + $data['action'] = $this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + $data['target_add'] = html_entity_decode($this->url->link('extension/advertise/google/target_add', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['target_edit'] = html_entity_decode($this->url->link('extension/advertise/google/target_edit', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&advertise_google_target_id={target_id}', true), ENT_QUOTES, 'UTF-8'); + $data['target_delete'] = html_entity_decode($this->url->link('extension/advertise/google/target_delete', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&advertise_google_target_id={target_id}', true), ENT_QUOTES, 'UTF-8'); + $data['target_list'] = html_entity_decode($this->url->link('extension/advertise/google/target_list', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['url_campaign_test'] = html_entity_decode($this->url->link('extension/advertise/google/campaign_test', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $data['can_edit_campaigns'] = (bool)$this->setting->get('advertise_google_can_edit_campaigns'); + $data['text_roas_warning'] = sprintf($this->language->get('warning_roas'), date($this->language->get('date_format_long'), time() + Googleshopping::ROAS_WAIT_INTERVAL)); + + $data['json_allowed_targets'] = json_encode($this->model_extension_advertise_google->getAllowedTargets()); + + $targets = $this->googleshopping->getTargets($this->store_id); + + foreach ($targets as &$target) { + if (!$target['roas_status']) { + $target['roas_warning'] = sprintf($this->language->get('warning_roas'), date($this->language->get('date_format_long'), $target['roas_available_on'])); + } else { + $target['roas_warning'] = null; + } + } + + $data['targets'] = $targets; + $data['json_targets'] = json_encode($targets); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['current_step'] = 3; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_campaign', $data)); + } + + public function target_add() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'success' => null, + 'redirect' => null, + 'error' => null + ); + + if ($this->validatePermission()) { + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateTarget()) { + $this->load->model('extension/advertise/google'); + + $target = array( + 'store_id' => $this->store_id, + 'campaign_name' => str_replace(',', ',', trim($this->request->post['campaign_name'])), + 'country' => $this->request->post['country'], + 'status' => $this->request->post['status'] == 'active' ? 'active' : 'paused', + 'budget' => (float)preg_replace('~[^0-9\.]~i', '', $this->request->post['budget']), + 'roas' => isset($this->request->post['roas']) ? (int)$this->request->post['roas'] : 0, + 'feeds' => array_values($this->request->post['feed']) + ); + + $this->model_extension_advertise_google->addTarget($target, $this->store_id); + + try { + $this->googleshopping->pushTargets(); + + $json['success'] = $this->language->get('success_target_add'); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $json['redirect'] = html_entity_decode($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + } catch (\RuntimeException $e) { + $json['error'] = $e->getMessage(); + } + } else { + $json['error'] = $this->error['warning']; + + if (isset($this->error['campaign_name'])) { + $json['error_campaign_name'] = $this->error['campaign_name']; + } + + if (isset($this->error['country'])) { + $json['error_country'] = $this->error['country']; + } + + if (isset($this->error['budget'])) { + $json['error_budget'] = $this->error['budget']; + } + + if (isset($this->error['feed'])) { + $json['error_feed'] = $this->error['feed']; + } + } + } else { + $json['error'] = $this->error['warning']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function target_edit() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'success' => null, + 'redirect' => null, + 'error' => null + ); + + if ($this->validatePermission()) { + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateTarget()) { + $this->load->model('extension/advertise/google'); + + $target = array( + 'campaign_name' => str_replace(',', ',', trim($this->request->post['campaign_name'])), + 'country' => $this->request->post['country'], + 'status' => $this->request->post['status'] == 'active' ? 'active' : 'paused', + 'budget' => (float)preg_replace('~[^0-9\.]~i', '', $this->request->post['budget']), + 'roas' => isset($this->request->post['roas']) ? (int)$this->request->post['roas'] : 0, + 'feeds' => array_values($this->request->post['feed']) + ); + + $this->googleshopping->editTarget((int)$this->request->get['advertise_google_target_id'], $target); + + try { + $this->googleshopping->pushTargets(); + + $json['success'] = $this->language->get('success_target_edit'); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $json['redirect'] = html_entity_decode($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + } catch (\RuntimeException $e) { + $json['error'] = $e->getMessage(); + } + } else { + $json['error'] = $this->error['warning']; + + if (isset($this->error['campaign_name'])) { + $json['error_campaign_name'] = $this->error['campaign_name']; + } + + if (isset($this->error['country'])) { + $json['error_country'] = $this->error['country']; + } + + if (isset($this->error['budget'])) { + $json['error_budget'] = $this->error['budget']; + } + + if (isset($this->error['feed'])) { + $json['error_feed'] = $this->error['feed']; + } + } + } else { + $json['error'] = $this->error['warning']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function target_delete() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'success' => null, + 'redirect' => null, + 'error' => null + ); + + if ($this->validatePermission()) { + $this->load->model('extension/advertise/google'); + + $advertise_google_target_id = (int)$this->request->get['advertise_google_target_id']; + + $target_info = $this->googleshopping->getTarget($advertise_google_target_id); + + if (!empty($target_info)) { + try { + $this->googleshopping->deleteCampaign($target_info['campaign_name']); + + $this->googleshopping->deleteTarget($advertise_google_target_id); + + $json['success'] = $this->language->get('success_target_delete'); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $json['redirect'] = html_entity_decode($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + } catch (\RuntimeException $e) { + $json['error'] = $e->getMessage(); + } + } + } else { + $json['error'] = $this->error['warning']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function target_list() { + $this->load->language('extension/advertise/google'); + + $json = array( + 'targets' => null, + 'error' => null + ); + + $this->load->model('extension/advertise/google'); + + $targets = $this->googleshopping->getTargets($this->store_id); + + foreach ($targets as &$target) { + if (!$target['roas_status']) { + $target['roas_warning'] = sprintf($this->language->get('warning_roas'), date($this->language->get('date_format_long'), $target['roas_available_on'])); + } else { + $target['roas_warning'] = null; + } + } + + $json['targets'] = $targets; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function callback_merchant() { + $state_verified = + !empty($this->session->data['advertise_google']['state']) && + !empty($this->request->get['state']) && + $this->request->get['state'] == $this->session->data['advertise_google']['state']; + + $error = isset($this->request->get['error']) ? $this->request->get['error'] : null; + $merchant_id = isset($this->request->get['merchant_id']) ? $this->request->get['merchant_id'] : null; + + if ($state_verified && is_null($error)) { + $this->load->language('extension/advertise/google'); + + try { + $this->googleshopping->verifySite(); + + $this->load->model('user/user'); + $user_info = $this->model_user_user->getUser($this->user->getId()); + + $this->applyNewSettings(array( + 'advertise_google_gmc_account_selected' => true, + 'advertise_google_gmc_account_id' => $merchant_id, + 'advertise_google_gmc_account_accepted_by' => array( + 'user_id' => $user_info['user_id'], + 'user_group_id' => $user_info['user_group_id'], + 'user_group' => $user_info['user_group'], + 'username' => $user_info['username'], + 'firstname' => $user_info['firstname'], + 'lastname' => $user_info['lastname'], + 'email' => $user_info['email'], + 'ip' => $user_info['ip'] + ), + 'advertise_google_gmc_account_accepted_at' => time(), + 'advertise_google_conversion_tracker' => $this->googleshopping->getConversionTracker(), + 'advertise_google_can_edit_campaigns' => '0' + )); + + if ($this->session->data['advertise_google']['account_type'] == 'api') { + $this->session->data['success'] = sprintf($this->language->get('success_merchant_access'), $merchant_id); + } else { + $this->session->data['success'] = $this->language->get('success_merchant'); + } + + if (count($this->googleshopping->getTargets($this->store_id)) > 0) { + $this->response->redirect($this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + unset($this->session->data['advertise_google']); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->session->data['error'] = $e->getMessage(); + } + } else if (!is_null($error)) { + $this->session->data['error'] = $error; + + $setting = $this->model_setting_setting->getSetting('advertise_google', $this->store_id); + + unset($setting['advertise_google_status']); + unset($setting['advertise_google_work']); + unset($setting['advertise_google_gmc_account_selected']); + unset($setting['advertise_google_gmc_shipping_taxes_configured']); + unset($setting['advertise_google_can_edit_campaigns']); + + $this->model_setting_setting->editSetting('advertise_google', $setting, $this->store_id); + } + + unset($this->session->data['advertise_google']); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + public function callback_connect() { + $state_verified = + !empty($this->session->data['advertise_google']['state']) && + !empty($this->request->get['state']) && + $this->request->get['state'] == $this->session->data['advertise_google']['state']; + + if ($state_verified) { + $this->load->language('extension/advertise/google'); + + $this->load->model('extension/advertise/google'); + + try { + $access = $this->googleshopping->access($this->session->data['advertise_google'], urldecode($this->request->get['code'])); + + $this->applyNewSettings(array( + 'advertise_google_app_id' => $this->session->data['advertise_google']['app_id'], + 'advertise_google_app_secret' => $this->session->data['advertise_google']['app_secret'], + 'advertise_google_status' => $this->session->data['advertise_google']['status'], + 'advertise_google_cron_token' => $this->session->data['advertise_google']['cron_token'], + 'advertise_google_cron_acknowledge' => $this->session->data['advertise_google']['cron_acknowledge'], + 'advertise_google_cron_email' => $this->session->data['advertise_google']['cron_email'], + 'advertise_google_cron_email_status' => $this->session->data['advertise_google']['cron_email_status'], + 'advertise_google_access_token' => $access['access_token'], + 'advertise_google_refresh_token' => $access['refresh_token'] + )); + + $this->session->data['success'] = $this->language->get('success_connect'); + + if (count($this->googleshopping->getTargets($this->store_id)) > 0 && $this->setting->get('advertise_google_gmc_account_selected')) { + $this->response->redirect($this->url->link('extension/advertise/google/campaign', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->session->data['error'] = $e->getMessage(); + } + } else if (isset($this->request->get['error'])) { + $this->session->data['error'] = $this->request->get['error']; + } + + unset($this->session->data['advertise_google']); + + if ($this->setting->get('advertise_google_gmc_account_selected')) { + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } else { + $this->response->redirect($this->url->link('extension/advertise/google/merchant', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + } + + public function connect() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->document->addStyle('view/stylesheet/googleshopping/stepper.css'); + + $this->load->model('extension/advertise/google'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validateSettings() && $this->validateConnect()) { + unset($this->session->data['advertise_google']); + + $this->session->data['advertise_google']['app_id'] = $this->request->post['advertise_google_app_id']; + $this->session->data['advertise_google']['app_secret'] = $this->request->post['advertise_google_app_secret']; + $this->session->data['advertise_google']['status'] = $this->request->post['advertise_google_status']; + $this->session->data['advertise_google']['cron_email_status'] = $this->request->post['advertise_google_cron_email_status']; + $this->session->data['advertise_google']['cron_email'] = $this->request->post['advertise_google_cron_email']; + $this->session->data['advertise_google']['cron_token'] = $this->request->post['advertise_google_cron_token']; + $this->session->data['advertise_google']['cron_acknowledge'] = isset($this->request->post['advertise_google_cron_acknowledge']); + $this->session->data['advertise_google']['redirect_uri'] = html_entity_decode($this->url->link('extension/advertise/google/callback_connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), ENT_QUOTES, 'UTF-8'); + $this->session->data['advertise_google']['state'] = md5(microtime(true) . json_encode($this->session->data['advertise_google']) . microtime(true)); + + $url = $this->googleshopping->authorize($this->session->data['advertise_google']); + + $this->response->redirect($url); + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + if (empty($this->session->data['success']) && $this->getSettingValue('advertise_google_app_id', false) && $this->getSettingValue('advertise_google_app_secret', false)) { + $data['error'] = $this->session->data['error']; + } + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['error_cron_email'] = $this->getValidationError('cron_email'); + $data['error_cron_acknowledge'] = $this->getValidationError('cron_acknowledge'); + + if (isset($this->error['app_id'])) { + $data['error_app_id'] = $this->error['app_id']; + } else { + $data['error_app_id'] = ''; + } + + if (isset($this->error['app_secret'])) { + $data['error_app_secret'] = $this->error['app_secret']; + } else { + $data['error_app_secret'] = ''; + } + + $data['success'] = ''; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + $data['advertise_google_status'] = $this->getSettingValue('advertise_google_status', 1); + $data['advertise_google_app_id'] = $this->getSettingValue('advertise_google_app_id', ''); + $data['advertise_google_app_secret'] = $this->getSettingValue('advertise_google_app_secret', ''); + $data['advertise_google_cron_email_status'] = $this->getSettingValue('advertise_google_cron_email_status'); + $data['advertise_google_cron_email'] = $this->getSettingValue('advertise_google_cron_email', $this->config->get('config_email')); + $data['advertise_google_cron_token'] = $this->getSettingValue('advertise_google_cron_token'); + $data['advertise_google_cron_acknowledge'] = $this->getSettingValue('advertise_google_cron_acknowledge', null, true); + + $server = $this->googleshopping->getStoreUrl(); + + $data['advertise_google_cron_command'] = 'export CUSTOM_SERVER_NAME=' . parse_url($server, PHP_URL_HOST) . '; export CUSTOM_SERVER_PORT=443; export ADVERTISE_GOOGLE_CRON=1; export ADVERTISE_GOOGLE_STORE_ID=' . $this->store_id . '; ' . PHP_BINDIR . '/php -d session.save_path=' . session_save_path() . ' -d memory_limit=256M ' . DIR_SYSTEM . 'library/googleshopping/cron.php > /dev/null 2> /dev/null'; + + if (!$this->setting->get('advertise_google_cron_token')) { + $data['advertise_google_cron_token'] = md5(mt_rand()); + } + + $host_and_uri = parse_url($server, PHP_URL_HOST) . dirname(parse_url($server, PHP_URL_PATH)); + + $data['advertise_google_cron_url'] = 'https://' . rtrim($host_and_uri, '/') . '/index.php?route=extension/advertise/google/cron&cron_token={CRON_TOKEN}'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + $data['action'] = $this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + $data['text_connect_intro'] = sprintf($this->language->get('text_connect_intro'), Googleshopping::API_URL); + + $data['current_step'] = 1; + $data['steps'] = $this->load->view('extension/advertise/google_steps', $data); + + $this->response->setOutput($this->load->view('extension/advertise/google_connect', $data)); + } + + public function disconnect() { + $this->load->language('extension/advertise/google'); + + if ($this->validatePermission()) { + try { + $this->load->model('setting/setting'); + + $this->googleshopping->disconnect(); + + foreach ($this->googleshopping->getTargets($this->store_id) as $target) { + $this->googleshopping->deleteTarget($target['target_id']); + } + + $setting = $this->model_setting_setting->getSetting('advertise_google', $this->store_id); + + unset($setting['advertise_google_status']); + unset($setting['advertise_google_work']); + unset($setting['advertise_google_access_token']); + unset($setting['advertise_google_refresh_token']); + unset($setting['advertise_google_gmc_account_selected']); + unset($setting['advertise_google_gmc_shipping_taxes_configured']); + unset($setting['advertise_google_can_edit_campaigns']); + + $this->model_setting_setting->editSetting('advertise_google', $setting, $this->store_id); + + $this->session->data['success'] = $this->language->get('success_disconnect'); + } catch (ConnectionException $e) { + $this->session->data['error'] = $e->getMessage(); + + $this->response->redirect($this->url->link('extension/advertise/google/connect', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } catch (\RuntimeException $e) { + $this->session->data['error'] = $e->getMessage(); + } + } else { + $this->session->data['error'] = $this->error['warning']; + } + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + public function checklist() { + $this->load->language('extension/advertise/google'); + + $this->document->setTitle($this->language->get('heading_title')); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validatePermission()) { + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('advertise_google', $this->request->post, $this->store_id); + + $this->response->redirect($this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true)); + } + + $data = array(); + + $data['error'] = ''; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extensions'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true), + ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true), + ); + + $data['text_panel_heading'] = sprintf($this->language->get('text_panel_heading'), $this->googleshopping->getStoreName()); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=advertise', true); + $data['action'] = $this->url->link('extension/advertise/google/checklist', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/advertise/google_checklist', $data)); + } + + public function popup_product() { + $json = array( + 'body' => '', + 'title' => '', + 'success' => false, + 'required_fields' => [], + 'success_message' => '' + ); + + $this->language->load('extension/advertise/google'); + + $this->load->model('extension/advertise/google'); + + $operand_info = NULL; + $form_data = NULL; + $filter_data = NULL; + $product_ids = array(); + + if ($this->request->post['operand']['type'] == 'single') { + $product_advertise_google_id = $this->request->post['operand']['data']; + + $product_info = $this->model_extension_advertise_google->getProductByProductAdvertiseGoogleId($product_advertise_google_id); + + if ($product_info !== NULL) { + $json['product_id'] = $product_info['product_id']; + + // Required variables: + $operand_info = array( + 'title' => sprintf($this->language->get('text_popup_title_single'), $product_info['name'], $product_info['model']) + ); + + $required_fields = $this->model_extension_advertise_google->getRequiredFieldsByProductIds(array($product_info['product_id']), $this->store_id); + + if ($this->request->post['action'] == 'submit') { + $form_data = array_merge($this->request->post['form'], array( + 'product_id' => $product_info['product_id'] + )); + } + + $options = $this->model_extension_advertise_google->getProductOptionsByProductIds(array($product_info['product_id'])); + + $default_form_data = $this->model_extension_advertise_google->getProductAdvertiseGoogle($product_advertise_google_id); + } + } else if ($this->request->post['operand']['type'] == 'multiple') { + if (!empty($this->request->post['operand']['data']['all_pages'])) { + $filter_data = $this->getFilter($this->request->post['operand']['data']['filter']); + + $total_products = $this->googleshopping->getTotalProducts($filter_data, $this->store_id); + + // Required variables: + $operand_info = array( + 'title' => sprintf($this->language->get('text_popup_title_multiple'), $total_products) + ); + + $required_fields = $this->model_extension_advertise_google->getRequiredFieldsByFilter($filter_data, $this->store_id); + + if ($this->request->post['action'] == 'submit') { + $form_data = $this->request->post['form']; + } + + $options = $this->model_extension_advertise_google->getProductOptionsByFilter($filter_data); + } else { + $product_ids = $this->request->post['operand']['data']['select']; + + $total_products = count($product_ids); + + // Required variables: + $operand_info = array( + 'title' => sprintf($this->language->get('text_popup_title_multiple'), $total_products) + ); + + $required_fields = $this->model_extension_advertise_google->getRequiredFieldsByProductIds($product_ids, $this->store_id); + + if ($this->request->post['action'] == 'submit') { + $form_data = $this->request->post['form']; + } + + $options = $this->model_extension_advertise_google->getProductOptionsByProductIds($product_ids); + } + + $default_form_data = array( + 'google_product_category' => '', + 'condition' => '', + 'adult' => '', + 'multipack' => '', + 'is_bundle' => '', + 'age_group' => '', + 'color' => '', + 'gender' => '', + 'size_type' => '', + 'size_system' => '', + 'size' => '' + ); + } + + if ($operand_info !== NULL) { + $json['title'] = $operand_info['title']; + $json['success_message'] = $this->language->get('success_product'); + + $this->load->config('googleshopping/googleshopping'); + + $json['required_fields'] = $required_fields; + + if ($this->request->post['action'] == 'submit' && $this->validateProduct($required_fields)) { + $form_data['store_id'] = (int)$this->store_id; + + if ($this->request->post['operand']['type'] == 'single') { + $this->model_extension_advertise_google->updateSingleProductFields($form_data); + } else if ($this->request->post['operand']['type'] == 'multiple') { + if (!empty($this->request->post['operand']['data']['all_pages'])) { + $this->model_extension_advertise_google->updateMultipleProductFields($filter_data, $form_data); + } else { + foreach ($product_ids as $product_id) { + $form_data['product_id'] = (int)$product_id; + $this->model_extension_advertise_google->updateSingleProductFields($form_data); + } + } + } + + $json['success'] = true; + } + + $data['error'] = ''; + + if (!empty($this->error['warning'])) { + $data['error'] = $this->error['warning']; + } + + if (isset($this->error['color'])) { + $data['error_color'] = $this->error['color']; + } else { + $data['error_color'] = ''; + } + + if (isset($this->error['size_system'])) { + $data['error_size_system'] = $this->error['size_system']; + } else { + $data['error_size_system'] = ''; + } + + if (isset($this->error['size_type'])) { + $data['error_size_type'] = $this->error['size_type']; + } else { + $data['error_size_type'] = ''; + } + + if (isset($this->error['size'])) { + $data['error_size'] = $this->error['size']; + } else { + $data['error_size'] = ''; + } + + if (isset($this->error['product_category'])) { + $data['error_product_category'] = $this->error['product_category']; + } else { + $data['error_product_category'] = ''; + } + + if (isset($this->error['condition'])) { + $data['error_condition'] = $this->error['condition']; + } else { + $data['error_condition'] = ''; + } + + if (isset($this->error['age_group'])) { + $data['error_age_group'] = $this->error['age_group']; + } else { + $data['error_age_group'] = ''; + } + + if (isset($this->error['gender'])) { + $data['error_gender'] = $this->error['gender']; + } else { + $data['error_gender'] = ''; + } + + if (isset($this->error['adult'])) { + $data['error_adult'] = $this->error['adult']; + } else { + $data['error_adult'] = ''; + } + + if (isset($this->error['multipack'])) { + $data['error_multipack'] = $this->error['multipack']; + } else { + $data['error_multipack'] = ''; + } + + if (isset($this->error['is_bundle'])) { + $data['error_is_bundle'] = $this->error['is_bundle']; + } else { + $data['error_is_bundle'] = ''; + } + + $data['google_product_categories'] = $this->config->get('advertise_google_google_product_categories'); + $data['conditions'] = array( + 'new' => $this->language->get('text_condition_new'), + 'refurbished' => $this->language->get('text_condition_refurbished'), + 'used' => $this->language->get('text_condition_used') + ); + $data['age_groups'] = array( + '' => $this->language->get('text_does_not_apply'), + 'newborn' => $this->language->get('text_age_group_newborn'), + 'infant' => $this->language->get('text_age_group_infant'), + 'toddler' => $this->language->get('text_age_group_toddler'), + 'kids' => $this->language->get('text_age_group_kids'), + 'adult' => $this->language->get('text_age_group_adult') + ); + $data['genders'] = array( + 'unisex' => $this->language->get('text_gender_unisex'), + 'female' => $this->language->get('text_gender_female'), + 'male' => $this->language->get('text_gender_male') + ); + $data['size_systems'] = array( + '' => $this->language->get('text_does_not_apply') + ); + foreach ($this->config->get('advertise_google_size_systems') as $system) { + $data['size_systems'][$system] = $system; + } + + $data['size_types'] = array( + '' => $this->language->get('text_does_not_apply'), + 'regular' => $this->language->get('text_size_type_regular'), + 'petite' => $this->language->get('text_size_type_petite'), + 'plus' => $this->language->get('text_size_type_plus'), + 'big and tall' => $this->language->get('text_size_type_big_and_tall'), + 'maternity' => $this->language->get('text_size_type_maternity') + ); + + $data['options'] = array( + '' => $this->language->get('text_does_not_apply') + ); + + foreach ($options as $option) { + $data['options'][$option['option_id']] = $option['name']; + } + + $data['required_fields'] = json_encode($required_fields); + + if ($this->request->post['action'] == 'submit') { + $form_data = $this->request->post['form']; + } else { + $form_data = $default_form_data; + } + + $data['google_product_category'] = $form_data['google_product_category']; + $data['condition'] = $form_data['condition']; + $data['adult'] = $form_data['adult']; + $data['multipack'] = $form_data['multipack']; + $data['is_bundle'] = $form_data['is_bundle']; + $data['age_group'] = $form_data['age_group']; + $data['color'] = $form_data['color']; + $data['gender'] = $form_data['gender']; + $data['size_type'] = $form_data['size_type']; + $data['size_system'] = $form_data['size_system']; + $data['size'] = $form_data['size']; + + $json['body'] = $this->load->view('extension/advertise/google_popup_product', $data); + } else { + $json['title'] = $this->language->get('error_popup_not_found_title'); + $json['body'] = $this->language->get('error_popup_not_found_body'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function popup_issues() { + $json = array( + 'body' => '', + 'title' => '' + ); + + $this->language->load('extension/advertise/google'); + + $this->load->model('catalog/product'); + $this->load->model('extension/advertise/google'); + + $product_id = isset($this->request->get['product_id']) ? (int)$this->request->get['product_id'] : 0; + + $product_issues = $this->model_extension_advertise_google->getProductIssues($product_id, $this->store_id); + + if ($product_issues !== NULL) { + $json['title'] = sprintf($this->language->get('text_popup_title_single'), $product_issues['name'], $product_issues['model']); + + $data['product_issues'] = $product_issues['entries']; + + $json['body'] = $this->load->view('extension/advertise/google_popup_issues', $data); + } else { + $json['title'] = $this->language->get('error_popup_not_found_title'); + $json['body'] = $this->language->get('error_popup_not_found_body'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function admin_link(&$route, &$data, &$template) { + if (!$this->user->hasPermission('access', 'extension/advertise/google')) { + return; + } + + foreach ($data['menus'] as &$menu) { + if ($menu['id'] == 'menu-marketing') { + $children = array(); + + $this->load->model('setting/store'); + + $children[] = array( + 'name' => $this->config->get('config_name'), + 'children' => array(), + 'href' => $this->url->link('extension/advertise/google', 'store_id=0&user_token=' . $this->session->data['user_token'], true) + ); + + foreach ($this->model_setting_store->getStores() as $store) { + $children[] = array( + 'name' => $store['name'], + 'children' => array(), + 'href' => $this->url->link('extension/advertise/google', 'store_id=' . $store['store_id'] . '&user_token=' . $this->session->data['user_token'], true) + ); + } + + array_push($menu['children'], array( + 'name' => 'Google Shopping', + 'children' => $children, + 'href' => '' + )); + + return; + } + } + } + + public function addProduct(&$route, &$args, &$output) { + $this->load->model('extension/advertise/google'); + $this->load->model('catalog/product'); + + foreach ($this->model_catalog_product->getProductStores($output) as $store_id) { + $this->model_extension_advertise_google->insertNewProducts(array($output), $store_id); + } + } + + public function copyProduct(&$route, &$args, &$output) { + $this->load->model('extension/advertise/google'); + $this->load->model('catalog/product'); + + $final_product_id = $this->model_extension_advertise_google->getFinalProductId(); + + if (!empty($final_product_id)) { + foreach ($this->model_catalog_product->getProductStores($final_product_id) as $store_id) { + $this->model_extension_advertise_google->insertNewProducts(array($final_product_id), $store_id); + } + } + } + + public function deleteProduct(&$route, &$args, &$output) { + $this->load->model('extension/advertise/google'); + + $this->model_extension_advertise_google->deleteProducts(array((int)$args[0])); + } + + public function install() { + $this->load->model('extension/advertise/google'); + + $this->model_extension_advertise_google->createTables(); + $this->model_extension_advertise_google->createEvents(); + } + + public function uninstall() { + $this->load->model('extension/advertise/google'); + + $this->model_extension_advertise_google->dropTables(); + $this->model_extension_advertise_google->deleteEvents(); + } + + public function category_autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('extension/advertise/google'); + + $filter_data = array( + 'filter_name' => $this->request->get['filter_name'], + 'sort' => 'name', + 'order' => 'ASC', + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_extension_advertise_google->getCategories($filter_data, $this->store_id); + + foreach ($results as $result) { + $json[] = array( + 'category_id' => $result['category_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $sort_order = array(); + + foreach ($json as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $json); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function getFilter($array) { + if (!empty($array)) { + return array( + 'filter_product_name' => $array['product_name'], + 'filter_product_model' => $array['product_model'], + 'filter_category_id' => $array['category_id'], + 'filter_is_modified' => $array['is_modified'], + 'filter_store_id' => $this->store_id + ); + } + + return array( + 'filter_store_id' => $this->store_id + ); + } + + protected function applyNewSettings($new_settings) { + $this->load->model('setting/setting'); + + $old_settings = $this->model_setting_setting->getSetting('advertise_google', $this->store_id); + + $new_settings = array_merge($old_settings, $new_settings); + + $this->model_setting_setting->editSetting('advertise_google', $new_settings, $this->store_id); + + foreach ($new_settings as $key => $value) { + $this->setting->set($key, $value); + } + } + + protected function product(&$row) { + $this->load->config('googleshopping/googleshopping'); + + $this->load->model('tool/image'); + + if (!empty($row['image']) && file_exists(DIR_IMAGE . $row['image'])) { + $image = $this->model_tool_image->resize($row['image'], 50, 50); + } else { + $image = $this->model_tool_image->resize('no_image.png', 50, 50); + } + + return array( + 'product_advertise_google_id' => (int)$row['product_advertise_google_id'], + 'product_id' => (int)$row['product_id'], + 'image' => $image, + 'name' => htmlentities(html_entity_decode($row['name'], ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8'), + 'model' => $row['model'], + 'impressions' => (int)$row['impressions'], + 'clicks' => (int)$row['clicks'], + 'conversions' => (int)$row['conversions'], + 'cost' => $this->googleshopping->currencyFormat($row['cost']), + 'conversion_value' => $this->googleshopping->currencyFormat($row['conversion_value']), + 'destination_status' => $row['destination_status'], + 'is_modified' => (bool)$row['is_modified'], + 'has_issues' => (bool)$row['has_issues'], + 'url_issues' => html_entity_decode($this->url->link('extension/advertise/google/popup_issues', 'store_id=' . $this->store_id . '&user_token=' . $this->session->data['user_token'] . '&product_id=' . $row['product_id'], true), ENT_QUOTES, 'UTF-8'), + 'campaigns' => $this->model_extension_advertise_google->getProductCampaigns((int)$row['product_id'], $this->store_id) + ); + } + + protected function getSettingValue($key, $default = null, $checkbox = false) { + if ($checkbox) { + if ($this->request->server['REQUEST_METHOD'] == 'POST' && !isset($this->request->post[$key])) { + return $default; + } else { + return $this->setting->get($key); + } + } + + if (isset($this->request->post[$key])) { + return $this->request->post[$key]; + } else if ($this->setting->has($key)) { + return $this->setting->get($key); + } else { + return $default; + } + } + + protected function getValidationError($key) { + if (isset($this->error[$key])) { + return $this->error[$key]; + } else { + return ''; + } + } + + protected function validateSettings() { + $this->validatePermission(); + + if (empty($this->request->post['advertise_google_status'])) { + return true; + } + + if (!empty($this->request->post['advertise_google_cron_email_status'])) { + if (!filter_var($this->request->post['advertise_google_cron_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['cron_email'] = $this->language->get('error_invalid_email'); + } + } + + if (empty($this->request->post['advertise_google_cron_acknowledge'])) { + $this->error['cron_acknowledge'] = $this->language->get('error_cron_acknowledge'); + } + + if ($this->error && empty($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_form'); + } + + return !$this->error; + } + + protected function validateShippingAndTaxes() { + $this->validatePermission(); + + if (empty($this->request->post['advertise_google_shipping_taxes']['min_transit_time']) || !is_numeric($this->request->post['advertise_google_shipping_taxes']['min_transit_time']) || (int)$this->request->post['advertise_google_shipping_taxes']['min_transit_time'] < 0) { + $this->error['min_transit_time'] = $this->language->get('error_min_transit_time'); + } else if (empty($this->request->post['advertise_google_shipping_taxes']['max_transit_time']) || !is_numeric($this->request->post['advertise_google_shipping_taxes']['max_transit_time']) || (int)$this->request->post['advertise_google_shipping_taxes']['max_transit_time'] < (int)$this->request->post['advertise_google_shipping_taxes']['min_transit_time']) { + $this->error['max_transit_time'] = $this->language->get('error_max_transit_time'); + } + + switch ($this->request->post['advertise_google_shipping_taxes']['shipping_type']) { + case 'flat' : + if (!isset($this->request->post['advertise_google_shipping_taxes']['flat_rate']) || !is_numeric($this->request->post['advertise_google_shipping_taxes']['flat_rate']) || (float)$this->request->post['advertise_google_shipping_taxes']['flat_rate'] <= 0) { + $this->error['flat_rate'] = $this->language->get('error_flat_rate'); + } + break; + case 'carrier' : + if (empty($this->request->post['advertise_google_shipping_taxes']['carrier'])) { + $this->error['warning'] = $this->language->get('error_carrier'); + } + + if (empty($this->request->post['advertise_google_shipping_taxes']['carrier_postcode'])) { + $this->error['carrier_postcode'] = $this->language->get('error_carrier_postcode'); + } + + if (!isset($this->request->post['advertise_google_shipping_taxes']['carrier_price_percentage']) || !is_numeric($this->request->post['advertise_google_shipping_taxes']['carrier_price_percentage']) || (float)$this->request->post['advertise_google_shipping_taxes']['carrier_price_percentage'] < 0 || (float)$this->request->post['advertise_google_shipping_taxes']['carrier_price_percentage'] > 100) { + $this->error['carrier_price_percentage'] = $this->language->get('error_carrier_price_percentage'); + } + break; + } + + switch ($this->request->post['advertise_google_shipping_taxes']['tax_type']) { + case 'usa' : + if (empty($this->request->post['advertise_google_shipping_taxes']['tax'])) { + $this->error['warning'] = $this->language->get('error_tax'); + } + break; + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateMapping() { + $this->validatePermission(); + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateProduct($required_fields) { + if (!$this->user->hasPermission('modify', 'extension/advertise/google')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (empty($this->error)) { + foreach ($required_fields as $key => $requirements) { + if (empty($requirements['selected_field']) && (!isset($this->request->post['form'][$key]) || $this->request->post['form'][$key] == '')) { + $this->error[$key] = $this->language->get('error_field_no_value'); + } else if (!empty($requirements['selected_field'])) { + foreach ($requirements['selected_field'] as $dependency => $values) { + if (in_array($this->request->post['form'][$dependency], $values) && (!isset($this->request->post['form'][$key]) || $this->request->post['form'][$key] == '')) { + $this->error[$key] = $this->language->get('error_field_no_value'); + } + } + } + } + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validatePermission() { + if (!$this->user->hasPermission('modify', 'extension/advertise/google')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + protected function validateCampaign() { + $this->validatePermission(); + + $this->load->model('extension/advertise/google'); + + $targets = $this->googleshopping->getTargets($this->store_id); + + if (empty($targets)) { + $this->error['warning'] = $this->language->get('error_no_targets'); + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateConnect() { + $this->validatePermission(); + + if (!isset($this->request->post['advertise_google_app_id']) || trim($this->request->post['advertise_google_app_id']) == '') { + $this->error['app_id'] = $this->language->get('error_empty_app_id'); + } else if ($this->model_extension_advertise_google->isAppIdUsed($this->request->post['advertise_google_app_id'], $this->store_id)) { + $this->error['app_id'] = $this->language->get('error_used_app_id'); + } + + if (!isset($this->request->post['advertise_google_app_secret']) || trim($this->request->post['advertise_google_app_secret']) == '') { + $this->error['app_secret'] = $this->language->get('error_empty_app_secret'); + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + protected function validateTarget() { + $this->validatePermission(); + + if (!isset($this->request->post['budget']) || !is_numeric($this->request->post['budget']) || (float)$this->request->post['budget'] < 5) { + $this->error['budget'] = $this->language->get('error_budget'); + } + + if (empty($this->request->post['feed']) || !is_array($this->request->post['feed'])) { + $this->error['feed'] = $this->language->get('error_empty_feed'); + } else { + foreach ($this->request->post['feed'] as $feed) { + if (empty($feed['language']) || empty($feed['currency'])) { + $this->error['feed'] = $this->language->get('error_invalid_feed'); + break; + } + } + } + + if (empty($this->request->post['country'])) { + $this->error['country'] = $this->language->get('error_empty_country'); + } + + if (empty($this->request->post['campaign_name']) || trim($this->request->post['campaign_name']) == '') { + $this->error['campaign_name'] = $this->language->get('error_empty_campaign_name'); + } else { + $disallowed_names = []; + + $this->load->model('extension/advertise/google'); + + foreach ($this->googleshopping->getTargets($this->store_id) as $existing_target) { + if (isset($this->request->get['advertise_google_target_id']) && $existing_target['target_id'] == $this->request->get['advertise_google_target_id']) { + // Ignore this target as it is currntly being edited + continue; + } + + $disallowed_names[] = strtolower(str_replace(',', ',', trim($existing_target['campaign_name']))); + } + + if (in_array(trim(strtolower($this->request->post['campaign_name'])), $disallowed_names)) { + $this->error['campaign_name'] = $this->language->get('error_campaign_name_in_use'); + } + + if (strtolower(trim($this->request->post['campaign_name'])) == 'total') { + $this->error['campaign_name'] = $this->language->get('error_campaign_name_total'); + } + } + + if (!isset($this->error['warning']) && $this->error) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/analytics/google.php b/public/admin/controller/extension/analytics/google.php new file mode 100644 index 0000000..77c39e9 --- /dev/null +++ b/public/admin/controller/extension/analytics/google.php @@ -0,0 +1,85 @@ +<?php +class ControllerExtensionAnalyticsGoogle extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/analytics/google'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('analytics_google', $this->request->post, $this->request->get['store_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=analytics', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=analytics', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/analytics/google', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true) + ); + + $data['action'] = $this->url->link('extension/analytics/google', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=analytics', true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['analytics_google_code'])) { + $data['analytics_google_code'] = $this->request->post['analytics_google_code']; + } else { + $data['analytics_google_code'] = $this->model_setting_setting->getSettingValue('analytics_google_code', $this->request->get['store_id']); + } + + if (isset($this->request->post['analytics_google_status'])) { + $data['analytics_google_status'] = $this->request->post['analytics_google_status']; + } else { + $data['analytics_google_status'] = $this->model_setting_setting->getSettingValue('analytics_google_status', $this->request->get['store_id']); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/analytics/google', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/analytics/google')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['analytics_google_code']) { + $this->error['code'] = $this->language->get('error_code'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/captcha/basic.php b/public/admin/controller/extension/captcha/basic.php new file mode 100644 index 0000000..f975ba3 --- /dev/null +++ b/public/admin/controller/extension/captcha/basic.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionCaptchaBasic extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/captcha/basic'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('captcha_basic', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/captcha/basic', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/captcha/basic', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true); + + if (isset($this->request->post['captcha_basic_status'])) { + $data['captcha_basic_status'] = $this->request->post['captcha_basic_status']; + } else { + $data['captcha_basic_status'] = $this->config->get('captcha_basic_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/captcha/basic', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/captcha/basic')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/captcha/google.php b/public/admin/controller/extension/captcha/google.php new file mode 100644 index 0000000..e6a98c6 --- /dev/null +++ b/public/admin/controller/extension/captcha/google.php @@ -0,0 +1,99 @@ +<?php +class ControllerExtensionCaptchaGoogle extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/captcha/google'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('captcha_google', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/captcha/google', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/captcha/google', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=captcha', true); + + if (isset($this->request->post['captcha_google_key'])) { + $data['captcha_google_key'] = $this->request->post['captcha_google_key']; + } else { + $data['captcha_google_key'] = $this->config->get('captcha_google_key'); + } + + if (isset($this->request->post['captcha_google_secret'])) { + $data['captcha_google_secret'] = $this->request->post['captcha_google_secret']; + } else { + $data['captcha_google_secret'] = $this->config->get('captcha_google_secret'); + } + + if (isset($this->request->post['captcha_google_status'])) { + $data['captcha_google_status'] = $this->request->post['captcha_google_status']; + } else { + $data['captcha_google_status'] = $this->config->get('captcha_google_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/captcha/google', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/captcha/google')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['captcha_google_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + if (!$this->request->post['captcha_google_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/dashboard/activity.php b/public/admin/controller/extension/dashboard/activity.php new file mode 100644 index 0000000..68d71fe --- /dev/null +++ b/public/admin/controller/extension/dashboard/activity.php @@ -0,0 +1,120 @@ +<?php +class ControllerExtensionDashboardActivity extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/activity'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_activity', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/activity', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/activity', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_activity_width'])) { + $data['dashboard_activity_width'] = $this->request->post['dashboard_activity_width']; + } else { + $data['dashboard_activity_width'] = $this->config->get('dashboard_activity_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_activity_status'])) { + $data['dashboard_activity_status'] = $this->request->post['dashboard_activity_status']; + } else { + $data['dashboard_activity_status'] = $this->config->get('dashboard_activity_status'); + } + + if (isset($this->request->post['dashboard_activity_sort_order'])) { + $data['dashboard_activity_sort_order'] = $this->request->post['dashboard_activity_sort_order']; + } else { + $data['dashboard_activity_sort_order'] = $this->config->get('dashboard_activity_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/activity_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/activity')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/activity'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['activities'] = array(); + + $this->load->model('extension/dashboard/activity'); + + $results = $this->model_extension_dashboard_activity->getActivities(); + + foreach ($results as $result) { + $comment = vsprintf($this->language->get('text_activity_' . $result['key']), json_decode($result['data'], true)); + + $find = array( + 'customer_id=', + 'order_id=', + 'return_id=' + ); + + $replace = array( + $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=', true), + $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=', true), + $this->url->link('sale/return/edit', 'user_token=' . $this->session->data['user_token'] . '&return_id=', true) + ); + + $data['activities'][] = array( + 'comment' => str_replace($find, $replace, $comment), + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])) + ); + } + + return $this->load->view('extension/dashboard/activity_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/dashboard/chart.php b/public/admin/controller/extension/dashboard/chart.php new file mode 100644 index 0000000..f361a09 --- /dev/null +++ b/public/admin/controller/extension/dashboard/chart.php @@ -0,0 +1,197 @@ +<?php +class ControllerExtensionDashboardChart extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/chart'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_chart', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/chart', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/chart', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_chart_width'])) { + $data['dashboard_chart_width'] = $this->request->post['dashboard_chart_width']; + } else { + $data['dashboard_chart_width'] = $this->config->get('dashboardchart_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_chart_status'])) { + $data['dashboard_chart_status'] = $this->request->post['dashboard_chart_status']; + } else { + $data['dashboard_chart_status'] = $this->config->get('dashboard_chart_status'); + } + + if (isset($this->request->post['dashboard_chart_sort_order'])) { + $data['dashboard_chart_sort_order'] = $this->request->post['dashboard_chart_sort_order']; + } else { + $data['dashboard_chart_sort_order'] = $this->config->get('dashboard_chart_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/chart_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/chart')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/chart'); + + $data['user_token'] = $this->session->data['user_token']; + + return $this->load->view('extension/dashboard/chart_info', $data); + } + + public function chart() { + $this->load->language('extension/dashboard/chart'); + + $json = array(); + + $this->load->model('extension/dashboard/chart'); + + $json['order'] = array(); + $json['customer'] = array(); + $json['xaxis'] = array(); + + $json['order']['label'] = $this->language->get('text_order'); + $json['customer']['label'] = $this->language->get('text_customer'); + $json['order']['data'] = array(); + $json['customer']['data'] = array(); + + if (isset($this->request->get['range'])) { + $range = $this->request->get['range']; + } else { + $range = 'day'; + } + + switch ($range) { + default: + case 'day': + $results = $this->model_extension_dashboard_chart->getTotalOrdersByDay(); + + foreach ($results as $key => $value) { + $json['order']['data'][] = array($key, $value['total']); + } + + $results = $this->model_extension_dashboard_chart->getTotalCustomersByDay(); + + foreach ($results as $key => $value) { + $json['customer']['data'][] = array($key, $value['total']); + } + + for ($i = 0; $i < 24; $i++) { + $json['xaxis'][] = array($i, $i); + } + break; + case 'week': + $results = $this->model_extension_dashboard_chart->getTotalOrdersByWeek(); + + foreach ($results as $key => $value) { + $json['order']['data'][] = array($key, $value['total']); + } + + $results = $this->model_extension_dashboard_chart->getTotalCustomersByWeek(); + + foreach ($results as $key => $value) { + $json['customer']['data'][] = array($key, $value['total']); + } + + $date_start = strtotime('-' . date('w') . ' days'); + + for ($i = 0; $i < 7; $i++) { + $date = date('Y-m-d', $date_start + ($i * 86400)); + + $json['xaxis'][] = array(date('w', strtotime($date)), date('D', strtotime($date))); + } + break; + case 'month': + $results = $this->model_extension_dashboard_chart->getTotalOrdersByMonth(); + + foreach ($results as $key => $value) { + $json['order']['data'][] = array($key, $value['total']); + } + + $results = $this->model_extension_dashboard_chart->getTotalCustomersByMonth(); + + foreach ($results as $key => $value) { + $json['customer']['data'][] = array($key, $value['total']); + } + + for ($i = 1; $i <= date('t'); $i++) { + $date = date('Y') . '-' . date('m') . '-' . $i; + + $json['xaxis'][] = array(date('j', strtotime($date)), date('d', strtotime($date))); + } + break; + case 'year': + $results = $this->model_extension_dashboard_chart->getTotalOrdersByYear(); + + foreach ($results as $key => $value) { + $json['order']['data'][] = array($key, $value['total']); + } + + $results = $this->model_extension_dashboard_chart->getTotalCustomersByYear(); + + foreach ($results as $key => $value) { + $json['customer']['data'][] = array($key, $value['total']); + } + + for ($i = 1; $i <= 12; $i++) { + $json['xaxis'][] = array($i, date('M', mktime(0, 0, 0, $i))); + } + break; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/dashboard/customer.php b/public/admin/controller/extension/dashboard/customer.php new file mode 100644 index 0000000..e5054d3 --- /dev/null +++ b/public/admin/controller/extension/dashboard/customer.php @@ -0,0 +1,124 @@ +<?php +class ControllerExtensionDashboardCustomer extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/customer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_customer', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/customer', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/customer', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_customer_width'])) { + $data['dashboard_customer_width'] = $this->request->post['dashboard_customer_width']; + } else { + $data['dashboard_customer_width'] = $this->config->get('dashboard_customer_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_customer_status'])) { + $data['dashboard_customer_status'] = $this->request->post['dashboard_customer_status']; + } else { + $data['dashboard_customer_status'] = $this->config->get('dashboard_customer_status'); + } + + if (isset($this->request->post['dashboard_customer_sort_order'])) { + $data['dashboard_customer_sort_order'] = $this->request->post['dashboard_customer_sort_order']; + } else { + $data['dashboard_customer_sort_order'] = $this->config->get('dashboard_customer_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/customer_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/customer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/customer'); + + $data['user_token'] = $this->session->data['user_token']; + + // Total Orders + $this->load->model('customer/customer'); + + $today = $this->model_customer_customer->getTotalCustomers(array('filter_date_added' => date('Y-m-d', strtotime('-1 day')))); + + $yesterday = $this->model_customer_customer->getTotalCustomers(array('filter_date_added' => date('Y-m-d', strtotime('-2 day')))); + + $difference = $today - $yesterday; + + if ($difference && $today) { + $data['percentage'] = round(($difference / $today) * 100); + } else { + $data['percentage'] = 0; + } + + $customer_total = $this->model_customer_customer->getTotalCustomers(); + + if ($customer_total > 1000000000000) { + $data['total'] = round($customer_total / 1000000000000, 1) . 'T'; + } elseif ($customer_total > 1000000000) { + $data['total'] = round($customer_total / 1000000000, 1) . 'B'; + } elseif ($customer_total > 1000000) { + $data['total'] = round($customer_total / 1000000, 1) . 'M'; + } elseif ($customer_total > 1000) { + $data['total'] = round($customer_total / 1000, 1) . 'K'; + } else { + $data['total'] = $customer_total; + } + + $data['customer'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/dashboard/customer_info', $data); + } +} diff --git a/public/admin/controller/extension/dashboard/map.php b/public/admin/controller/extension/dashboard/map.php new file mode 100644 index 0000000..0e19331 --- /dev/null +++ b/public/admin/controller/extension/dashboard/map.php @@ -0,0 +1,111 @@ +<?php +class ControllerExtensionDashboardMap extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/map'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_map', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/map', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/map', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_map_width'])) { + $data['dashboard_map_width'] = $this->request->post['dashboard_map_width']; + } else { + $data['dashboard_map_width'] = $this->config->get('dashboard_map_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_map_status'])) { + $data['dashboard_map_status'] = $this->request->post['dashboard_map_status']; + } else { + $data['dashboard_map_status'] = $this->config->get('dashboard_map_status'); + } + + if (isset($this->request->post['dashboard_map_sort_order'])) { + $data['dashboard_map_sort_order'] = $this->request->post['dashboard_map_sort_order']; + } else { + $data['dashboard_map_sort_order'] = $this->config->get('dashboard_map_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/map_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/map')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/map'); + + $data['user_token'] = $this->session->data['user_token']; + + return $this->load->view('extension/dashboard/map_info', $data); + } + + public function map() { + $json = array(); + + $this->load->model('extension/dashboard/map'); + + $results = $this->model_extension_dashboard_map->getTotalOrdersByCountry(); + + foreach ($results as $result) { + $json[strtolower($result['iso_code_2'])] = array( + 'total' => $result['total'], + 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')) + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/extension/dashboard/online.php b/public/admin/controller/extension/dashboard/online.php new file mode 100644 index 0000000..4bb1ff7 --- /dev/null +++ b/public/admin/controller/extension/dashboard/online.php @@ -0,0 +1,113 @@ +<?php +class ControllerExtensionDashboardOnline extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/online'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_online', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/online', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/online', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_online_width'])) { + $data['dashboard_online_width'] = $this->request->post['dashboard_online_width']; + } else { + $data['dashboard_online_width'] = $this->config->get('dashboard_online_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_online_status'])) { + $data['dashboard_online_status'] = $this->request->post['dashboard_online_status']; + } else { + $data['dashboard_online_status'] = $this->config->get('dashboard_online_status'); + } + + if (isset($this->request->post['dashboard_online_sort_order'])) { + $data['dashboard_online_sort_order'] = $this->request->post['dashboard_online_sort_order']; + } else { + $data['dashboard_online_sort_order'] = $this->config->get('dashboard_online_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/online_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/online')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/online'); + + $data['user_token'] = $this->session->data['user_token']; + + // Total Orders + $this->load->model('extension/dashboard/online'); + + // Customers Online + $online_total = $this->model_extension_dashboard_online->getTotalOnline(); + + if ($online_total > 1000000000000) { + $data['total'] = round($online_total / 1000000000000, 1) . 'T'; + } elseif ($online_total > 1000000000) { + $data['total'] = round($online_total / 1000000000, 1) . 'B'; + } elseif ($online_total > 1000000) { + $data['total'] = round($online_total / 1000000, 1) . 'M'; + } elseif ($online_total > 1000) { + $data['total'] = round($online_total / 1000, 1) . 'K'; + } else { + $data['total'] = $online_total; + } + + $data['online'] = $this->url->link('report/online', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/dashboard/online_info', $data); + } +} diff --git a/public/admin/controller/extension/dashboard/order.php b/public/admin/controller/extension/dashboard/order.php new file mode 100644 index 0000000..3383fe3 --- /dev/null +++ b/public/admin/controller/extension/dashboard/order.php @@ -0,0 +1,124 @@ +<?php +class ControllerExtensionDashboardOrder extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_order', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/order', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/order', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_order_width'])) { + $data['dashboard_order_width'] = $this->request->post['dashboard_order_width']; + } else { + $data['dashboard_order_width'] = $this->config->get('dashboard_order_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_order_status'])) { + $data['dashboard_order_status'] = $this->request->post['dashboard_order_status']; + } else { + $data['dashboard_order_status'] = $this->config->get('dashboard_order_status'); + } + + if (isset($this->request->post['dashboard_order_sort_order'])) { + $data['dashboard_order_sort_order'] = $this->request->post['dashboard_order_sort_order']; + } else { + $data['dashboard_order_sort_order'] = $this->config->get('dashboard_order_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/order_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/order')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/order'); + + $data['user_token'] = $this->session->data['user_token']; + + // Total Orders + $this->load->model('sale/order'); + + $today = $this->model_sale_order->getTotalOrders(array('filter_date_added' => date('Y-m-d', strtotime('-1 day')))); + + $yesterday = $this->model_sale_order->getTotalOrders(array('filter_date_added' => date('Y-m-d', strtotime('-2 day')))); + + $difference = $today - $yesterday; + + if ($difference && $today) { + $data['percentage'] = round(($difference / $today) * 100); + } else { + $data['percentage'] = 0; + } + + $order_total = $this->model_sale_order->getTotalOrders(); + + if ($order_total > 1000000000000) { + $data['total'] = round($order_total / 1000000000000, 1) . 'T'; + } elseif ($order_total > 1000000000) { + $data['total'] = round($order_total / 1000000000, 1) . 'B'; + } elseif ($order_total > 1000000) { + $data['total'] = round($order_total / 1000000, 1) . 'M'; + } elseif ($order_total > 1000) { + $data['total'] = round($order_total / 1000, 1) . 'K'; + } else { + $data['total'] = $order_total; + } + + $data['order'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/dashboard/order_info', $data); + } +} diff --git a/public/admin/controller/extension/dashboard/recent.php b/public/admin/controller/extension/dashboard/recent.php new file mode 100644 index 0000000..45063c7 --- /dev/null +++ b/public/admin/controller/extension/dashboard/recent.php @@ -0,0 +1,118 @@ +<?php +class ControllerExtensionDashboardRecent extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/recent'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_recent', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/recent', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/recent', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_recent_width'])) { + $data['dashboard_recent_width'] = $this->request->post['dashboard_recent_width']; + } else { + $data['dashboard_recent_width'] = $this->config->get('dashboard_recent_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_recent_status'])) { + $data['dashboard_recent_status'] = $this->request->post['dashboard_recent_status']; + } else { + $data['dashboard_recent_status'] = $this->config->get('dashboard_recent_status'); + } + + if (isset($this->request->post['dashboard_recent_sort_order'])) { + $data['dashboard_recent_sort_order'] = $this->request->post['dashboard_recent_sort_order']; + } else { + $data['dashboard_recent_sort_order'] = $this->config->get('dashboard_recent_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/recent_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/recent')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/recent'); + + $data['user_token'] = $this->session->data['user_token']; + + // Last 5 Orders + $data['orders'] = array(); + + $filter_data = array( + 'sort' => 'o.date_added', + 'order' => 'DESC', + 'start' => 0, + 'limit' => 5 + ); + + $this->load->model('sale/order'); + + $results = $this->model_sale_order->getOrders($filter_data); + + foreach ($results as $result) { + $data['orders'][] = array( + 'order_id' => $result['order_id'], + 'customer' => $result['customer'], + 'status' => $result['order_status'], + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'total' => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']), + 'view' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $result['order_id'], true), + ); + } + + return $this->load->view('extension/dashboard/recent_info', $data); + } +} diff --git a/public/admin/controller/extension/dashboard/sale.php b/public/admin/controller/extension/dashboard/sale.php new file mode 100644 index 0000000..887079c --- /dev/null +++ b/public/admin/controller/extension/dashboard/sale.php @@ -0,0 +1,123 @@ +<?php +class ControllerExtensionDashboardSale extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/dashboard/sale'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('dashboard_sale', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/dashboard/sale', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/dashboard/sale', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=dashboard', true); + + if (isset($this->request->post['dashboard_sale_width'])) { + $data['dashboard_sale_width'] = $this->request->post['dashboard_sale_width']; + } else { + $data['dashboard_sale_width'] = $this->config->get('dashboard_sale_width'); + } + + $data['columns'] = array(); + + for ($i = 3; $i <= 12; $i++) { + $data['columns'][] = $i; + } + + if (isset($this->request->post['dashboard_sale_status'])) { + $data['dashboard_sale_status'] = $this->request->post['dashboard_sale_status']; + } else { + $data['dashboard_sale_status'] = $this->config->get('dashboard_sale_status'); + } + + if (isset($this->request->post['dashboard_sale_sort_order'])) { + $data['dashboard_sale_sort_order'] = $this->request->post['dashboard_sale_sort_order']; + } else { + $data['dashboard_sale_sort_order'] = $this->config->get('dashboard_sale_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/dashboard/sale_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/dashboard/sale')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function dashboard() { + $this->load->language('extension/dashboard/sale'); + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('extension/dashboard/sale'); + + $today = $this->model_extension_dashboard_sale->getTotalSales(array('filter_date_added' => date('Y-m-d', strtotime('-1 day')))); + + $yesterday = $this->model_extension_dashboard_sale->getTotalSales(array('filter_date_added' => date('Y-m-d', strtotime('-2 day')))); + + $difference = $today - $yesterday; + + if ($difference && (int)$today) { + $data['percentage'] = round(($difference / $today) * 100); + } else { + $data['percentage'] = 0; + } + + $sale_total = $this->model_extension_dashboard_sale->getTotalSales(); + + if ($sale_total > 1000000000000) { + $data['total'] = round($sale_total / 1000000000000, 1) . 'T'; + } elseif ($sale_total > 1000000000) { + $data['total'] = round($sale_total / 1000000000, 1) . 'B'; + } elseif ($sale_total > 1000000) { + $data['total'] = round($sale_total / 1000000, 1) . 'M'; + } elseif ($sale_total > 1000) { + $data['total'] = round($sale_total / 1000, 1) . 'K'; + } else { + $data['total'] = round($sale_total); + } + + $data['sale'] = $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/dashboard/sale_info', $data); + } +} diff --git a/public/admin/controller/extension/extension/advertise.php b/public/admin/controller/extension/extension/advertise.php new file mode 100644 index 0000000..0d8689e --- /dev/null +++ b/public/admin/controller/extension/extension/advertise.php @@ -0,0 +1,134 @@ +<?php +class ControllerExtensionExtensionAdvertise extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/advertise'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/advertise'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('advertise', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/advertise/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/advertise/' . $this->request->get['extension']); + + // Compatibility + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'advertise/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'advertise/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/advertise/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/advertise'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('advertise', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/advertise/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('advertise'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/advertise/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/advertise/' . $value . '.php')) { + $this->model_setting_extension->uninstall('advertise', $value); + + unset($extensions[$key]); + } + } + + $this->load->model('setting/store'); + $this->load->model('setting/setting'); + + $stores = $this->model_setting_store->getStores(); + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/advertise/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + // Compatibility code for old extension folders + $this->load->language('extension/advertise/' . $extension, 'extension'); + + $store_data = array(); + + $store_data[] = array( + 'name' => $this->config->get('config_name'), + 'edit' => $this->url->link('extension/advertise/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=0', true), + 'status' => $this->config->get('advertise_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + + foreach ($stores as $store) { + $store_data[] = array( + 'name' => $store['name'], + 'edit' => $this->url->link('extension/advertise/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id'], true), + 'status' => $this->model_setting_setting->getSettingValue('advertise_' . $extension . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'install' => $this->url->link('extension/extension/advertise/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/advertise/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'store' => $store_data + ); + } + } + + $this->response->setOutput($this->load->view('extension/extension/advertise', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/advertise')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/analytics.php b/public/admin/controller/extension/extension/analytics.php new file mode 100644 index 0000000..74bff33 --- /dev/null +++ b/public/admin/controller/extension/extension/analytics.php @@ -0,0 +1,136 @@ +<?php +class ControllerExtensionExtensionAnalytics extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/analytics'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/analytics'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('analytics', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/analytics/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/analytics/' . $this->request->get['extension']); + + // Compatibility + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'analytics/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'analytics/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/analytics/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/analytics'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('analytics', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/analytics/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('analytics'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/analytics/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/analytics/' . $value . '.php')) { + $this->model_setting_extension->uninstall('analytics', $value); + + unset($extensions[$key]); + } + } + + $this->load->model('setting/store'); + $this->load->model('setting/setting'); + + $stores = $this->model_setting_store->getStores(); + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/analytics/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + // Compatibility code for old extension folders + $this->load->language('extension/analytics/' . $extension, 'extension'); + + $store_data = array(); + + $store_data[] = array( + 'name' => $this->config->get('config_name'), + 'edit' => $this->url->link('extension/analytics/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=0', true), + 'status' => $this->config->get('analytics_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + + foreach ($stores as $store) { + $store_data[] = array( + 'name' => $store['name'], + 'edit' => $this->url->link('extension/analytics/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id'], true), + 'status' => $this->model_setting_setting->getSettingValue('analytics_' . $extension . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'install' => $this->url->link('extension/extension/analytics/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/analytics/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'store' => $store_data + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/analytics', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/analytics')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/captcha.php b/public/admin/controller/extension/extension/captcha.php new file mode 100644 index 0000000..846ad1c --- /dev/null +++ b/public/admin/controller/extension/extension/captcha.php @@ -0,0 +1,115 @@ +<?php +class ControllerExtensionExtensionCaptcha extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/captcha'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/captcha'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('captcha', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/captcha/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/captcha/' . $this->request->get['extension']); + + // Compatibility + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'captcha/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'captcha/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/captcha/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/captcha'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('captcha', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/captcha/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('captcha'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/captcha/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/captcha/' . $value . '.php')) { + $this->model_setting_extension->uninstall('captcha', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/captcha/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/captcha/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title') . (($extension == $this->config->get('config_captcha')) ? $this->language->get('text_default') : null), + 'status' => $this->config->get('captcha_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('extension/extension/captcha/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/captcha/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/captcha/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/captcha', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/captcha')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/dashboard.php b/public/admin/controller/extension/extension/dashboard.php new file mode 100644 index 0000000..d400418 --- /dev/null +++ b/public/admin/controller/extension/extension/dashboard.php @@ -0,0 +1,114 @@ +<?php +class ControllerExtensionExtensionDashboard extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/dashboard'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/dashboard'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('dashboard', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/dashboard/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/dashboard/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/dashboard/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/dashboard'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('dashboard', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/dashboard/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('dashboard'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/dashboard/' . $value . '.php')) { + $this->model_setting_extension->uninstall('dashboard', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/dashboard/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + // Compatibility code for old extension folders + $this->load->language('extension/dashboard/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'width' => $this->config->get('dashboard_' . $extension . '_width'), + 'status' => $this->config->get('dashboard_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('dashboard_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/dashboard/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/dashboard/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/dashboard/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/dashboard', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/dashboard')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/feed.php b/public/admin/controller/extension/extension/feed.php new file mode 100644 index 0000000..8dc1c94 --- /dev/null +++ b/public/admin/controller/extension/extension/feed.php @@ -0,0 +1,111 @@ +<?php +class ControllerExtensionExtensionFeed extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/feed'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/feed'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('feed', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/feed/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/feed/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/feed/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/feed'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('feed', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/feed/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('feed'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/feed/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/feed/' . $value . '.php')) { + $this->model_setting_extension->uninstall('feed', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/feed/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/feed/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('feed_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('extension/extension/feed/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/feed/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/feed/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/feed', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/feed')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/fraud.php b/public/admin/controller/extension/extension/fraud.php new file mode 100644 index 0000000..8a4b97b --- /dev/null +++ b/public/admin/controller/extension/extension/fraud.php @@ -0,0 +1,111 @@ +<?php +class ControllerExtensionExtensionFraud extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/fraud'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/fraud'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('fraud', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/fraud/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/fraud/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/fraud/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/fraud'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('fraud', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/fraud/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('fraud'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/fraud/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/fraud/' . $value . '.php')) { + $this->model_setting_extension->uninstall('fraud', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/fraud/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/fraud/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('fraud_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('extension/extension/fraud/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/fraud/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/fraud/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/fraud', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/fraud')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/menu.php b/public/admin/controller/extension/extension/menu.php new file mode 100644 index 0000000..d490606 --- /dev/null +++ b/public/admin/controller/extension/extension/menu.php @@ -0,0 +1,121 @@ +<?php +class ControllerExtensionExtensionMenu extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/menu'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/menu'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('menu', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/menu/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/menu/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/menu/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/menu'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('menu', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/menu/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + $data['text_layout'] = sprintf($this->language->get('text_layout'), $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true)); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('menu'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/menu/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/menu/' . $value . '.php')) { + $this->model_setting_extension->uninstall('menu', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/menu/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/menu/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('menu_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'install' => $this->url->link('extension/extension/menu/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/menu/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/menu/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $sort_order = array(); + + foreach ($data['extensions'] as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $data['extensions']); + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/menu', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/menu')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/module.php b/public/admin/controller/extension/extension/module.php new file mode 100644 index 0000000..a76d202 --- /dev/null +++ b/public/admin/controller/extension/extension/module.php @@ -0,0 +1,191 @@ +<?php +class ControllerExtensionExtensionModule extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + if ($this->validate()) { + $this->model_setting_extension->install('module', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/module/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/module/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/module/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } else { + $this->session->data['error'] = $this->error['warning']; + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('module', $this->request->get['extension']); + + $this->model_setting_module->deleteModulesByCode($this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/module/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function add() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + if ($this->validate()) { + $this->load->language('module' . '/' . $this->request->get['extension']); + + $this->model_setting_module->addModule($this->request->get['extension'], $this->language->get('heading_title')); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function delete() { + $this->load->language('extension/extension/module'); + + $this->load->model('setting/extension'); + + $this->load->model('setting/module'); + + if (isset($this->request->get['module_id']) && $this->validate()) { + $this->model_setting_module->deleteModule($this->request->get['module_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + $data['text_layout'] = sprintf($this->language->get('text_layout'), $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true)); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('module'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/module/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/module/' . $value . '.php')) { + $this->model_setting_extension->uninstall('module', $value); + + unset($extensions[$key]); + + $this->model_setting_module->deleteModulesByCode($value); + } + } + + $data['extensions'] = array(); + + // Create a new language container so we don't pollute the current one + $language = new Language($this->config->get('config_language')); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/module/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/module/' . $extension, 'extension'); + + $module_data = array(); + + $modules = $this->model_setting_module->getModulesByCode($extension); + + foreach ($modules as $module) { + if ($module['setting']) { + $setting_info = json_decode($module['setting'], true); + } else { + $setting_info = array(); + } + + $module_data[] = array( + 'module_id' => $module['module_id'], + 'name' => $module['name'], + 'status' => (isset($setting_info['status']) && $setting_info['status']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'edit' => $this->url->link('extension/module/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $module['module_id'], true), + 'delete' => $this->url->link('extension/extension/module/delete', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $module['module_id'], true) + ); + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('module_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'module' => $module_data, + 'install' => $this->url->link('extension/extension/module/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/module/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/module/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $sort_order = array(); + + foreach ($data['extensions'] as $key => $value) { + $sort_order[$key] = $value['name']; + } + + array_multisort($sort_order, SORT_ASC, $data['extensions']); + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/module', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/module')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/extension/payment.php b/public/admin/controller/extension/extension/payment.php new file mode 100644 index 0000000..e73d3d5 --- /dev/null +++ b/public/admin/controller/extension/extension/payment.php @@ -0,0 +1,123 @@ +<?php +class ControllerExtensionExtensionPayment extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/payment'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/payment'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('payment', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/payment/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/payment/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/payment/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/payment'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('payment', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/payment/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('payment'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/payment/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/payment/' . $value . '.php')) { + $this->model_setting_extension->uninstall('payment', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/payment/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/payment/' . $extension, 'extension'); + + $text_link = $this->language->get('extension')->get('text_' . $extension); + + if ($text_link != 'text_' . $extension) { + $link = $text_link; + } else { + $link = ''; + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'link' => $link, + 'status' => $this->config->get('payment_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('payment_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/payment/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/payment/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/payment/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/payment', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/payment')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/promotion.php b/public/admin/controller/extension/extension/promotion.php new file mode 100644 index 0000000..aeef853 --- /dev/null +++ b/public/admin/controller/extension/extension/promotion.php @@ -0,0 +1,23 @@ +<?php +class ControllerExtensionExtensionPromotion extends Controller { + public function index() { + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_URL, OPENCART_SERVER . 'index.php?route=api/promotion&type=' . substr($this->request->get['route'], strrpos($this->request->get['route'], '/') + 1)); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); + curl_setopt($curl, CURLOPT_TIMEOUT, 30); + + $response = curl_exec($curl); + + curl_close($curl); + + if ($response) { + return $response; + } else { + return ''; + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/report.php b/public/admin/controller/extension/extension/report.php new file mode 100644 index 0000000..685604c --- /dev/null +++ b/public/admin/controller/extension/extension/report.php @@ -0,0 +1,112 @@ +<?php +class ControllerExtensionExtensionReport extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/report'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/report'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('report', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/report/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/report/' . $this->request->get['extension']); + + $this->load->controller('extension/report/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/report'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('report', $this->request->get['extension']); + + $this->load->controller('extension/report/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('report'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/report/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/report/' . $value . '.php')) { + $this->model_setting_extension->uninstall('report', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/report/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/report/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('report_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('report_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/report/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/report/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/report/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/report', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/report')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/shipping.php b/public/admin/controller/extension/extension/shipping.php new file mode 100644 index 0000000..55feb41 --- /dev/null +++ b/public/admin/controller/extension/extension/shipping.php @@ -0,0 +1,114 @@ +<?php +class ControllerExtensionExtensionShipping extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/shipping'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/shipping'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('shipping', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/shipping/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/shipping/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/shipping/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/shipping'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('shipping', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/shipping/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('shipping'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/shipping/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/shipping/' . $value . '.php')) { + $this->model_setting_extension->uninstall('shipping', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/shipping/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/shipping/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('shipping_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('shipping_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/shipping/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/shipping/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/shipping/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/shipping', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/shipping')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/theme.php b/public/admin/controller/extension/extension/theme.php new file mode 100644 index 0000000..813f368 --- /dev/null +++ b/public/admin/controller/extension/extension/theme.php @@ -0,0 +1,131 @@ +<?php +class ControllerExtensionExtensionTheme extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/theme'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/feed'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('theme', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/theme/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/theme/' . $this->request->get['extension']); + + // Call install method if it exsits + $this->load->controller('extension/theme/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/theme'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('theme', $this->request->get['extension']); + + // Call uninstall method if it exsits + $this->load->controller('extension/theme/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $extensions = $this->model_setting_extension->getInstalled('theme'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/theme/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/theme/' . $value . '.php')) { + $this->model_setting_extension->uninstall('theme', $value); + + unset($extensions[$key]); + } + } + + $this->load->model('setting/store'); + $this->load->model('setting/setting'); + + $stores = $this->model_setting_store->getStores(); + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/theme/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/theme/' . $extension, 'extension'); + + $store_data = array(); + + $store_data[] = array( + 'name' => $this->config->get('config_name'), + 'edit' => $this->url->link('extension/theme/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=0', true), + 'status' => $this->config->get('theme_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + + foreach ($stores as $store) { + $store_data[] = array( + 'name' => $store['name'], + 'edit' => $this->url->link('extension/theme/' . $extension, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id'], true), + 'status' => $this->model_setting_setting->getSettingValue('theme_' . $extension . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled') + ); + } + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'install' => $this->url->link('extension/extension/theme/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/theme/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'store' => $store_data + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/theme', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/theme')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/extension/total.php b/public/admin/controller/extension/extension/total.php new file mode 100644 index 0000000..ad27ff9 --- /dev/null +++ b/public/admin/controller/extension/extension/total.php @@ -0,0 +1,112 @@ +<?php +class ControllerExtensionExtensionTotal extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/extension/total'); + + $this->load->model('setting/extension'); + + $this->getList(); + } + + public function install() { + $this->load->language('extension/extension/total'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->install('total', $this->request->get['extension']); + + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/total/' . $this->request->get['extension']); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/total/' . $this->request->get['extension']); + + $this->load->controller('extension/total/' . $this->request->get['extension'] . '/install'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + public function uninstall() { + $this->load->language('extension/extension/total'); + + $this->load->model('setting/extension'); + + if ($this->validate()) { + $this->model_setting_extension->uninstall('total', $this->request->get['extension']); + + $this->load->controller('extension/total/' . $this->request->get['extension'] . '/uninstall'); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->getList(); + } + + protected function getList() { + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $this->load->model('setting/extension'); + + $extensions = $this->model_setting_extension->getInstalled('total'); + + foreach ($extensions as $key => $value) { + if (!is_file(DIR_APPLICATION . 'controller/extension/total/' . $value . '.php') && !is_file(DIR_APPLICATION . 'controller/total/' . $value . '.php')) { + $this->model_setting_extension->uninstall('total', $value); + + unset($extensions[$key]); + } + } + + $data['extensions'] = array(); + + // Compatibility code for old extension folders + $files = glob(DIR_APPLICATION . 'controller/extension/total/*.php'); + + if ($files) { + foreach ($files as $file) { + $extension = basename($file, '.php'); + + $this->load->language('extension/total/' . $extension, 'extension'); + + $data['extensions'][] = array( + 'name' => $this->language->get('extension')->get('heading_title'), + 'status' => $this->config->get('total_' . $extension . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'), + 'sort_order' => $this->config->get('total_' . $extension . '_sort_order'), + 'install' => $this->url->link('extension/extension/total/install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'uninstall' => $this->url->link('extension/extension/total/uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension, true), + 'installed' => in_array($extension, $extensions), + 'edit' => $this->url->link('extension/total/' . $extension, 'user_token=' . $this->session->data['user_token'], true) + ); + } + } + + $data['promotion'] = $this->load->controller('extension/extension/promotion'); + + $this->response->setOutput($this->load->view('extension/extension/total', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/extension/total')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/feed/google_base.php b/public/admin/controller/extension/feed/google_base.php new file mode 100644 index 0000000..ff88d41 --- /dev/null +++ b/public/admin/controller/extension/feed/google_base.php @@ -0,0 +1,243 @@ +<?php +class ControllerExtensionFeedGoogleBase extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/feed/google_base'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('feed_google_base', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/feed/google_base', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/feed/google_base', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['data_feed'] = HTTP_CATALOG . 'index.php?route=extension/feed/google_base'; + + if (isset($this->request->post['feed_google_base_status'])) { + $data['feed_google_base_status'] = $this->request->post['feed_google_base_status']; + } else { + $data['feed_google_base_status'] = $this->config->get('feed_google_base_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/feed/google_base', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/feed/google_base')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('extension/feed/google_base'); + + $this->model_extension_feed_google_base->install(); + } + + public function uninstall() { + $this->load->model('extension/feed/google_base'); + + $this->model_extension_feed_google_base->uninstall(); + } + + public function import() { + $this->load->language('extension/feed/google_base'); + + $json = array(); + + // Check user has permission + if (!$this->user->hasPermission('modify', 'extension/feed/google_base')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (!$json) { + if (!empty($this->request->files['file']['name']) && is_file($this->request->files['file']['tmp_name'])) { + // Sanitize the filename + $filename = basename(html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8')); + + // Allowed file extension types + if (utf8_strtolower(utf8_substr(strrchr($filename, '.'), 1)) != 'txt') { + $json['error'] = $this->language->get('error_filetype'); + } + + // Allowed file mime types + if ($this->request->files['file']['type'] != 'text/plain') { + $json['error'] = $this->language->get('error_filetype'); + } + + // Return any upload error + if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) { + $json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']); + } + } else { + $json['error'] = $this->language->get('error_upload'); + } + } + + if (!$json) { + $json['success'] = $this->language->get('text_success'); + + $this->load->model('extension/feed/google_base'); + + // Get the contents of the uploaded file + $content = file_get_contents($this->request->files['file']['tmp_name']); + + $this->model_extension_feed_google_base->import($content); + + unlink($this->request->files['file']['tmp_name']); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function category() { + $this->load->language('extension/feed/google_base'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['google_base_categories'] = array(); + + $this->load->model('extension/feed/google_base'); + + $results = $this->model_extension_feed_google_base->getCategories(($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['google_base_categories'][] = array( + 'google_base_category_id' => $result['google_base_category_id'], + 'google_base_category' => $result['google_base_category'], + 'category_id' => $result['category_id'], + 'category' => $result['category'] + ); + } + + $category_total = $this->model_extension_feed_google_base->getTotalCategories(); + + $pagination = new Pagination(); + $pagination->total = $category_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('extension/feed/google_base/category', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($category_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($category_total - 10)) ? $category_total : ((($page - 1) * 10) + 10), $category_total, ceil($category_total / 10)); + + $this->response->setOutput($this->load->view('extension/feed/google_base_category', $data)); + } + + public function addCategory() { + $this->load->language('extension/feed/google_base'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/feed/google_base')) { + $json['error'] = $this->language->get('error_permission'); + } elseif (!empty($this->request->post['google_base_category_id']) && !empty($this->request->post['category_id'])) { + $this->load->model('extension/feed/google_base'); + + $this->model_extension_feed_google_base->addCategory($this->request->post); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function removeCategory() { + $this->load->language('extension/feed/google_base'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/feed/google_base')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('extension/feed/google_base'); + + $this->model_extension_feed_google_base->deleteCategory($this->request->post['category_id']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_name'])) { + $this->load->model('extension/feed/google_base'); + + if (isset($this->request->get['filter_name'])) { + $filter_name = $this->request->get['filter_name']; + } else { + $filter_name = ''; + } + + $filter_data = array( + 'filter_name' => html_entity_decode($filter_name, ENT_QUOTES, 'UTF-8'), + 'start' => 0, + 'limit' => 5 + ); + + $results = $this->model_extension_feed_google_base->getGoogleBaseCategories($filter_data); + + foreach ($results as $result) { + $json[] = array( + 'google_base_category_id' => $result['google_base_category_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/extension/feed/google_sitemap.php b/public/admin/controller/extension/feed/google_sitemap.php new file mode 100644 index 0000000..38c96dc --- /dev/null +++ b/public/admin/controller/extension/feed/google_sitemap.php @@ -0,0 +1,69 @@ +<?php +class ControllerExtensionFeedGoogleSitemap extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/feed/google_sitemap'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('feed_google_sitemap', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/feed/google_sitemap', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/feed/google_sitemap', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=feed', true); + + if (isset($this->request->post['feed_google_sitemap_status'])) { + $data['feed_google_sitemap_status'] = $this->request->post['feed_google_sitemap_status']; + } else { + $data['feed_google_sitemap_status'] = $this->config->get('feed_google_sitemap_status'); + } + + $data['data_feed'] = HTTP_CATALOG . 'index.php?route=extension/feed/google_sitemap'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/feed/google_sitemap', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/feed/google_sitemap')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/feed/openbaypro.php b/public/admin/controller/extension/feed/openbaypro.php new file mode 100644 index 0000000..10e8994 --- /dev/null +++ b/public/admin/controller/extension/feed/openbaypro.php @@ -0,0 +1,48 @@ +<?php +class ControllerExtensionFeedOpenbaypro extends Controller { + private $error = array(); + + public function index() { + $this->response->redirect($this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/openbaypro')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('setting/setting'); + $this->load->model('setting/event'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'marketplace/openbay'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'marketplace/openbay'); + + $settings = $this->model_setting_setting->getSetting('feed_openbaypro'); + $settings['feed_openbaypro_status'] = 1; + $settings['feed_openbaypro_language'] = "en_GB"; + $this->model_setting_setting->editSetting('feed_openbaypro', $settings); + + $this->model_setting_event->addEvent('openbay_product_del_after', 'admin/model/catalog/product/deleteProduct/after', 'marketplace/openbay/eventDeleteProduct'); + + $this->model_setting_event->addEvent('openbay_product_edit_after', 'admin/model/catalog/product/editProduct/after', 'marketplace/openbay/eventEditProduct'); + + $this->model_setting_event->addEvent('openbay_menu', 'admin/view/common/column_left/before', 'marketplace/openbay/eventMenu'); + } + + public function uninstall() { + $this->load->model('setting/setting'); + $this->load->model('setting/event'); + + $settings = $this->model_setting_setting->getSetting('feed_openbaypro'); + $settings['feed_openbaypro_status'] = 0; + $this->model_setting_setting->editSetting('feed_openbaypro', $settings); + + $this->model_setting_event->deleteEventByCode('openbay_product_del_after'); + $this->model_setting_event->deleteEventByCode('openbay_product_edit_after'); + $this->model_setting_event->deleteEventByCode('openbay_menu'); + } +} diff --git a/public/admin/controller/extension/fraud/fraudlabspro.php b/public/admin/controller/extension/fraud/fraudlabspro.php new file mode 100644 index 0000000..c17eda0 --- /dev/null +++ b/public/admin/controller/extension/fraud/fraudlabspro.php @@ -0,0 +1,331 @@ +<?php +class ControllerExtensionFraudFraudLabsPro extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/fraud/fraudlabspro'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('fraud_fraudlabspro', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/fraud/fraudlabspro', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/fraud/fraudlabspro', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true); + + if (isset($this->request->post['fraud_fraudlabspro_key'])) { + $data['fraud_fraudlabspro_key'] = $this->request->post['fraud_fraudlabspro_key']; + } else { + $data['fraud_fraudlabspro_key'] = $this->config->get('fraud_fraudlabspro_key'); + } + + if (isset($this->request->post['fraud_fraudlabspro_score'])) { + $data['fraud_fraudlabspro_score'] = $this->request->post['fraud_fraudlabspro_score']; + } else { + $data['fraud_fraudlabspro_score'] = $this->config->get('fraud_fraudlabspro_score'); + } + + if (isset($this->request->post['fraud_fraudlabspro_order_status_id'])) { + $data['fraud_fraudlabspro_order_status_id'] = $this->request->post['fraud_fraudlabspro_order_status_id']; + } else { + $data['fraud_fraudlabspro_order_status_id'] = $this->config->get('fraud_fraudlabspro_order_status_id'); + } + + if (isset($this->request->post['fraud_fraudlabspro_review_status_id'])) { + $data['fraud_fraudlabspro_review_status_id'] = $this->request->post['fraud_fraudlabspro_review_status_id']; + } else { + $data['fraud_fraudlabspro_review_status_id'] = $this->config->get('fraud_fraudlabspro_review_status_id'); + } + + if (isset($this->request->post['fraud_fraudlabspro_approve_status_id'])) { + $data['fraud_fraudlabspro_approve_status_id'] = $this->request->post['fraud_fraudlabspro_approve_status_id']; + } else { + $data['fraud_fraudlabspro_approve_status_id'] = $this->config->get('fraud_fraudlabspro_approve_status_id'); + } + + if (isset($this->request->post['fraud_fraudlabspro_reject_status_id'])) { + $data['fraud_fraudlabspro_reject_status_id'] = $this->request->post['fraud_fraudlabspro_reject_status_id']; + } else { + $data['fraud_fraudlabspro_reject_status_id'] = $this->config->get('fraud_fraudlabspro_reject_status_id'); + } + + if (isset($this->request->post['fraud_fraudlabspro_simulate_ip'])) { + $data['fraud_fraudlabspro_simulate_ip'] = $this->request->post['fraud_fraudlabspro_simulate_ip']; + } else { + $data['fraud_fraudlabspro_simulate_ip'] = $this->config->get('fraud_fraudlabspro_simulate_ip'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['fraud_fraudlabspro_status'])) { + $data['fraud_fraudlabspro_status'] = $this->request->post['fraud_fraudlabspro_status']; + } else { + $data['fraud_fraudlabspro_status'] = $this->config->get('fraud_fraudlabspro_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/fraud/fraudlabspro', $data)); + } + + public function install() { + $this->load->model('extension/fraud/fraudlabspro'); + + $this->model_extension_fraud_fraudlabspro->install(); + } + + public function uninstall() { + $this->load->model('extension/fraud/fraudlabspro'); + + $this->model_extension_fraud_fraudlabspro->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/fraud/fraudlabspro')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['fraud_fraudlabspro_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } + + public function order() { + $this->load->language('extension/fraud/fraudlabspro'); + + $this->load->model('extension/fraud/fraudlabspro'); + + // Action of the Approve/Reject button click + if (isset($_POST['flp_id'])){ + $flp_status = $_POST['new_status']; + $data['flp_status'] = $flp_status; + + //Feedback FLP status to server + $fraud_fraudlabspro_key = $this->config->get('fraud_fraudlabspro_key'); + + for($i=0; $i<3; $i++){ + $result = @file_get_contents('https://api.fraudlabspro.com/v1/order/feedback?key=' . $fraud_fraudlabspro_key . '&format=json&id=' . $_POST['flp_id'] . '&action=' . $flp_status); + + if($result) break; + } + + // Update fraud status into table + $this->db->query("UPDATE `" . DB_PREFIX . "fraudlabspro` SET fraudlabspro_status = '" . $this->db->escape($flp_status) . "' WHERE order_id = " . $this->db->escape($this->request->get['order_id'])); + + //Update history record + if (strtolower($flp_status) == 'approve'){ + $data_temp = array( + 'order_status_id'=>$this->config->get('fraud_fraudlabspro_approve_status_id'), + 'notify'=>0, + 'comment'=>'Approved using FraudLabs Pro.' + ); + + $this->model_extension_fraud_fraudlabspro->addOrderHistory($this->request->get['order_id'], $data_temp); + } + else if (strtolower($flp_status) == "reject"){ + $data_temp = array( + 'order_status_id'=>$this->config->get('fraud_fraudlabspro_reject_status_id'), + 'notify'=>0, + 'comment'=>'Rejected using FraudLabs Pro.' + ); + + $this->model_extension_fraud_fraudlabspro->addOrderHistory($this->request->get['order_id'], $data_temp); + } + } + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $fraud_info = $this->model_extension_fraud_fraudlabspro->getOrder($order_id); + + if ($fraud_info) { + if ($fraud_info['ip_address']) { + $data['flp_ip_address'] = $fraud_info['ip_address']; + } else { + $data['flp_ip_address'] = ''; + } + + if ($fraud_info['ip_netspeed']) { + $data['flp_ip_net_speed'] = $fraud_info['ip_netspeed']; + } else { + $data['flp_ip_net_speed'] = ''; + } + + if ($fraud_info['ip_isp_name']) { + $data['flp_ip_isp_name'] = $fraud_info['ip_isp_name']; + } else { + $data['flp_ip_isp_name'] = ''; + } + + if ($fraud_info['ip_usage_type']) { + $data['flp_ip_usage_type'] = $fraud_info['ip_usage_type']; + } else { + $data['flp_ip_usage_type'] = ''; + } + + if ($fraud_info['ip_domain']) { + $data['flp_ip_domain'] = $fraud_info['ip_domain']; + } else { + $data['flp_ip_domain'] = ''; + } + + if ($fraud_info['ip_timezone']) { + $data['flp_ip_time_zone'] = $fraud_info['ip_timezone']; + } else { + $data['flp_ip_time_zone'] = ''; + } + + if ($fraud_info['ip_country']) { + $data['flp_ip_location'] = $this->fix_case($fraud_info['ip_continent']) . ", " . $fraud_info['ip_country'] . ", " . $fraud_info['ip_region'] . ", " . $fraud_info['ip_city'] . " <a href=\"http://www.geolocation.com/" . $fraud_info['ip_address'] . "\" target=\"_blank\">[Map]</a>"; + } else { + $data['flp_ip_location'] = '-'; + } + + if ($fraud_info['distance_in_mile'] != '-') { + $data['flp_ip_distance'] = $fraud_info['distance_in_mile'] . " miles"; + } else { + $data['flp_ip_distance'] = ''; + } + + if ($fraud_info['ip_latitude']) { + $data['flp_ip_latitude'] = $fraud_info['ip_latitude']; + } else { + $data['flp_ip_latitude'] = ''; + } + + if ($fraud_info['ip_longitude']) { + $data['flp_ip_longitude'] = $fraud_info['ip_longitude']; + } else { + $data['flp_ip_longitude'] = ''; + } + + if ($fraud_info['is_high_risk_country']) { + $data['flp_risk_country'] = $fraud_info['is_high_risk_country']; + } else { + $data['flp_risk_country'] = ''; + } + + if ($fraud_info['is_free_email']) { + $data['flp_free_email'] = $fraud_info['is_free_email']; + } else { + $data['flp_free_email'] = ''; + } + + if ($fraud_info['is_address_ship_forward']) { + $data['flp_ship_forward'] = $fraud_info['is_address_ship_forward']; + } else { + $data['flp_ship_forward'] = ''; + } + + if ($fraud_info['is_proxy_ip_address']) { + $data['flp_using_proxy'] = $fraud_info['is_proxy_ip_address']; + } else { + $data['flp_using_proxy'] = ''; + } + + if ($fraud_info['is_bin_found']) { + $data['flp_bin_found'] = $fraud_info['is_bin_found']; + } else { + $data['flp_bin_found'] = ''; + } + + if ($fraud_info['is_email_blacklist']) { + $data['flp_email_blacklist'] = $fraud_info['is_email_blacklist']; + } else { + $data['flp_email_blacklist'] = ''; + } + + if ($fraud_info['is_credit_card_blacklist']) { + $data['flp_credit_card_blacklist'] = $fraud_info['is_credit_card_blacklist']; + } else { + $data['flp_credit_card_blacklist'] = ''; + } + + if ($fraud_info['fraudlabspro_score']) { + $data['flp_score'] = $fraud_info['fraudlabspro_score']; + } else { + $data['flp_score'] = ''; + } + + if ($fraud_info['fraudlabspro_status']) { + $data['flp_status'] = $fraud_info['fraudlabspro_status']; + } else { + $data['flp_status'] = ''; + } + + if ($fraud_info['fraudlabspro_message']) { + $data['flp_message'] = $fraud_info['fraudlabspro_message']; + } else { + $data['flp_message'] = ''; + } + + if ($fraud_info['fraudlabspro_id']) { + $data['flp_id'] = $fraud_info['fraudlabspro_id']; + $data['flp_link'] = $fraud_info['fraudlabspro_id']; + } else { + $data['flp_id'] = ''; + $data['flp_link'] = ''; + } + + if ($fraud_info['fraudlabspro_credits']) { + $data['flp_credits'] = $fraud_info['fraudlabspro_credits']; + } else { + $data['flp_credits'] = ''; + } + + return $this->load->view('extension/fraud/fraudlabspro_info', $data); + } + } + + private function fix_case($s) { + $s = ucwords(strtolower($s)); + $s = preg_replace_callback("/( [ a-zA-Z]{1}')([a-zA-Z0-9]{1})/s", create_function('$matches', 'return $matches[1].strtoupper($matches[2]);'), $s); + return $s; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/fraud/ip.php b/public/admin/controller/extension/fraud/ip.php new file mode 100644 index 0000000..fec9b53 --- /dev/null +++ b/public/admin/controller/extension/fraud/ip.php @@ -0,0 +1,171 @@ +<?php +class ControllerExtensionFraudIp extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/fraud/ip'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('fraud_ip', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true)); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/fraud/ip', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/fraud/ip', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true); + + if (isset($this->request->post['fraud_ip_order_status_id'])) { + $data['fraud_ip_order_status_id'] = $this->request->post['fraud_ip_order_status_id']; + } else { + $data['fraud_ip_order_status_id'] = $this->config->get('fraud_ip_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['fraud_ip_status'])) { + $data['fraud_ip_status'] = $this->request->post['fraud_ip_status']; + } else { + $data['fraud_ip_status'] = $this->config->get('fraud_ip_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/fraud/ip', $data)); + } + + public function install() { + $this->load->model('extension/fraud/ip'); + + $this->model_extension_fraud_ip->install(); + } + + public function uninstall() { + $this->load->model('extension/fraud/ip'); + + $this->model_extension_fraud_ip->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/fraud/ip')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function ip() { + $this->load->language('extension/fraud/ip'); + + $this->load->model('extension/fraud/ip'); + $this->load->model('customer/customer'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['ips'] = array(); + + $results = $this->model_extension_fraud_ip->getIps(($page - 1) * 10, 10); + + foreach ($results as $result) { + $data['ips'][] = array( + 'ip' => $result['ip'], + 'total' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']), + 'date_added' => date('d/m/y', strtotime($result['date_added'])), + 'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip'], true) + ); + } + + $ip_total = $this->model_extension_fraud_ip->getTotalIps(); + + $pagination = new Pagination(); + $pagination->total = $ip_total; + $pagination->page = $page; + $pagination->limit = 10; + $pagination->url = $this->url->link('extension/fraud/ip/ip', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($ip_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($ip_total - 10)) ? $ip_total : ((($page - 1) * 10) + 10), $ip_total, ceil($ip_total / 10)); + + $this->response->setOutput($this->load->view('extension/fraud/ip_ip', $data)); + } + + public function addIp() { + $this->load->language('extension/fraud/ip'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/fraud/ip')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('extension/fraud/ip'); + + if (!$this->model_extension_fraud_ip->getTotalIpsByIp($this->request->post['ip'])) { + $this->model_extension_fraud_ip->addIp($this->request->post['ip']); + } + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function removeIp() { + $this->load->language('extension/fraud/ip'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/fraud/ip')) { + $json['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('extension/fraud/ip'); + + $this->model_extension_fraud_ip->removeIp($this->request->post['ip']); + + $json['success'] = $this->language->get('text_success'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/extension/fraud/maxmind.php b/public/admin/controller/extension/fraud/maxmind.php new file mode 100644 index 0000000..ffa17dc --- /dev/null +++ b/public/admin/controller/extension/fraud/maxmind.php @@ -0,0 +1,429 @@ +<?php +class ControllerExtensionFraudMaxMind extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/fraud/maxmind'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('fraud_maxmind', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/fraud/maxmind', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/fraud/maxmind', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud', true); + + if (isset($this->request->post['fraud_maxmind_key'])) { + $data['fraud_maxmind_key'] = $this->request->post['fraud_maxmind_key']; + } else { + $data['fraud_maxmind_key'] = $this->config->get('fraud_maxmind_key'); + } + + if (isset($this->request->post['fraud_maxmind_score'])) { + $data['fraud_maxmind_score'] = $this->request->post['fraud_maxmind_score']; + } else { + $data['fraud_maxmind_score'] = $this->config->get('fraud_maxmind_score'); + } + + if (isset($this->request->post['fraud_maxmind_order_status_id'])) { + $data['fraud_maxmind_order_status_id'] = $this->request->post['fraud_maxmind_order_status_id']; + } else { + $data['fraud_maxmind_order_status_id'] = $this->config->get('fraud_maxmind_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['fraud_maxmind_status'])) { + $data['fraud_maxmind_status'] = $this->request->post['fraud_maxmind_status']; + } else { + $data['fraud_maxmind_status'] = $this->config->get('fraud_maxmind_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/fraud/maxmind', $data)); + } + + public function install() { + $this->load->model('extension/fraud/maxmind'); + + $this->model_extension_fraud_maxmind->install(); + } + + public function uninstall() { + $this->load->model('extension/fraud/maxmind'); + + $this->model_extension_fraud_maxmind->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/fraud/maxmind')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['fraud_maxmind_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } + + public function order() { + $this->load->language('extension/fraud/maxmind'); + + $this->load->model('extension/fraud/maxmind'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $fraud_info = $this->model_extension_fraud_maxmind->getOrder($order_id); + + if ($fraud_info) { + $data['text_country_match'] = $this->language->get('text_country_match'); + $data['text_country_code'] = $this->language->get('text_country_code'); + $data['text_high_risk_country'] = $this->language->get('text_high_risk_country'); + $data['text_distance'] = $this->language->get('text_distance'); + $data['text_ip_region'] = $this->language->get('text_ip_region'); + $data['text_ip_city'] = $this->language->get('text_ip_city'); + $data['text_ip_latitude'] = $this->language->get('text_ip_latitude'); + $data['text_ip_longitude'] = $this->language->get('text_ip_longitude'); + $data['text_ip_isp'] = $this->language->get('text_ip_isp'); + $data['text_ip_org'] = $this->language->get('text_ip_org'); + $data['text_ip_asnum'] = $this->language->get('text_ip_asnum'); + $data['text_ip_user_type'] = $this->language->get('text_ip_user_type'); + $data['text_ip_country_confidence'] = $this->language->get('text_ip_country_confidence'); + $data['text_ip_region_confidence'] = $this->language->get('text_ip_region_confidence'); + $data['text_ip_city_confidence'] = $this->language->get('text_ip_city_confidence'); + $data['text_ip_postal_confidence'] = $this->language->get('text_ip_postal_confidence'); + $data['text_ip_postal_code'] = $this->language->get('text_ip_postal_code'); + $data['text_ip_accuracy_radius'] = $this->language->get('text_ip_accuracy_radius'); + $data['text_ip_net_speed_cell'] = $this->language->get('text_ip_net_speed_cell'); + $data['text_ip_metro_code'] = $this->language->get('text_ip_metro_code'); + $data['text_ip_area_code'] = $this->language->get('text_ip_area_code'); + $data['text_ip_time_zone'] = $this->language->get('text_ip_time_zone'); + $data['text_ip_region_name'] = $this->language->get('text_ip_region_name'); + $data['text_ip_domain'] = $this->language->get('text_ip_domain'); + $data['text_ip_country_name'] = $this->language->get('text_ip_country_name'); + $data['text_ip_continent_code'] = $this->language->get('text_ip_continent_code'); + $data['text_ip_corporate_proxy'] = $this->language->get('text_ip_corporate_proxy'); + $data['text_anonymous_proxy'] = $this->language->get('text_anonymous_proxy'); + $data['text_proxy_score'] = $this->language->get('text_proxy_score'); + $data['text_is_trans_proxy'] = $this->language->get('text_is_trans_proxy'); + $data['text_free_mail'] = $this->language->get('text_free_mail'); + $data['text_carder_email'] = $this->language->get('text_carder_email'); + $data['text_high_risk_username'] = $this->language->get('text_high_risk_username'); + $data['text_high_risk_password'] = $this->language->get('text_high_risk_password'); + $data['text_bin_match'] = $this->language->get('text_bin_match'); + $data['text_bin_country'] = $this->language->get('text_bin_country'); + $data['text_bin_name_match'] = $this->language->get('text_bin_name_match'); + $data['text_bin_name'] = $this->language->get('text_bin_name'); + $data['text_bin_phone_match'] = $this->language->get('text_bin_phone_match'); + $data['text_bin_phone'] = $this->language->get('text_bin_phone'); + $data['text_customer_phone_in_billing_location'] = $this->language->get('text_customer_phone_in_billing_location'); + $data['text_ship_forward'] = $this->language->get('text_ship_forward'); + $data['text_city_postal_match'] = $this->language->get('text_city_postal_match'); + $data['text_ship_city_postal_match'] = $this->language->get('text_ship_city_postal_match'); + $data['text_score'] = $this->language->get('text_score'); + $data['text_explanation'] = $this->language->get('text_explanation'); + $data['text_risk_score'] = $this->language->get('text_risk_score'); + $data['text_queries_remaining'] = $this->language->get('text_queries_remaining'); + $data['text_maxmind_id'] = $this->language->get('text_maxmind_id'); + $data['text_error'] = $this->language->get('text_error'); + + $data['help_country_match'] = $this->language->get('help_country_match'); + $data['help_country_code'] = $this->language->get('help_country_code'); + $data['help_high_risk_country'] = $this->language->get('help_high_risk_country'); + $data['help_distance'] = $this->language->get('help_distance'); + $data['help_ip_region'] = $this->language->get('help_ip_region'); + $data['help_ip_city'] = $this->language->get('help_ip_city'); + $data['help_ip_latitude'] = $this->language->get('help_ip_latitude'); + $data['help_ip_longitude'] = $this->language->get('help_ip_longitude'); + $data['help_ip_isp'] = $this->language->get('help_ip_isp'); + $data['help_ip_org'] = $this->language->get('help_ip_org'); + $data['help_ip_asnum'] = $this->language->get('help_ip_asnum'); + $data['help_ip_user_type'] = $this->language->get('help_ip_user_type'); + $data['help_ip_country_confidence'] = $this->language->get('help_ip_country_confidence'); + $data['help_ip_region_confidence'] = $this->language->get('help_ip_region_confidence'); + $data['help_ip_city_confidence'] = $this->language->get('help_ip_city_confidence'); + $data['help_ip_postal_confidence'] = $this->language->get('help_ip_postal_confidence'); + $data['help_ip_postal_code'] = $this->language->get('help_ip_postal_code'); + $data['help_ip_accuracy_radius'] = $this->language->get('help_ip_accuracy_radius'); + $data['help_ip_net_speed_cell'] = $this->language->get('help_ip_net_speed_cell'); + $data['help_ip_metro_code'] = $this->language->get('help_ip_metro_code'); + $data['help_ip_area_code'] = $this->language->get('help_ip_area_code'); + $data['help_ip_time_zone'] = $this->language->get('help_ip_time_zone'); + $data['help_ip_region_name'] = $this->language->get('help_ip_region_name'); + $data['help_ip_domain'] = $this->language->get('help_ip_domain'); + $data['help_ip_country_name'] = $this->language->get('help_ip_country_name'); + $data['help_ip_continent_code'] = $this->language->get('help_ip_continent_code'); + $data['help_ip_corporate_proxy'] = $this->language->get('help_ip_corporate_proxy'); + $data['help_anonymous_proxy'] = $this->language->get('help_anonymous_proxy'); + $data['help_proxy_score'] = $this->language->get('help_proxy_score'); + $data['help_is_trans_proxy'] = $this->language->get('help_is_trans_proxy'); + $data['help_free_mail'] = $this->language->get('help_free_mail'); + $data['help_carder_email'] = $this->language->get('help_carder_email'); + $data['help_high_risk_username'] = $this->language->get('help_high_risk_username'); + $data['help_high_risk_password'] = $this->language->get('help_high_risk_password'); + $data['help_bin_match'] = $this->language->get('help_bin_match'); + $data['help_bin_country'] = $this->language->get('help_bin_country'); + $data['help_bin_name_match'] = $this->language->get('help_bin_name_match'); + $data['help_bin_name'] = $this->language->get('help_bin_name'); + $data['help_bin_phone_match'] = $this->language->get('help_bin_phone_match'); + $data['help_bin_phone'] = $this->language->get('help_bin_phone'); + $data['help_customer_phone_in_billing_location'] = $this->language->get('help_customer_phone_in_billing_location'); + $data['help_ship_forward'] = $this->language->get('help_ship_forward'); + $data['help_city_postal_match'] = $this->language->get('help_city_postal_match'); + $data['help_ship_city_postal_match'] = $this->language->get('help_ship_city_postal_match'); + $data['help_score'] = $this->language->get('help_score'); + $data['help_explanation'] = $this->language->get('help_explanation'); + $data['help_risk_score'] = $this->language->get('help_risk_score'); + $data['help_queries_remaining'] = $this->language->get('help_queries_remaining'); + $data['help_maxmind_id'] = $this->language->get('help_maxmind_id'); + $data['help_error'] = $this->language->get('help_error'); + + $data['country_match'] = $fraud_info['country_match']; + + if ($fraud_info['country_code']) { + $data['country_code'] = $fraud_info['country_code']; + } else { + $data['country_code'] = ''; + } + + $data['high_risk_country'] = $fraud_info['high_risk_country']; + $data['distance'] = $fraud_info['distance']; + + if ($fraud_info['ip_region']) { + $data['ip_region'] = $fraud_info['ip_region']; + } else { + $data['ip_region'] = ''; + } + + if ($fraud_info['ip_city']) { + $data['ip_city'] = $fraud_info['ip_city']; + } else { + $data['ip_city'] = ''; + } + + $data['ip_latitude'] = $fraud_info['ip_latitude']; + $data['ip_longitude'] = $fraud_info['ip_longitude']; + + if ($fraud_info['ip_isp']) { + $data['ip_isp'] = $fraud_info['ip_isp']; + } else { + $data['ip_isp'] = ''; + } + + if ($fraud_info['ip_org']) { + $data['ip_org'] = $fraud_info['ip_org']; + } else { + $data['ip_org'] = ''; + } + + $data['ip_asnum'] = $fraud_info['ip_asnum']; + + if ($fraud_info['ip_user_type']) { + $data['ip_user_type'] = $fraud_info['ip_user_type']; + } else { + $data['ip_user_type'] = ''; + } + + if ($fraud_info['ip_country_confidence']) { + $data['ip_country_confidence'] = $fraud_info['ip_country_confidence']; + } else { + $data['ip_country_confidence'] = ''; + } + + if ($fraud_info['ip_region_confidence']) { + $data['ip_region_confidence'] = $fraud_info['ip_region_confidence']; + } else { + $data['ip_region_confidence'] = ''; + } + + if ($fraud_info['ip_city_confidence']) { + $data['ip_city_confidence'] = $fraud_info['ip_city_confidence']; + } else { + $data['ip_city_confidence'] = ''; + } + + if ($fraud_info['ip_postal_confidence']) { + $data['ip_postal_confidence'] = $fraud_info['ip_postal_confidence']; + } else { + $data['ip_postal_confidence'] = ''; + } + + if ($fraud_info['ip_postal_code']) { + $data['ip_postal_code'] = $fraud_info['ip_postal_code']; + } else { + $data['ip_postal_code'] = ''; + } + + $data['ip_accuracy_radius'] = $fraud_info['ip_accuracy_radius']; + + if ($fraud_info['ip_net_speed_cell']) { + $data['ip_net_speed_cell'] = $fraud_info['ip_net_speed_cell']; + } else { + $data['ip_net_speed_cell'] = ''; + } + + $data['ip_metro_code'] = $fraud_info['ip_metro_code']; + $data['ip_area_code'] = $fraud_info['ip_area_code']; + + if ($fraud_info['ip_time_zone']) { + $data['ip_time_zone'] = $fraud_info['ip_time_zone']; + } else { + $data['ip_time_zone'] = ''; + } + + if ($fraud_info['ip_region_name']) { + $data['ip_region_name'] = $fraud_info['ip_region_name']; + } else { + $data['ip_region_name'] = ''; + } + + if ($fraud_info['ip_domain']) { + $data['ip_domain'] = $fraud_info['ip_domain']; + } else { + $data['ip_domain'] = ''; + } + + if ($fraud_info['ip_country_name']) { + $data['ip_country_name'] = $fraud_info['ip_country_name']; + } else { + $data['ip_country_name'] = ''; + } + + if ($fraud_info['ip_continent_code']) { + $data['ip_continent_code'] = $fraud_info['ip_continent_code']; + } else { + $data['ip_continent_code'] = ''; + } + + if ($fraud_info['ip_corporate_proxy']) { + $data['ip_corporate_proxy'] = $fraud_info['ip_corporate_proxy']; + } else { + $data['ip_corporate_proxy'] = ''; + } + + $data['anonymous_proxy'] = $fraud_info['anonymous_proxy']; + $data['proxy_score'] = $fraud_info['proxy_score']; + + if ($fraud_info['is_trans_proxy']) { + $data['is_trans_proxy'] = $fraud_info['is_trans_proxy']; + } else { + $data['is_trans_proxy'] = ''; + } + + $data['free_mail'] = $fraud_info['free_mail']; + $data['carder_email'] = $fraud_info['carder_email']; + + if ($fraud_info['high_risk_username']) { + $data['high_risk_username'] = $fraud_info['high_risk_username']; + } else { + $data['high_risk_username'] = ''; + } + + if ($fraud_info['high_risk_password']) { + $data['high_risk_password'] = $fraud_info['high_risk_password']; + } else { + $data['high_risk_password'] = ''; + } + + $data['bin_match'] = $fraud_info['bin_match']; + + if ($fraud_info['bin_country']) { + $data['bin_country'] = $fraud_info['bin_country']; + } else { + $data['bin_country'] = ''; + } + + $data['bin_name_match'] = $fraud_info['bin_name_match']; + + if ($fraud_info['bin_name']) { + $data['bin_name'] = $fraud_info['bin_name']; + } else { + $data['bin_name'] = ''; + } + + $data['bin_phone_match'] = $fraud_info['bin_phone_match']; + + if ($fraud_info['bin_phone']) { + $data['bin_phone'] = $fraud_info['bin_phone']; + } else { + $data['bin_phone'] = ''; + } + + if ($fraud_info['customer_phone_in_billing_location']) { + $data['customer_phone_in_billing_location'] = $fraud_info['customer_phone_in_billing_location']; + } else { + $data['customer_phone_in_billing_location'] = ''; + } + + $data['ship_forward'] = $fraud_info['ship_forward']; + + if ($fraud_info['city_postal_match']) { + $data['city_postal_match'] = $fraud_info['city_postal_match']; + } else { + $data['city_postal_match'] = ''; + } + + if ($fraud_info['ship_city_postal_match']) { + $data['ship_city_postal_match'] = $fraud_info['ship_city_postal_match']; + } else { + $data['ship_city_postal_match'] = ''; + } + + $data['score'] = $fraud_info['score']; + $data['explanation'] = $fraud_info['explanation']; + $data['risk_score'] = $fraud_info['risk_score']; + $data['queries_remaining'] = $fraud_info['queries_remaining']; + $data['maxmind_id'] = $fraud_info['maxmind_id']; + $data['error'] = $fraud_info['error']; + + return $this->load->view('extension/fraud/maxmind_info', $data); + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/account.php b/public/admin/controller/extension/module/account.php new file mode 100644 index 0000000..c424934 --- /dev/null +++ b/public/admin/controller/extension/module/account.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleAccount extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/account'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_account', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/account', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/account', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_account_status'])) { + $data['module_account_status'] = $this->request->post['module_account_status']; + } else { + $data['module_account_status'] = $this->config->get('module_account_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/account', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/account')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/amazon_login.php b/public/admin/controller/extension/module/amazon_login.php new file mode 100644 index 0000000..0247dfb --- /dev/null +++ b/public/admin/controller/extension/module/amazon_login.php @@ -0,0 +1,114 @@ +<?php +class ControllerExtensionModuleAmazonLogin extends Controller { + private $version = '3.1'; + private $error = array(); + + public function index() { + + $this->load->language('extension/module/amazon_login'); + + $this->load->model('setting/setting'); + $this->load->model('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_amazon_login', $this->request->post); + + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_login'); + $this->model_setting_event->addEvent('amazon_login', 'catalog/controller/account/logout/after', 'extension/module/amazon_login/logout'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['heading_title'] = $this->language->get('heading_title') . ' ' . $this->version; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/amazon_login', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/amazon_login', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['module_amazon_login_button_type'])) { + $data['module_amazon_login_button_type'] = $this->request->post['module_amazon_login_button_type']; + } elseif ($this->config->get('module_amazon_login_button_type')) { + $data['module_amazon_login_button_type'] = $this->config->get('module_amazon_login_button_type'); + } else { + $data['module_amazon_login_button_type'] = 'LwA'; + } + + if (isset($this->request->post['module_amazon_login_button_colour'])) { + $data['module_amazon_login_button_colour'] = $this->request->post['module_amazon_login_button_colour']; + } elseif ($this->config->get('module_amazon_login_button_colour')) { + $data['module_amazon_login_button_colour'] = $this->config->get('module_amazon_login_button_colour'); + } else { + $data['module_amazon_login_button_colour'] = 'gold'; + } + + if (isset($this->request->post['module_amazon_login_button_size'])) { + $data['module_amazon_login_button_size'] = $this->request->post['module_amazon_login_button_size']; + } elseif ($this->config->get('module_amazon_login_button_size')) { + $data['module_amazon_login_button_size'] = $this->config->get('module_amazon_login_button_size'); + } else { + $data['module_amazon_login_button_size'] = 'medium'; + } + + if (isset($this->request->post['module_amazon_login_status'])) { + $data['module_amazon_login_status'] = $this->request->post['module_amazon_login_status']; + } else { + $data['module_amazon_login_status'] = $this->config->get('module_amazon_login_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/amazon_login', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/amazon_login')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_login'); + $this->model_setting_event->addEvent('amazon_login', 'catalog/controller/account/logout/after', 'extension/module/amazon_login/logout'); + } + + public function uninstall() { + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_login'); + } + +} diff --git a/public/admin/controller/extension/module/amazon_pay.php b/public/admin/controller/extension/module/amazon_pay.php new file mode 100644 index 0000000..441eabf --- /dev/null +++ b/public/admin/controller/extension/module/amazon_pay.php @@ -0,0 +1,115 @@ +<?php +class ControllerExtensionModuleAmazonPay extends Controller { + private $version = '3.1'; + private $error = array(); + + public function index() { + $this->load->language('extension/module/amazon_pay'); + + $this->load->model('setting/setting'); + $this->load->model('design/layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_amazon_pay', $this->request->post); + + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_pay'); + $this->model_setting_event->addEvent('amazon_pay', 'catalog/controller/account/logout/after', 'extension/module/amazon_pay/logout'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['heading_title'] = $this->language->get('heading_title') . ' ' . $this->version; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'separator' => false + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true), + 'separator' => ' :: ' + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/amazon_pay', 'user_token=' . $this->session->data['user_token'], true), + 'separator' => ' :: ' + ); + + $data['action'] = $this->url->link('extension/module/amazon_pay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['module_amazon_pay_button_type'])) { + $data['module_amazon_pay_button_type'] = $this->request->post['module_amazon_pay_button_type']; + } elseif ($this->config->get('module_amazon_pay_button_type')) { + $data['module_amazon_pay_button_type'] = $this->config->get('module_amazon_pay_button_type'); + } else { + $data['module_amazon_pay_button_type'] = 'PwA'; + } + + if (isset($this->request->post['module_amazon_pay_button_colour'])) { + $data['module_amazon_pay_button_colour'] = $this->request->post['module_amazon_pay_button_colour']; + } elseif ($this->config->get('module_amazon_pay_button_colour')) { + $data['module_amazon_pay_button_colour'] = $this->config->get('module_amazon_pay_button_colour'); + } else { + $data['module_amazon_pay_button_colour'] = 'gold'; + } + + if (isset($this->request->post['module_amazon_pay_button_size'])) { + $data['module_amazon_pay_button_size'] = $this->request->post['module_amazon_pay_button_size']; + } elseif ($this->config->get('module_amazon_pay_button_size')) { + $data['module_amazon_pay_button_size'] = $this->config->get('module_amazon_pay_button_size'); + } else { + $data['module_amazon_pay_button_size'] = 'medium'; + } + + if (isset($this->request->post['module_amazon_pay_status'])) { + $data['module_amazon_pay_status'] = $this->request->post['module_amazon_pay_status']; + } else { + $data['module_amazon_pay_status'] = $this->config->get('module_amazon_pay_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/amazon_pay', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/amazon_pay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_pay'); + } + + public function uninstall() { + $this->load->model('setting/event'); + $this->model_setting_event->deleteEventByCode('amazon_pay'); + } + +} diff --git a/public/admin/controller/extension/module/banner.php b/public/admin/controller/extension/module/banner.php new file mode 100644 index 0000000..a2e47e9 --- /dev/null +++ b/public/admin/controller/extension/module/banner.php @@ -0,0 +1,154 @@ +<?php +class ControllerExtensionModuleBanner extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/banner'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('banner', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/banner', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/banner', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/banner', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/banner', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['banner_id'])) { + $data['banner_id'] = $this->request->post['banner_id']; + } elseif (!empty($module_info)) { + $data['banner_id'] = $module_info['banner_id']; + } else { + $data['banner_id'] = ''; + } + + $this->load->model('design/banner'); + + $data['banners'] = $this->model_design_banner->getBanners(); + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = ''; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/banner', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/banner')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/bestseller.php b/public/admin/controller/extension/module/bestseller.php new file mode 100644 index 0000000..3b5db39 --- /dev/null +++ b/public/admin/controller/extension/module/bestseller.php @@ -0,0 +1,152 @@ +<?php +class ControllerExtensionModuleBestSeller extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/bestseller'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('bestseller', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->cache->delete('product'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/bestseller', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/bestseller', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/bestseller', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/bestseller', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['limit'])) { + $data['limit'] = $this->request->post['limit']; + } elseif (!empty($module_info)) { + $data['limit'] = $module_info['limit']; + } else { + $data['limit'] = 5; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 200; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 200; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/bestseller', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/bestseller')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/carousel.php b/public/admin/controller/extension/module/carousel.php new file mode 100644 index 0000000..0d0c244 --- /dev/null +++ b/public/admin/controller/extension/module/carousel.php @@ -0,0 +1,158 @@ +<?php +class ControllerExtensionModuleCarousel extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/carousel'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('carousel', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/carousel', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/carousel', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/carousel', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/carousel', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['banner_id'])) { + $data['banner_id'] = $this->request->post['banner_id']; + } elseif (!empty($module_info)) { + $data['banner_id'] = $module_info['banner_id']; + } else { + $data['banner_id'] = ''; + } + + $this->load->model('design/banner'); + + $data['banners'] = $this->model_design_banner->getBanners(); + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 130; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 100; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $this->load->model('design/banner'); + + $data['banners'] = $this->model_design_banner->getBanners(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/carousel', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/carousel')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/category.php b/public/admin/controller/extension/module/category.php new file mode 100644 index 0000000..1eb9fe0 --- /dev/null +++ b/public/admin/controller/extension/module/category.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleCategory extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/category'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_category', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/category', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/category', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_category_status'])) { + $data['module_category_status'] = $this->request->post['module_category_status']; + } else { + $data['module_category_status'] = $this->config->get('module_category_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/category', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/category')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/divido_calculator.php b/public/admin/controller/extension/module/divido_calculator.php new file mode 100644 index 0000000..9442142 --- /dev/null +++ b/public/admin/controller/extension/module/divido_calculator.php @@ -0,0 +1,64 @@ +<?php +class ControllerExtensionModuleDividoCalculator extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/divido_calculator'); + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_divido_calculator', $this->request->post); + $this->session->data['success'] = $this->language->get('text_success'); + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/divido_calculator', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/divido_calculator', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_divido_calculator_status'])) { + $data['module_divido_calculator_status'] = $this->request->post['module_divido_calculator_status']; + } else { + $data['module_divido_calculator_status'] = $this->config->get('module_divido_calculator_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/divido_calculator', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/divido_calculator')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/ebay_listing.php b/public/admin/controller/extension/module/ebay_listing.php new file mode 100644 index 0000000..2446110 --- /dev/null +++ b/public/admin/controller/extension/module/ebay_listing.php @@ -0,0 +1,208 @@ +<?php +class ControllerExtensionModuleEbayListing extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/ebay_listing'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_ebay_listing', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->cache->delete('ebay'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/ebay_listing', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/ebay_listing', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['ebay_listing_username'])) { + $data['ebay_listing_username'] = $this->request->post['ebay_listing_username']; + } else { + $data['ebay_listing_username'] = $this->config->get('ebay_listing_username'); + } + + if (isset($this->request->post['ebay_listing_keywords'])) { + $data['ebay_listing_keywords'] = $this->request->post['ebay_listing_keywords']; + } else { + $data['ebay_listing_keywords'] = $this->config->get('ebay_listing_keywords'); + } + + if (isset($this->request->post['ebay_listing_description'])) { + $data['ebay_listing_description'] = $this->request->post['ebay_listing_description']; + } else { + $data['ebay_listing_description'] = $this->config->get('ebay_listing_description'); + } + + if (isset($this->request->post['ebay_listing_limit'])) { + $data['ebay_listing_limit'] = $this->request->post['ebay_listing_limit']; + } elseif ($this->config->has('ebay_listing_limit')) { + $data['ebay_listing_limit'] = $this->config->get('ebay_listing_limit'); + } else { + $data['ebay_listing_limit'] = 5; + } + + if (isset($this->request->post['ebay_listing_width'])) { + $data['ebay_listing_width'] = $this->request->post['width']; + } elseif ($this->config->has('ebay_listing_width')) { + $data['ebay_listing_width'] = $this->config->get('ebay_listing_width'); + } else { + $data['ebay_listing_width'] = 200; + } + + if (isset($this->request->post['ebay_listing_height'])) { + $data['ebay_listing_height'] = $this->request->post['ebay_listing_height']; + } elseif ($this->config->has('ebay_listing_height')) { + $data['ebay_listing_height'] = $this->config->get('ebay_listing_height'); + } else { + $data['ebay_listing_height'] = 200; + } + + if (isset($this->request->post['ebay_listing_sort'])) { + $data['ebay_listing_sort'] = $this->request->post['ebay_listing_sort']; + } elseif ($this->config->has('ebay_listing_sort')) { + $data['ebay_listing_sort'] = $this->config->get('ebay_listing_sort'); + } else { + $data['ebay_listing_sort'] = 'StartTimeNewest'; + } + + if (isset($this->request->post['ebay_listing_site'])) { + $data['ebay_listing_site'] = $this->request->post['ebay_listing_site']; + } else { + $data['ebay_listing_site'] = $this->config->get('ebay_listing_site'); + } + + $data['sites'] = array(); + + $data['sites'][] = array( + 'text' => 'USA', + 'value' => 0 + ); + + $data['sites'][] = array( + 'text' => 'UK', + 'value' => 3 + ); + $data['sites'][] = array( + 'text' => 'Australia', + 'value' => 15 + ); + + $data['sites'][] = array( + 'text' => 'Canada (English)', + 'value' => 2 + ); + + $data['sites'][] = array( + 'text' => 'France', + 'value' => 71 + ); + $data['sites'][] = array( + 'text' => 'Germany', + 'value' => 77 + ); + $data['sites'][] = array( + 'text' => 'Italy', + 'value' => 101 + ); + $data['sites'][] = array( + 'text' => 'Spain', + 'value' => 186 + ); + $data['sites'][] = array( + 'text' => 'Ireland', + 'value' => 205 + ); + + $data['sites'][] = array( + 'text' => 'Austria', + 'value' => 16 + ); + + $data['sites'][] = array( + 'text' => 'Netherlands', + 'value' => 146 + ); + + $data['sites'][] = array( + 'text' => 'Belgium (French)', + 'value' => 23 + ); + + $data['sites'][] = array( + 'text' => 'Belgium (Dutch)', + 'value' => 123 + ); + + if (isset($this->request->post['ebay_listing_status'])) { + $data['ebay_listing_status'] = $this->request->post['ebay_listing_status']; + } else { + $data['ebay_listing_status'] = $this->config->get('ebay_listing_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/ebay_listing', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/ebay_listing')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['ebay_listing_width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['ebay_listing_height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/featured.php b/public/admin/controller/extension/module/featured.php new file mode 100644 index 0000000..d72d54e --- /dev/null +++ b/public/admin/controller/extension/module/featured.php @@ -0,0 +1,175 @@ +<?php +class ControllerExtensionModuleFeatured extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/featured'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('featured', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + $this->load->model('catalog/product'); + + $data['products'] = array(); + + if (!empty($this->request->post['product'])) { + $products = $this->request->post['product']; + } elseif (!empty($module_info['product'])) { + $products = $module_info['product']; + } else { + $products = array(); + } + + foreach ($products as $product_id) { + $product_info = $this->model_catalog_product->getProduct($product_id); + + if ($product_info) { + $data['products'][] = array( + 'product_id' => $product_info['product_id'], + 'name' => $product_info['name'] + ); + } + } + + if (isset($this->request->post['limit'])) { + $data['limit'] = $this->request->post['limit']; + } elseif (!empty($module_info)) { + $data['limit'] = $module_info['limit']; + } else { + $data['limit'] = 5; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 200; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 200; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/featured', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/featured')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/filter.php b/public/admin/controller/extension/module/filter.php new file mode 100644 index 0000000..0b0170a --- /dev/null +++ b/public/admin/controller/extension/module/filter.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModulefilter extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/filter'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_filter', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/filter', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/filter', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_filter_status'])) { + $data['module_filter_status'] = $this->request->post['module_filter_status']; + } else { + $data['module_filter_status'] = $this->config->get('module_filter_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/filter', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/filter')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/google_hangouts.php b/public/admin/controller/extension/module/google_hangouts.php new file mode 100644 index 0000000..8f6058f --- /dev/null +++ b/public/admin/controller/extension/module/google_hangouts.php @@ -0,0 +1,83 @@ +<?php +class ControllerExtensionModuleGoogleHangouts extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/google_hangouts'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_google_hangouts', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['code'])) { + $data['error_code'] = $this->error['code']; + } else { + $data['error_code'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/google_hangouts', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/google_hangouts', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_google_hangouts_code'])) { + $data['module_google_hangouts_code'] = $this->request->post['module_google_hangouts_code']; + } else { + $data['module_google_hangouts_code'] = $this->config->get('module_google_hangouts_code'); + } + + if (isset($this->request->post['module_google_hangouts_status'])) { + $data['module_google_hangouts_status'] = $this->request->post['module_google_hangouts_status']; + } else { + $data['module_google_hangouts_status'] = $this->config->get('module_google_hangouts_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/google_hangouts', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/google_hangouts')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['module_google_hangouts_code']) { + $this->error['code'] = $this->language->get('error_code'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/html.php b/public/admin/controller/extension/module/html.php new file mode 100644 index 0000000..f34cace --- /dev/null +++ b/public/admin/controller/extension/module/html.php @@ -0,0 +1,118 @@ +<?php +class ControllerExtensionModuleHTML extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/html'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('html', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/html', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/html', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/html', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/html', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['module_description'])) { + $data['module_description'] = $this->request->post['module_description']; + } elseif (!empty($module_info)) { + $data['module_description'] = $module_info['module_description']; + } else { + $data['module_description'] = array(); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/html', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/html')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/information.php b/public/admin/controller/extension/module/information.php new file mode 100644 index 0000000..107aa3f --- /dev/null +++ b/public/admin/controller/extension/module/information.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleInformation extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/information'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_information', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/information', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/information', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_information_status'])) { + $data['module_information_status'] = $this->request->post['module_information_status']; + } else { + $data['module_information_status'] = $this->config->get('module_information_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/information', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/information')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/klarna_checkout_module.php b/public/admin/controller/extension/module/klarna_checkout_module.php new file mode 100644 index 0000000..9d0b200 --- /dev/null +++ b/public/admin/controller/extension/module/klarna_checkout_module.php @@ -0,0 +1,72 @@ +<?php +class ControllerExtensionModuleKlarnaCheckoutModule extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/klarna_checkout_module'); + + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_klarna_checkout_module', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/klarna_checkout_module', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/klarna_checkout_module', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_klarna_checkout_status'])) { + $data['module_klarna_checkout_status'] = $this->request->post['module_klarna_checkout_status']; + } else { + $data['module_klarna_checkout_status'] = $this->config->get('module_klarna_checkout_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/klarna_checkout_module', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/klarna_checkout_module')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->error) { + return true; + } else { + return false; + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/latest.php b/public/admin/controller/extension/module/latest.php new file mode 100644 index 0000000..f01f34e --- /dev/null +++ b/public/admin/controller/extension/module/latest.php @@ -0,0 +1,152 @@ +<?php +class ControllerExtensionModuleLatest extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/latest'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('latest', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->cache->delete('product'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/latest', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/latest', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/latest', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/latest', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['limit'])) { + $data['limit'] = $this->request->post['limit']; + } elseif (!empty($module_info)) { + $data['limit'] = $module_info['limit']; + } else { + $data['limit'] = 5; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 200; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 200; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/latest', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/latest')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/laybuy_layout.php b/public/admin/controller/extension/module/laybuy_layout.php new file mode 100644 index 0000000..bb34b4e --- /dev/null +++ b/public/admin/controller/extension/module/laybuy_layout.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleLaybuyLayout extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + + $this->load->language('extension/module/laybuy_layout'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_laybuy_layout', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/laybuy_layout', 'user_token=' . $this->session->data['user_token'], true) + ); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['action'] = $this->url->link('extension/module/laybuy_layout', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_laybuy_layout_status'])) { + $data['module_laybuy_layout_status'] = $this->request->post['module_laybuy_layout_status']; + } else { + $data['module_laybuy_layout_status'] = $this->config->get('module_laybuy_layout_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/laybuy_layout', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/laybuy_layout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/pilibaba_button.php b/public/admin/controller/extension/module/pilibaba_button.php new file mode 100644 index 0000000..1948588 --- /dev/null +++ b/public/admin/controller/extension/module/pilibaba_button.php @@ -0,0 +1,65 @@ +<?php +class ControllerExtensionModulePilibabaButton extends Controller { + public function index() { + $this->load->language('extension/module/pilibaba_button'); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_pilibaba_button', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/pilibaba_button', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/pilibaba_button', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_pilibaba_button_status'])) { + $data['module_pilibaba_button_status'] = $this->request->post['module_pilibaba_button_status']; + } else { + $data['module_pilibaba_button_status'] = $this->config->get('module_pilibaba_button_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/pilibaba_button', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/pilibaba_button')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/pp_braintree_button.php b/public/admin/controller/extension/module/pp_braintree_button.php new file mode 100644 index 0000000..bce800a --- /dev/null +++ b/public/admin/controller/extension/module/pp_braintree_button.php @@ -0,0 +1,93 @@ +<?php +class ControllerExtensionModulePPBraintreeButton extends Controller { + public function index() { + $this->load->language('extension/module/pp_braintree_button'); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_pp_braintree_button', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/pp_braintree_button', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/pp_braintree_button', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + $data['layouts'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['module_pp_braintree_button_status'])) { + $data['module_pp_braintree_button_status'] = $this->request->post['module_pp_braintree_button_status']; + } else { + $data['module_pp_braintree_button_status'] = $this->config->get('module_pp_braintree_button_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/pp_braintree_button', $data)); + } + + public function install() { + $this->load->model('setting/setting'); + + $settings['module_pp_braintree_button_status'] = 1; + + $this->model_setting_setting->editSetting('module_pp_braintree_button', $settings); + } + + public function configure() { + $this->load->language('extension/extension/module'); + + if (!$this->user->hasPermission('modify', 'extension/extension/module')) { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_setting_extension->install('module', 'pp_braintree_button'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/module/pp_braintree_button'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/module/pp_braintree_button'); + + $this->install(); + + $this->response->redirect($this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/pp_braintree_button')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/pp_button.php b/public/admin/controller/extension/module/pp_button.php new file mode 100644 index 0000000..5ca281d --- /dev/null +++ b/public/admin/controller/extension/module/pp_button.php @@ -0,0 +1,94 @@ +<?php +class ControllerExtensionModulePPButton extends Controller { + public function index() { + $this->load->language('extension/module/pp_button'); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_pp_button', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/pp_button', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/pp_button', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + $data['layouts'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['module_pp_button_status'])) { + $data['module_pp_button_status'] = $this->request->post['module_pp_button_status']; + } else { + $data['module_pp_button_status'] = $this->config->get('module_pp_button_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/pp_button', $data)); + } + + public function install() { + $this->load->model('setting/setting'); + + $settings['module_pp_button_status'] = 1; + + $this->model_setting_setting->editSetting('module_pp_button', $settings); + } + + public function configure() { + $this->load->language('extension/extension/module'); + + if (!$this->user->hasPermission('modify', 'extension/extension/module')) { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_setting_extension->install('module', 'pp_button'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/module/pp_button'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/module/pp_button'); + + $this->install(); + + $this->response->redirect($this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/pp_button')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/pp_login.php b/public/admin/controller/extension/module/pp_login.php new file mode 100644 index 0000000..c174cd6 --- /dev/null +++ b/public/admin/controller/extension/module/pp_login.php @@ -0,0 +1,295 @@ +<?php +class ControllerExtensionModulePPLogin extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/pp_login'); + + $this->load->model('setting/setting'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_pp_login', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['client_id'])) { + $data['error_client_id'] = $this->error['client_id']; + } else { + $data['error_client_id'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/pp_login', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/pp_login', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_pp_login_client_id'])) { + $data['module_pp_login_client_id'] = $this->request->post['module_pp_login_client_id']; + } else { + $data['module_pp_login_client_id'] = $this->config->get('module_pp_login_client_id'); + } + + if (isset($this->request->post['module_pp_login_secret'])) { + $data['module_pp_login_secret'] = $this->request->post['module_pp_login_secret']; + } else { + $data['module_pp_login_secret'] = $this->config->get('module_pp_login_secret'); + } + + if (isset($this->request->post['module_pp_login_sandbox'])) { + $data['module_pp_login_sandbox'] = $this->request->post['module_pp_login_sandbox']; + } else { + $data['module_pp_login_sandbox'] = $this->config->get('module_pp_login_sandbox'); + } + + if (isset($this->request->post['module_pp_login_debug'])) { + $data['module_pp_login_debug'] = $this->request->post['module_pp_login_debug']; + } else { + $data['module_pp_login_debug'] = $this->config->get('module_pp_login_debug'); + } + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + if (isset($this->request->post['module_pp_login_customer_group_id'])) { + $data['module_pp_login_customer_group_id'] = $this->request->post['module_pp_login_customer_group_id']; + } else { + $data['module_pp_login_customer_group_id'] = $this->config->get('module_pp_login_customer_group_id'); + } + + if (isset($this->request->post['module_pp_login_button_colour'])) { + $data['module_pp_login_button_colour'] = $this->request->post['module_pp_login_button_colour']; + } elseif ($this->config->get('module_pp_login_button_colour')) { + $data['module_pp_login_button_colour'] = $this->config->get('module_pp_login_button_colour'); + } else { + $data['module_pp_login_button_colour'] = 'blue'; + } + + if (isset($this->request->post['module_pp_login_seamless'])) { + $data['module_pp_login_seamless'] = $this->request->post['module_pp_login_seamless']; + } else { + $data['module_pp_login_seamless'] = $this->config->get('module_pp_login_seamless'); + } + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + $data['locales'] = array(); + + $data['locales'][] = array( + 'value' => 'en-gb', + 'text' => 'English (Great Britain)' + ); + + $data['locales'][] = array( + 'value' => 'zh-cn', + 'text' => 'Chinese (People\'s Republic of China)' + ); + + $data['locales'][] = array( + 'value' => 'zh-hk', + 'text' => 'Chinese (Hong Kong)', + ); + + $data['locales'][] = array( + 'value' => 'zh-tw', + 'text' => 'Chinese (Taiwan)' + ); + + $data['locales'][] = array( + 'value' => 'zh-xc', + 'text' => 'Chinese (US)' + ); + + $data['locales'][] = array( + 'value' => 'da-dk', + 'text' => 'Danish' + ); + + $data['locales'][] = array( + 'value' => 'nl-nl', + 'text' => 'Dutch' + ); + + $data['locales'][] = array( + 'value' => 'en-au', + 'text' => 'English (Australia)' + ); + + $data['locales'][] = array( + 'value' => 'en-us', + 'text' => 'English (US)', + ); + + $data['locales'][] = array( + 'value' => 'fr-fr', + 'text' => 'French' + ); + + $data['locales'][] = array( + 'value' => 'fr-ca', + 'text' => 'French (Canada)' + ); + + $data['locales'][] = array( + 'value' => 'fr-xc', + 'text' => 'French (international)' + ); + + $data['locales'][] = array( + 'value' => 'de-de', + 'text' => 'German' + ); + + $data['locales'][] = array( + 'value' => 'he-il', + 'text' => 'Hebrew (Israel)' + ); + + $data['locales'][] = array( + 'value' => 'id-id', + 'text' => 'Indonesian' + ); + + $data['locales'][] = array( + 'value' => 'it-il', + 'text' => 'Italian' + ); + + $data['locales'][] = array( + 'value' => 'ja-jp' , + 'text' => 'Japanese' + ); + + $data['locales'][] = array( + 'value' => 'no-no', + 'text' => 'Norwegian' + ); + + $data['locales'][] = array( + 'value' => 'pl-pl', + 'text' => 'Polish'); + + $data['locales'][] = array( + 'value' => 'pt-pt', + 'text' => 'Portuguese' + ); + + $data['locales'][] = array( + 'value' => 'pt-br', + 'text' => 'Portuguese (Brazil)' + ); + + $data['locales'][] = array( + 'value' => 'ru-ru', + 'text' => 'Russian' + ); + + $data['locales'][] = array( + 'value' => 'es-es', + 'text' => 'Spanish' + ); + + $data['locales'][] = array( + 'value' => 'es-xc', + 'text' => 'Spanish (Mexico)' + ); + + $data['locales'][] = array( + 'value' => 'sv-se', + 'text' => 'Swedish' + ); + + $data['locales'][] = array( + 'value' => 'th-th', + 'text' => 'Thai' + ); + + $data['locales'][] = array( + 'value' => 'tr-tr', + 'text' => 'Turkish' + ); + + if (isset($this->request->post['module_pp_login_locale'])) { + $data['module_pp_login_locale'] = $this->request->post['module_pp_login_locale']; + } else { + $data['module_pp_login_locale'] = $this->config->get('module_pp_login_locale'); + } + + $data['return_url'] = HTTPS_CATALOG . 'index.php?route=extension/module/pp_login/login'; + + if (isset($this->request->post['module_pp_login_status'])) { + $data['module_pp_login_status'] = $this->request->post['module_pp_login_status']; + } else { + $data['module_pp_login_status'] = $this->config->get('module_pp_login_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/pp_login', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/pp_login')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['module_pp_login_client_id']) { + $this->error['client_id'] = $this->language->get('error_client_id'); + } + + if (!$this->request->post['module_pp_login_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('marketplace/event'); + + $this->model_setting_event->addEvent('pp_login', 'catalog/controller/account/logout/after', 'extension/module/pp_login/logout'); + } + + public function uninstall() { + $this->load->model('marketplace/event'); + + $this->model_setting_event->deleteEventByCode('pp_login'); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/sagepay_direct_cards.php b/public/admin/controller/extension/module/sagepay_direct_cards.php new file mode 100644 index 0000000..ae5b188 --- /dev/null +++ b/public/admin/controller/extension/module/sagepay_direct_cards.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleSagepayDirectCards extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/sagepay_direct_cards'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_sagepay_direct_cards', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/sagepay_direct_cards', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/sagepay_direct_cards', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_sagepay_direct_cards_status'])) { + $data['module_sagepay_direct_cards_status'] = $this->request->post['module_sagepay_direct_cards_status']; + } else { + $data['module_sagepay_direct_cards_status'] = $this->config->get('module_sagepay_direct_cards_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/sagepay_direct_cards', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/sagepay_direct_cards')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/sagepay_server_cards.php b/public/admin/controller/extension/module/sagepay_server_cards.php new file mode 100644 index 0000000..1b8a480 --- /dev/null +++ b/public/admin/controller/extension/module/sagepay_server_cards.php @@ -0,0 +1,67 @@ +<?php +class ControllerExtensionModuleSagepayServerCards extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/sagepay_server_cards'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_sagepay_server_cards', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/sagepay_server_cards', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/sagepay_server_cards', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_sagepay_server_cards_status'])) { + $data['module_sagepay_server_cards_status'] = $this->request->post['module_sagepay_server_cards_status']; + } else { + $data['module_sagepay_server_cards_status'] = $this->config->get('module_sagepay_server_cards_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/sagepay_server_cards', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/sagepay_server_cards')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/slideshow.php b/public/admin/controller/extension/module/slideshow.php new file mode 100644 index 0000000..dc31c00 --- /dev/null +++ b/public/admin/controller/extension/module/slideshow.php @@ -0,0 +1,154 @@ +<?php +class ControllerExtensionModuleSlideshow extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/slideshow'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('slideshow', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/slideshow', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/slideshow', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/slideshow', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/slideshow', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['banner_id'])) { + $data['banner_id'] = $this->request->post['banner_id']; + } elseif (!empty($module_info)) { + $data['banner_id'] = $module_info['banner_id']; + } else { + $data['banner_id'] = ''; + } + + $this->load->model('design/banner'); + + $data['banners'] = $this->model_design_banner->getBanners(); + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = ''; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = ''; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/slideshow', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/slideshow')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/module/special.php b/public/admin/controller/extension/module/special.php new file mode 100644 index 0000000..ef86dd3 --- /dev/null +++ b/public/admin/controller/extension/module/special.php @@ -0,0 +1,152 @@ +<?php +class ControllerExtensionModuleSpecial extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/special'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/module'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->get['module_id'])) { + $this->model_setting_module->addModule('special', $this->request->post); + } else { + $this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post); + } + + $this->cache->delete('product'); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['name'])) { + $data['error_name'] = $this->error['name']; + } else { + $data['error_name'] = ''; + } + + if (isset($this->error['width'])) { + $data['error_width'] = $this->error['width']; + } else { + $data['error_width'] = ''; + } + + if (isset($this->error['height'])) { + $data['error_height'] = $this->error['height']; + } else { + $data['error_height'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + if (!isset($this->request->get['module_id'])) { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/special', 'user_token=' . $this->session->data['user_token'], true) + ); + } else { + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/special', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true) + ); + } + + if (!isset($this->request->get['module_id'])) { + $data['action'] = $this->url->link('extension/module/special', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/module/special', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true); + } + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $module_info = $this->model_setting_module->getModule($this->request->get['module_id']); + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($module_info)) { + $data['name'] = $module_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['limit'])) { + $data['limit'] = $this->request->post['limit']; + } elseif (!empty($module_info)) { + $data['limit'] = $module_info['limit']; + } else { + $data['limit'] = 5; + } + + if (isset($this->request->post['width'])) { + $data['width'] = $this->request->post['width']; + } elseif (!empty($module_info)) { + $data['width'] = $module_info['width']; + } else { + $data['width'] = 200; + } + + if (isset($this->request->post['height'])) { + $data['height'] = $this->request->post['height']; + } elseif (!empty($module_info)) { + $data['height'] = $module_info['height']; + } else { + $data['height'] = 200; + } + + if (isset($this->request->post['status'])) { + $data['status'] = $this->request->post['status']; + } elseif (!empty($module_info)) { + $data['status'] = $module_info['status']; + } else { + $data['status'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/special', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/special')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) { + $this->error['name'] = $this->language->get('error_name'); + } + + if (!$this->request->post['width']) { + $this->error['width'] = $this->language->get('error_width'); + } + + if (!$this->request->post['height']) { + $this->error['height'] = $this->language->get('error_height'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/module/store.php b/public/admin/controller/extension/module/store.php new file mode 100644 index 0000000..cad1dd9 --- /dev/null +++ b/public/admin/controller/extension/module/store.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionModuleStore extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/module/store'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('module_store', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/module/store', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/module/store', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true); + + if (isset($this->request->post['module_store_admin'])) { + $data['module_store_admin'] = $this->request->post['module_store_admin']; + } else { + $data['module_store_admin'] = $this->config->get('module_store_admin'); + } + + if (isset($this->request->post['module_store_status'])) { + $data['module_store_status'] = $this->request->post['module_store_status']; + } else { + $data['module_store_status'] = $this->config->get('module_store_status'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/module/store', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/module/store')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/openbay/amazon.php b/public/admin/controller/extension/openbay/amazon.php new file mode 100644 index 0000000..dd3178b --- /dev/null +++ b/public/admin/controller/extension/openbay/amazon.php @@ -0,0 +1,1129 @@ +<?php +class ControllerExtensionOpenbayAmazon extends Controller { + public function install() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/amazon_listing'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/amazon_listing'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/amazon_product'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/amazon_product'); + + $this->model_extension_openbay_amazon->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_amazon->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/amazon'); + + $this->load->language('extension/openbay/amazon'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + $data['success'] = ''; + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['validation'] = $this->openbay->amazon->validate(); + $data['link_settings'] = $this->url->link('extension/openbay/amazon/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_subscription'] = $this->url->link('extension/openbay/amazon/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['link_item_link'] = $this->url->link('extension/openbay/amazon/itemLinks', 'user_token=' . $this->session->data['user_token'], true); + $data['link_stock_updates'] = $this->url->link('extension/openbay/amazon/stockUpdates', 'user_token=' . $this->session->data['user_token'], true); + $data['link_saved_listings'] = $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_bulk_listing'] = $this->url->link('extension/openbay/amazon/bulkListProducts', 'user_token=' . $this->session->data['user_token'], true); + $data['link_bulk_linking'] = $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/amazon/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=amazon'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon', $data)); + } + + public function stockUpdates() { + $this->load->language('extension/openbay/amazon_stockupdates'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/stockUpdates', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['link_overview'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $request_arg = array(); + + if (isset($this->request->get['filter_date_start'])) { + $request_arg['date_start'] = date("Y-m-d", strtotime($this->request->get['filter_date_start'])); + } else { + $request_arg['date_start'] = date("Y-m-d"); + } + + if (isset($this->request->get['filter_date_end'])) { + $request_arg['date_end'] = date("Y-m-d", strtotime($this->request->get['filter_date_end'])); + } else { + $request_arg['date_end'] = date("Y-m-d"); + } + + $data['date_start'] = $request_arg['date_start']; + $data['date_end'] = $request_arg['date_end']; + + $xml = $this->openbay->amazon->getStockUpdatesStatus($request_arg); + $xml_object = simplexml_load_string($xml); + + $data['table_data'] = array(); + + if ($xml_object !== false) { + $table_data = array(); + + foreach($xml_object->update as $update_node) { + $row = array( + 'date_requested' => (string)$update_node->date_requested, + 'date_updated' => (string)$update_node->date_updated, + 'status' => (string)$update_node->status, + ); + + $data_items = array(); + + foreach($update_node->data->product as $product_node) { + $data_items[] = array( + 'sku' => (string)$product_node->sku, + 'stock' => (int)$product_node->stock + ); + } + + $row['data'] = $data_items; + $table_data[(int)$update_node->ref] = $row; + } + + $data['table_data'] = $table_data; + } else { + $data['error'] = $data['error_api_connection']; + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_stock_updates', $data)); + + } + + public function subscription() { + $this->load->language('extension/openbay/amazon_subscription'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/subscription', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['link_overview'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $response = simplexml_load_string($this->openbay->amazon->call('plans/getPlans')); + + $data['plans'] = array(); + + if ($response) { + foreach ($response->Plan as $plan) { + $data['plans'][] = array( + 'title' => (string)$plan->Title, + 'description' => (string)$plan->Description, + 'order_frequency' => (string)$plan->OrderFrequency, + 'product_listings' => (string)$plan->ProductListings, + 'bulk_listing' => (string)$plan->BulkListing, + 'price' => (string)$plan->Price, + ); + } + } + + $response = simplexml_load_string($this->openbay->amazon->call('plans/getUsersPlans')); + + $plan = false; + + if ($response) { + $plan = array( + 'merchant_id' => (string)$response->MerchantId, + 'user_status' => (string)$response->UserStatus, + 'title' => (string)$response->Title, + 'description' => (string)$response->Description, + 'price' => (string)$response->Price, + 'order_frequency' => (string)$response->OrderFrequency, + 'product_listings' => (string)$response->ProductListings, + 'listings_remain' => (string)$response->ListingsRemain, + 'listings_reserved' => (string)$response->ListingsReserved, + 'bulk_listing' => (string)$response->BulkListing, + ); + } + + $data['user_plan'] = $plan; + $data['link_change_plan'] = $this->openbay->amazon->getServer() . 'account/changePlan/?token=' . $this->config->get('openbay_amazon_token'); + $data['link_change_seller'] = $this->openbay->amazon->getServer() . 'account/changeSellerId/?token=' . $this->config->get('openbay_amazon_token'); + $data['link_register'] = 'https://account.openbaypro.com/amazon/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=subscription&utm_campaign=amazon'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_subscription', $data)); + } + + public function settings() { + $this->load->language('extension/openbay/amazon_settings'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/amazon'); + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + $settings = $this->model_setting_setting->getSetting('openbay_amazon'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + if (!isset($this->request->post['openbay_amazon_orders_marketplace_ids'])) { + $this->request->post['openbay_amazon_orders_marketplace_ids'] = array(); + } + + $settings = array_merge($settings, $this->request->post); + $this->model_setting_setting->editSetting('openbay_amazon', $settings); + + $this->config->set('openbay_amazon_token', $this->request->post['openbay_amazon_token']); + $this->config->set('openbay_amazon_encryption_key', $this->request->post['openbay_amazon_encryption_key']); + $this->config->set('openbay_amazon_encryption_iv', $this->request->post['openbay_amazon_encryption_iv']); + + $this->openbay->amazon->setEncryptionKey($this->request->post['openbay_amazon_encryption_key']); + $this->openbay->amazon->setEncryptionIv($this->request->post['openbay_amazon_encryption_iv']); + + if (!empty($this->request->post['openbay_amazon_token']) && !empty($this->request->post['openbay_amazon_encryption_key']) && !empty($this->request->post['openbay_amazon_encryption_iv'])) { + $this->model_extension_openbay_amazon->verifyConfig($settings); + } + + $this->session->data['success'] = $this->language->get('text_settings_updated'); + $this->response->redirect($this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + $data['cancel'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['marketplace_ids'] = (isset($settings['openbay_amazon_orders_marketplace_ids'])) ? (array)$settings['openbay_amazon_orders_marketplace_ids'] : array(); + $data['default_listing_marketplace_ids'] = (isset($settings['openbay_amazon_default_listing_marketplace_ids'])) ? (array)$settings['openbay_amazon_default_listing_marketplace_ids'] : array(); + + $data['marketplaces'] = array( + array('name' => $this->language->get('text_de'), 'id' => 'A1PA6795UKMFR9', 'code' => 'de'), + array('name' => $this->language->get('text_fr'), 'id' => 'A13V1IB3VIYZZH', 'code' => 'fr'), + array('name' => $this->language->get('text_it'), 'id' => 'APJ6JRA9NG5V4', 'code' => 'it'), + array('name' => $this->language->get('text_es'), 'id' => 'A1RKKUPIHCS9HS', 'code' => 'es'), + array('name' => $this->language->get('text_uk'), 'id' => 'A1F83G8C2ARO7P', 'code' => 'uk'), + ); + + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['openbay_amazon_status'] = isset($settings['openbay_amazon_status']) ? $settings['openbay_amazon_status'] : ''; + $data['openbay_amazon_token'] = isset($settings['openbay_amazon_token']) ? $settings['openbay_amazon_token'] : ''; + $data['openbay_amazon_encryption_key'] = isset($settings['openbay_amazon_encryption_key']) ? $settings['openbay_amazon_encryption_key'] : ''; + $data['openbay_amazon_encryption_iv'] = isset($settings['openbay_amazon_encryption_iv']) ? $settings['openbay_amazon_encryption_iv'] : ''; + $data['openbay_amazon_listing_tax_added'] = isset($settings['openbay_amazon_listing_tax_added']) ? $settings['openbay_amazon_listing_tax_added'] : '0.00'; + $data['openbay_amazon_order_tax'] = isset($settings['openbay_amazon_order_tax']) ? $settings['openbay_amazon_order_tax'] : '00'; + $data['openbay_amazon_default_listing_marketplace'] = isset($settings['openbay_amazon_default_listing_marketplace']) ? $settings['openbay_amazon_default_listing_marketplace'] : ''; + $data['openbay_amazon_listing_default_condition'] = isset($settings['openbay_amazon_listing_default_condition']) ? $settings['openbay_amazon_listing_default_condition'] : ''; + + $data['carriers'] = $this->openbay->amazon->getCarriers(); + $data['openbay_amazon_default_carrier'] = isset($settings['openbay_amazon_default_carrier']) ? $settings['openbay_amazon_default_carrier'] : ''; + + $unshipped_status_id = isset($settings['openbay_amazon_order_status_unshipped']) ? $settings['openbay_amazon_order_status_unshipped'] : ''; + $partially_shipped_status_id = isset($settings['openbay_amazon_order_status_partially_shipped']) ? $settings['openbay_amazon_order_status_partially_shipped'] : ''; + $shipped_status_id = isset($settings['openbay_amazon_order_status_shipped']) ? $settings['openbay_amazon_order_status_shipped'] : ''; + $canceled_status_id = isset($settings['openbay_amazon_order_status_canceled']) ? $settings['openbay_amazon_order_status_canceled'] : ''; + + $amazon_order_statuses = array( + 'unshipped' => array('name' => $this->language->get('text_unshipped'), 'order_status_id' => $unshipped_status_id), + 'partially_shipped' => array('name' => $this->language->get('text_partially_shipped'), 'order_status_id' => $partially_shipped_status_id), + 'shipped' => array('name' => $this->language->get('text_shipped'), 'order_status_id' => $shipped_status_id), + 'canceled' => array('name' => $this->language->get('text_canceled'), 'order_status_id' => $canceled_status_id), + ); + + $data['openbay_amazon_order_customer_group'] = isset($settings['openbay_amazon_order_customer_group']) ? $settings['openbay_amazon_order_customer_group'] : ''; + + $data['amazon_order_statuses'] = $amazon_order_statuses; + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['subscription_url'] = $this->url->link('extension/openbay/amazon/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['itemLinks_url'] = $this->url->link('extension/openbay/amazon_product/linkItems', 'user_token=' . $this->session->data['user_token'], true); + $data['openbay_amazon_notify_admin'] = isset($settings['openbay_amazon_notify_admin']) ? $settings['openbay_amazon_notify_admin'] : ''; + $data['link_signup'] = 'https://account.openbaypro.com/amazon/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=amazon'; + + $api_checked = false; + $api_status = false; + $api_auth = false; + + if (!empty($data['openbay_amazon_token']) && !empty($data['openbay_amazon_encryption_key']) && !empty($data['openbay_amazon_encryption_iv'])) { + $response = $this->openbay->amazon->call('ping/info', array('say hello')); + + $api_checked = true; + + if (!empty($response)) { + $ping_info = simplexml_load_string($response); + + if ($ping_info === false) { + /** + * The data from the API could not be extracted from the XML + */ + } else { + $api_status = ((string)$ping_info->Api_status == 'ok') ? true : false; + $api_auth = ((string)$ping_info->Auth == 'true') ? true : false; + } + } + } + + $data['api_status'] = $api_status; + $data['api_auth'] = $api_auth; + $data['api_checked'] = $api_checked; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_settings', $data)); + } + + public function itemLinks() { + $this->load->language('extension/openbay/amazon_links'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/itemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['user_token'] = $this->session->data['user_token']; + + $data['cancel'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_item_links', $data)); + } + + public function savedListings() { + $this->load->language('extension/openbay/amazon_listingsaved'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['link_overview'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['user_token'] = $this->session->data['user_token']; + $this->load->model('extension/openbay/amazon'); + $saved_products = $this->model_extension_openbay_amazon->getSavedProducts(); + + $data['saved_products'] = array(); + + foreach($saved_products as $saved_product) { + $data['saved_products'][] = array( + 'product_id' => $saved_product['product_id'], + 'product_name' => $saved_product['product_name'], + 'product_model' => $saved_product['product_model'], + 'product_sku' => $saved_product['product_sku'], + 'amazon_sku' => $saved_product['amazon_sku'], + 'var' => $saved_product['var'], + 'edit_link' => $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $saved_product['product_id'] . '&sku=' . $saved_product['var'], true), + ); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_saved_listings', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/amazon')) { + $this->error = $this->language->get('error_permission'); + } + + if (empty($this->error)) { + return true; + } + + return false; + } + + public function getVariants() { + $variants = array(); + + if ($this->openbay->addonLoad('openstock') && isset($this->request->get['product_id'])) { + $this->load->model('extension/module/openstock'); + $this->load->model('tool/image'); + $variants = $this->model_setting_module_openstock->getVariants($this->request->get['product_id']); + } + + if (empty($variants)) { + $variants = false; + } else { + foreach ($variants as $key => $variant) { + if ($variant['sku'] == '') { + unset($variants[$key]); + } + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($variants)); + } + + public function addLink() { + if (isset($this->request->get['product_id']) && isset($this->request->get['amazon_sku'])) { + $this->load->model('extension/openbay/amazon'); + + $amazon_sku = $this->request->get['amazon_sku']; + $product_id = $this->request->get['product_id']; + $var = isset($this->request->get['var']) ? $this->request->get['var'] : ''; + + $this->model_extension_openbay_amazon->linkProduct($amazon_sku, $product_id, $var); + + $logger = new Log('amazon_stocks.log'); + $logger->write('addItemLink() called for product id: ' . $product_id . ', amazon sku: ' . $amazon_sku . ', var: ' . $var); + + if ($var != '' && $this->openbay->addonLoad('openstock')) { + $logger->write('Using openStock'); + $this->load->model('tool/image'); + $this->load->model('extension/module/openstock'); + $option_stocks = $this->model_setting_module_openstock->getVariants($product_id); + + $quantity_data = array(); + + foreach($option_stocks as $option_stock) { + if (isset($option_stock['sku']) && $option_stock['sku'] == $var) { + $quantity_data[$amazon_sku] = $option_stock['stock']; + break; + } + } + + if (!empty($quantity_data)) { + $logger->write('Updating quantities with data: ' . print_r($quantity_data, true)); + $this->openbay->amazon->updateQuantities($quantity_data); + } else { + $logger->write('No quantity data will be posted . '); + } + } else { + $this->openbay->amazon->putStockUpdateBulk(array($product_id)); + } + + $json = json_encode('ok'); + } else { + $json = json_encode('error'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function deleteLink() { + if (isset($this->request->get['amazon_sku'])) { + $this->load->model('extension/openbay/amazon'); + + $amazon_sku = $this->request->get['amazon_sku']; + + $this->model_extension_openbay_amazon->removeProductLink($amazon_sku); + + $json = json_encode('ok'); + } else { + $json = json_encode('error'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function getLinks() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + + $json = json_encode($this->model_extension_openbay_amazon->getProductLinks()); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function getUnlinked() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + + $json = json_encode($this->model_extension_openbay_amazon->getUnlinkedProducts()); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function doBulkList() { + $this->load->language('amazon/listing'); + + if (empty($this->request->post['products'])) { + $json = array( + 'message' => $this->language->get('error_not_searched'), + ); + } else { + $this->load->model('extension/openbay/amazon_listing'); + + $delete_search_results = array(); + + $bulk_list_products = array(); + + foreach ($this->request->post['products'] as $product_id => $asin) { + $delete_search_results[] = $product_id; + + if (!empty($asin) && in_array($product_id, $this->request->post['product_ids'])) { + $bulk_list_products[$product_id] = $asin; + } + } + + $status = false; + + if ($bulk_list_products) { + $data = array(); + + $data['products'] = $bulk_list_products; + $data['marketplace'] = $this->request->post['marketplace']; + + if (!empty($this->request->post['start_selling'])) { + $data['start_selling'] = $this->request->post['start_selling']; + } + + if (!empty($this->request->post['condition']) && !empty($this->request->post['condition_note'])) { + $data['condition'] = $this->request->post['condition']; + $data['condition_note'] = $this->request->post['condition_note']; + } + + $status = $this->model_extension_openbay_amazon_listing->doBulkListing($data); + + if ($status) { + $message = $this->language->get('text_products_sent'); + + if ($delete_search_results) { + $this->model_extension_openbay_amazon_listing->deleteSearchResults($this->request->post['marketplace'], $delete_search_results); + } + } else { + $message = $this->language->get('error_sending_products'); + } + } else { + $message = $this->language->get('error_no_products_selected'); + } + + $json = array( + 'status' => $status, + 'message' => $message, + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function doBulkSearch() { + $this->load->model('catalog/product'); + $this->load->model('extension/openbay/amazon_listing'); + $this->load->language('extension/openbay/amazon_bulk_listing'); + + $json = array(); + $search_data = array(); + + if (!empty($this->request->post['product_ids'])) { + foreach ($this->request->post['product_ids'] as $product_id) { + $product = $this->model_catalog_product->getProduct($product_id); + + if (empty($product['sku'])) { + $json[$product_id] = array( + 'error' => $this->language->get('error_product_sku') + ); + } + + $key = ''; + + $id_types = array('isbn', 'upc', 'ean', 'jan', 'sku'); + + foreach ($id_types as $id_type) { + if (!empty($product[$id_type])) { + $key = $id_type; + break; + } + } + + if (!$key) { + $json[$product_id] = array( + 'error' => $this->language->get('error_searchable_fields') + ); + } + + if (!isset($json[$product_id])) { + $search_data[$key][] = array( + 'product_id' => $product['product_id'], + 'value' => trim($product[$id_type]), + 'marketplace' => $this->request->post['marketplace'], + ); + + $json[$product_id] = array( + 'success' => $this->language->get('text_searching') + ); + } + } + } + + if ($search_data) { + $this->model_extension_openbay_amazon_listing->doBulkSearch($search_data); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function bulkListProducts() { + $this->load->language('extension/openbay/amazon_bulk_listing'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/bulkListProducts', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $ping_info = simplexml_load_string($this->openbay->amazon->call('ping/info')); + + $bulk_listing_status = false; + + if ($ping_info) { + $bulk_listing_status = ((string)$ping_info->BulkListing == 'true') ? true : false; + } + + if (!empty($this->request->get['filter_marketplace'])) { + $filter_marketplace = $this->request->get['filter_marketplace']; + } else { + $filter_marketplace = $this->config->get('openbay_amazon_default_listing_marketplace'); + } + + $data['filter_marketplace'] = $filter_marketplace; + + $data['bulk_listing_status'] = $bulk_listing_status; + + $data['link_overview'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + if ($bulk_listing_status) { + $data['link_search'] = $this->url->link('extension/openbay/amazon/doBulkSearch', 'user_token=' . $this->session->data['user_token'], true); + + $data['default_condition'] = $this->config->get('openbay_amazon_listing_default_condition'); + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['marketplaces'] = array( + array('name' => $this->language->get('text_de'), 'code' => 'de'), + array('name' => $this->language->get('text_fr'), 'code' => 'fr'), + array('name' => $this->language->get('text_it'), 'code' => 'it'), + array('name' => $this->language->get('text_es'), 'code' => 'es'), + array('name' => $this->language->get('text_uk'), 'code' => 'uk'), + ); + + if (!empty($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $filter = array(); + + $filter['filter_marketplace'] = $filter_marketplace; + $filter['start'] = ($page - 1) * $this->config->get('config_limit_admin'); + $filter['limit'] = $this->config->get('config_limit_admin'); + + $results = $this->model_extension_openbay_amazon->getProductSearch($filter); + $product_total = $this->model_extension_openbay_amazon->getProductSearchTotal($filter); + + $data['products'] = array(); + + foreach ($results as $result) { + $product = $this->model_catalog_product->getProduct($result['product_id']); + + if ($product['image'] && file_exists(DIR_IMAGE . $product['image'])) { + $image = $this->model_tool_image->resize($product['image'], 40, 40); + } else { + $image = $this->model_tool_image->resize('no_image.png', 40, 40); + } + + if ($result['status'] == 'searching') { + $search_status = $this->language->get('text_searching'); + } else if ($result['status'] == 'finished') { + $search_status = $this->language->get('text_finished'); + } else { + $search_status = '-'; + } + + $href = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true); + + $search_results = array(); + + if ($result['data']) { + foreach ($result['data'] as $search_result) { + $link = $this->model_extension_openbay_amazon->getAsinLink($search_result['asin'], $result['marketplace']); + + $search_results[] = array( + 'title' => $search_result['title'], + 'asin' => $search_result['asin'], + 'href' => $link, + ); + } + } + + $data['products'][] = array( + 'product_id' => $product['product_id'], + 'href' => $href, + 'name' => $product['name'], + 'model' => $product['model'], + 'image' => $image, + 'matches' => $result['matches'], + 'search_status' => $search_status, + 'search_results' => $search_results, + ); + } + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/amazon/bulkListProducts', 'user_token=' . $this->session->data['user_token'] . '&page={page}&filter_marketplace=' . $filter_marketplace, true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_bulk_listing', $data)); + } + + public function bulkLinking() { + $this->load->language('extension/openbay/amazon_bulk_linking'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazon'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $ping_info = simplexml_load_string($this->openbay->amazon->call('ping/info')); + + $bulk_linking_status = false; + if ($ping_info) { + $bulk_linking_status = ((string)$ping_info->BulkLinking == 'true') ? true : false; + } + + $data['bulk_linking_status'] = $bulk_linking_status; + + if (!isset($this->request->get['marketplace'])) { + $marketplace_code = 'uk'; + } else { + $marketplace_code = $this->request->get['marketplace']; + } + + $total_linked = $this->model_extension_openbay_amazon->getTotalUnlinkedItemsFromReport($marketplace_code); + + if (isset($this->request->get['linked_item_page'])) { + $linked_item_page = (int)$this->request->get['linked_item_page']; + } else { + $linked_item_page = 1; + } + + if (isset($this->request->get['linked_item_limit'])){ + $linked_item_limit = (int)$this->request->get['linked_item_limit']; + } else { + $linked_item_limit = 25; + } + + $data['cancel_report_link'] = ''; + + if (isset($this->request->get['cancel_report']) && $this->request->get['cancel_report'] == 1) { + $this->load->model('setting/setting'); + + $settings = $this->model_setting_setting->getSetting('openbay_amazon'); + $settings['openbay_amazon_processing_listing_reports'] = ''; + + $this->model_setting_setting->editSetting('openbay_amazon', $settings); + + $this->response->redirect($this->url->link('extension/openbay/amazon/bulklinking', 'marketplace=' . $marketplace_code . '&user_token=' . $this->session->data['user_token'], true)); + } else { + $data['cancel_report_link'] = $this->url->link('extension/openbay/amazon/bulklinking', 'cancel_report=1&marketplace=uk&user_token=' . $this->session->data['user_token'], true); + } + + $marketplaces = array( + 'uk' => array( + 'name' => $this->language->get('text_uk'), + 'code' => 'uk', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=uk', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=uk', true), + ), + 'de' => array( + 'name' => $this->language->get('text_de'), + 'code' => 'de', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=de', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=de', true), + ), + 'fr' => array( + 'name' => $this->language->get('text_fr'), + 'code' => 'fr', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=fr', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=fr', true), + ), + 'it' => array( + 'name' => $this->language->get('text_it'), + 'code' => 'it', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=it', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=it', true), + ), + 'es' => array( + 'name' => $this->language->get('text_es'), + 'code' => 'es', + 'href_load_listings' => $this->url->link('extension/openbay/amazon/loadListingReport', 'user_token=' . $this->session->data['user_token'] . '&marketplace=es', true), + 'link' => $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&marketplace=es', true), + ), + ); + + $pagination = new Pagination(); + $pagination->total = $total_linked; + $pagination->page = $linked_item_page; + $pagination->limit = $linked_item_limit; + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/amazon/bulklinking', 'user_token=' . $this->session->data['user_token'] . '&linked_item_page={page}&marketplace=' . $marketplace_code, true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($total_linked) ? (($linked_item_page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($linked_item_page - 1) * $this->config->get('config_limit_admin')) > ($total_linked - $this->config->get('config_limit_admin'))) ? $total_linked : ((($linked_item_page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $total_linked, ceil($total_linked / $this->config->get('config_limit_admin'))); + + $results = $this->model_extension_openbay_amazon->getUnlinkedItemsFromReport($marketplace_code, $linked_item_limit, $linked_item_page); + + $products = array(); + + foreach ($results as $result) { + $products[] = array( + 'asin' => $result['asin'], + 'href_amazon' => $this->model_extension_openbay_amazon->getAsinLink($result['asin'], $marketplace_code), + 'amazon_sku' => $result['amazon_sku'], + 'amazon_quantity' => $result['amazon_quantity'], + 'amazon_price' => $result['amazon_price'], + 'name' => $result['name'], + 'sku' => $result['sku'], + 'quantity' => $result['quantity'], + 'combination' => $result['combination'], + 'product_id' => $result['product_id'], + 'var' => $result['var'], + 'href_product' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'], true), + ); + } + + $data['unlinked_products'] = $products; + $data['marketplaces'] = $marketplaces; + $data['marketplace_code'] = $marketplace_code; + + $data['marketplaces_processing'] = array(); + if (is_array($this->config->get('openbay_amazon_processing_listing_reports'))) { + $data['marketplaces_processing'] = $this->config->get('openbay_amazon_processing_listing_reports'); + } + + $data['cancel'] = $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_bulk_linking', $data)); + } + + public function loadListingReport() { + $this->load->model('extension/openbay/amazon'); + $this->load->model('setting/setting'); + $this->load->language('extension/openbay/amazon_bulk_linking'); + + $marketplace = $this->request->get['marketplace']; + + $this->model_extension_openbay_amazon->deleteListingReports($marketplace); + + $request_data = array( + 'marketplace' => $marketplace, + 'response_url' => HTTPS_CATALOG . 'index.php?route=extension/openbay/amazon/listingreport', + ); + + $response = $this->openbay->amazon->call('report/listing', $request_data); + $response = json_decode($response, 1); + + $json = array(); + $json['status'] = $response['status']; + + if ($json['status']) { + $json['message'] = $this->language->get('text_report_requested'); + + $settings = $this->model_setting_setting->getSetting('openbay_amazon'); + $settings['openbay_amazon_processing_listing_reports'][] = $marketplace; + + $this->model_setting_setting->editSetting('openbay_amazon', $settings); + } else { + $json['message'] = $this->language->get('text_report_request_failed'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function doBulkLinking() { + $this->load->model('extension/openbay/amazon'); + + $links = array(); + $skus = array(); + + if (!empty($this->request->post['link'])) { + foreach ($this->request->post['link'] as $link) { + if (!empty($link['product_id'])) { + $links[] = $link; + $skus[] = $link['amazon_sku']; + } + } + } + + if (!empty($links)) { + foreach ($links as $link) { + $this->model_extension_openbay_amazon->linkProduct($link['amazon_sku'], $link['product_id'], $link['sku']); + } + + $this->model_extension_openbay_amazon->updateAmazonSkusQuantities($skus); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('ok'))); + } + + public function doFullStockSync() { + /** + * This is used if you ever need to force a complete update of your stock levels to Amazon. + * It will get ALL products in your store then lookup any linked ones before sending to the API. + * + * This call can put serious load on your server if you have a lot of products. + * It will make a lot of database queries so ensure your php memory limit is set high enough. + */ + set_time_limit(0); + + $product_array = $this->db->query("SELECT `product_id` FROM `" . DB_PREFIX . "product`")->rows; + + $bulk_array = array(); + + foreach ($product_array as $product) { + $bulk_array[] = $product['product_id']; + } + + $this->openbay->amazon->putStockUpdateBulk($bulk_array); + } +} diff --git a/public/admin/controller/extension/openbay/amazon_listing.php b/public/admin/controller/extension/openbay/amazon_listing.php new file mode 100644 index 0000000..99f7884 --- /dev/null +++ b/public/admin/controller/extension/openbay/amazon_listing.php @@ -0,0 +1,607 @@ +<?php +class ControllerExtensionOpenbayAmazonListing extends Controller { + public function create() { + $this->load->language('extension/openbay/amazon_listing'); + $this->load->model('extension/openbay/amazon_listing'); + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + $this->load->model('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if ($this->request->post) { + $result = $this->model_extension_openbay_amazon_listing->simpleListing($this->request->post); + + if ($result['status'] === 1) { + $this->session->data['success'] = $this->language->get('text_product_sent'); + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } else { + $this->session->data['error'] = sprintf($this->language->get('text_product_not_sent'), $result['message']); + $this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->post['product_id'] . $url, true)); + } + } + + if (isset($this->request->get['product_id'])) { + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + if (empty($product_info)) { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $listing_status = $this->model_extension_openbay_amazon->getProductStatus($this->request->get['product_id']); + + if ($listing_status === 'processing' || $listing_status === 'ok') { + $this->response->redirect($this->url->link('extension/openbay/amazon_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true)); + } else if ($listing_status === 'error_advanced' || $listing_status === 'saved' || $listing_status === 'error_few') { + $this->response->redirect($this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true)); + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $data['url_return'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['url_search'] = $this->url->link('extension/openbay/amazon_listing/search', 'user_token=' . $this->session->data['user_token'], true); + $data['url_advanced'] = $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true); + + $data['button_search'] = $this->language->get('button_search'); + $data['button_new'] = $this->language->get('button_new'); + $data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_amazon_price'] = $this->language->get('button_amazon_price'); + $data['button_list'] = $this->language->get('button_list'); + $data['heading_title'] = $this->language->get('heading_title'); + $data['text_not_in_catalog'] = $this->language->get('text_not_in_catalog'); + $data['text_no_results'] = $this->language->get('text_no_results'); + $data['button_view_on_amazon'] = $this->language->get('button_view_on_amazon'); + $data['text_list'] = $this->language->get('text_list'); + $data['text_placeholder_search'] = $this->language->get('text_placeholder_search'); + $data['text_placeholder_condition'] = $this->language->get('text_placeholder_condition'); + $data['column_image'] = $this->language->get('column_image'); + $data['column_asin'] = $this->language->get('column_asin'); + $data['column_name'] = $this->language->get('column_name'); + $data['column_price'] = $this->language->get('column_price'); + $data['column_action'] = $this->language->get('column_action'); + $data['entry_sku'] = $this->language->get('entry_sku'); + $data['entry_condition'] = $this->language->get('entry_condition'); + $data['entry_condition_note'] = $this->language->get('entry_condition_note'); + $data['entry_price'] = $this->language->get('entry_price'); + $data['entry_sale_price'] = $this->language->get('entry_sale_price'); + $data['entry_sale_date'] = $this->language->get('entry_sale_date'); + $data['entry_quantity'] = $this->language->get('entry_quantity'); + $data['entry_start_selling'] = $this->language->get('entry_start_selling'); + $data['entry_restock_date'] = $this->language->get('entry_restock_date'); + $data['entry_from'] = $this->language->get('entry_from'); + $data['entry_to'] = $this->language->get('entry_to'); + $data['help_restock_date'] = $this->language->get('help_restock_date'); + $data['help_sku'] = $this->language->get('help_sku'); + $data['help_sale_price'] = $this->language->get('help_sale_price'); + $data['tab_required'] = $this->language->get('tab_required'); + $data['tab_additional'] = $this->language->get('tab_additional'); + $data['error_price'] = $this->language->get('error_price'); + $data['error_sku'] = $this->language->get('error_sku'); + $data['error_stock'] = $this->language->get('error_stock'); + + $data['form_action'] = $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'], true); + + $data['sku'] = trim($product_info['sku']); + + if ($this->config->get('openbay_amazon_listing_tax_added')) { + $data['price'] = $product_info['price'] * (1 + $this->config->get('openbay_amazon_listing_tax_added') / 100); + } else { + $data['price'] = $product_info['price']; + } + + $data['listing_errors'] = array(); + + if ($listing_status == 'error_quick') { + $data['listing_errors'] = $this->model_extension_openbay_amazon->getProductErrors($product_info['product_id'], 3); + } + + $data['price'] = number_format($data['price'], 2, '.', ''); + $data['quantity'] = $product_info['quantity']; + $data['product_id'] = $product_info['product_id']; + + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['marketplaces'] = array( + 'uk' => $this->language->get('text_united_kingdom'), + 'de' => $this->language->get('text_germany'), + 'fr' => $this->language->get('text_france'), + 'it' => $this->language->get('text_italy'), + 'es' => $this->language->get('text_spain'), + ); + + $data['default_marketplace'] = $this->config->get('openbay_amazon_default_listing_marketplace'); + $data['default_condition'] = $this->config->get('openbay_amazon_listing_default_condition'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_listing', $data)); + } + + public function edit() { + $this->load->model('extension/openbay/amazon_listing'); + $this->load->model('extension/openbay/amazon'); + $this->load->language('extension/openbay/amazon_listing'); + + $this->document->setTitle($this->language->get('text_edit_heading')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true), + 'text' => $this->language->get('text_edit_heading'), + ); + + $status = $this->model_extension_openbay_amazon->getProductStatus($product_id); + + if ($status === false) { + $this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + return; + } + + $data['product_links'] = $this->model_extension_openbay_amazon->getProductLinks($product_id); + $data['url_return'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + + if ($status == 'ok' || $status == 'linked') { + $data['url_create_new'] = $this->url->link('extension/openbay/amazon_listing/createNew', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + $data['url_delete_links'] = $this->url->link('extension/openbay/amazon_listing/deleteLinks', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + } + + if ($status == 'saved') { + $data['has_saved_listings'] = true; + } else { + $data['has_saved_listings'] = false; + } + + $data['url_saved_listings'] = $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id, true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['text_edit_heading'] = $this->language->get('text_edit_heading'); + $data['text_product_links'] = $this->language->get('text_product_links'); + $data['text_has_saved_listings'] = $this->language->get('text_has_saved_listings'); + $data['button_create_new_listing'] = $this->language->get('button_create_new_listing'); + $data['button_remove_links'] = $this->language->get('button_remove_links'); + $data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_saved_listings'] = $this->language->get('button_saved_listings'); + $data['column_name'] = $this->language->get('column_name'); + $data['column_model'] = $this->language->get('column_model'); + $data['column_combination'] = $this->language->get('column_combination'); + $data['column_sku'] = $this->language->get('column_sku'); + $data['column_amazon_sku'] = $this->language->get('column_amazon_sku'); + $data['column_sku_variant'] = $this->language->get('column_sku_variant'); + $data['text_no_results'] = $this->language->get('text_no_results'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_listing_edit', $data)); + } + + public function createNew() { + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + $this->load->model('extension/openbay/amazon'); + $this->model_extension_openbay_amazon->deleteProduct($product_id); + $this->response->redirect($this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + + public function deleteLinks() { + $this->load->language('extension/openbay/amazon_listing'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + $this->load->model('extension/openbay/amazon'); + + $links = $this->model_extension_openbay_amazon->getProductLinks($product_id); + foreach ($links as $link) { + $this->model_extension_openbay_amazon->removeProductLink($link['amazon_sku']); + } + $this->model_extension_openbay_amazon->deleteProduct($product_id); + $this->session->data['success'] = $this->language->get('text_links_removed'); + + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + public function search() { + $this->load->model('extension/openbay/amazon_listing'); + $this->load->language('extension/openbay/amazon_listing'); + + $error = ''; + + if (empty($this->request->post['search_string'])) { + $error = $this->language->get('error_text_missing'); + } + + if (empty($this->request->post['marketplace'])) { + $error = $this->language->get('error_marketplace_missing'); + } + + if ($error) { + $json = array( + 'data' => '', + 'error' => $error, + ); + } else { + $json = array( + 'data' => $this->model_extension_openbay_amazon_listing->search($this->request->post['search_string'], $this->request->post['marketplace']), + 'error' => '', + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function bestPrice() { + $this->load->model('extension/openbay/amazon_listing'); + $this->load->language('extension/openbay/amazon_listing'); + + $error = ''; + + if (empty($this->request->post['asin'])) { + $error = $this->language->get('error_missing_asin'); + } + + if (empty($this->request->post['marketplace'])) { + $error = $this->language->get('error_marketplace_missing'); + } + + if (empty($this->request->post['condition'])) { + $error = $this->language->get('error_condition_missing'); + } + + if ($error) { + $json = array( + 'data' => '', + 'error' => $error, + ); + } else { + $best_price = $this->model_extension_openbay_amazon_listing->getBestPrice($this->request->post['asin'], $this->request->post['condition'], $this->request->post['marketplace']); + + if ($best_price) { + $json = array( + 'data' => $best_price, + 'error' => '', + ); + } else { + $json = array( + 'data' => '', + 'error' => $this->language->get('error_amazon_price'), + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getProductByAsin() { + $this->load->model('extension/openbay/amazon_listing'); + + $data = $this->model_extension_openbay_amazon_listing->getProductByAsin($this->request->post['asin'], $this->request->post['market']); + + $json = array( + 'title' => (string)$data['ItemAttributes']['Title'], + 'img' => (!isset($data['ItemAttributes']['SmallImage']['URL']) ? '' : $data['ItemAttributes']['SmallImage']['URL']) + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getBrowseNodes() { + $this->load->model('extension/openbay/amazon_listing'); + + $data = array( + 'marketplaceId' => $this->request->post['marketplaceId'], + 'node' => (isset($this->request->post['node']) ? $this->request->post['node'] : ''), + ); + + $response = $this->model_extension_openbay_amazon_listing->getBrowseNodes($data); + + $this->response->setOutput($response); + } +} diff --git a/public/admin/controller/extension/openbay/amazon_product.php b/public/admin/controller/extension/openbay/amazon_product.php new file mode 100644 index 0000000..8c3ba1a --- /dev/null +++ b/public/admin/controller/extension/openbay/amazon_product.php @@ -0,0 +1,585 @@ +<?php +class ControllerExtensionOpenbayAmazonProduct extends Controller { + public function index() { + $this->load->language('catalog/product'); + $this->load->language('extension/openbay/amazon_listing'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazon'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $this->document->addScript('view/javascript/openbay/js/openbay.js'); + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon_listing/create', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_title_advanced'), + ); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + die('No product id'); + } + + if (isset($this->request->get['sku'])) { + $variation = $this->request->get['sku']; + } else { + $variation = ''; + } + $data['variation'] = $variation; + $data['errors'] = array(); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $data_array = $this->request->post; + + $this->model_extension_openbay_amazon->saveProduct($product_id, $data_array); + + if ($data_array['upload_after'] === 'true') { + $upload_result = $this->uploadItems(); + if ($upload_result['status'] == 'ok') { + $this->session->data['success'] = $this->language->get('text_uploaded'); + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } else { + $data['errors'][] = Array('message' => $upload_result['error_message']); + } + } else { + $this->session->data['success'] = $this->language->get('text_saved_local'); + $this->response->redirect($this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $saved_listing_data = $this->model_extension_openbay_amazon->getProduct($product_id, $variation); + if (empty($saved_listing_data)) { + $listing_saved = false; + } else { + $listing_saved = true; + } + + $errors = $this->model_extension_openbay_amazon->getProductErrors($product_id); + foreach($errors as $error) { + $error['message'] = 'Error for SKU: "' . $error['sku'] . '" - ' . $this->formatUrlsInText($error['message']); + $data['errors'][] = $error; + } + if (!empty($errors)) { + $data['has_listing_errors'] = true; + } else { + $data['has_listing_errors'] = false; + } + + $product_info = $this->model_catalog_product->getProduct($product_id); + $data['listing_name'] = $product_info['name'] . " : " . $product_info['model']; + $data['listing_sku'] = $product_info['sku']; + $data['listing_url'] = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + + if ($listing_saved) { + $data['edit_product_category'] = $saved_listing_data['category']; + } else { + $data['edit_product_category'] = ''; + } + + $data['amazon_categories'] = array(); + + $amazon_templates = $this->openbay->amazon->getCategoryTemplates(); + + foreach($amazon_templates as $template) { + $template = (array)$template; + $category_data = array( + 'friendly_name' => $template['friendly_name'], + 'name' => $template['name'], + 'template' => $template['xml'] + ); + $data['amazon_categories'][] = $category_data; + } + + if ($listing_saved) { + $data['template_parser_url'] = html_entity_decode($this->url->link('extension/openbay/amazon_product/parseTemplateAjax&edit_id=' . $product_id, 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['template_parser_url'] = html_entity_decode($this->url->link('extension/openbay/amazon_product/parseTemplateAjax&product_id=' . $product_id, 'user_token=' . $this->session->data['user_token'], true)); + } + + $data['url_remove_errors'] = $this->url->link('extension/openbay/amazon_product/removeErrors', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + $data['cancel_url'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['saved_listings_url'] = $this->url->link('extension/openbay/amazon/savedListings', 'user_token=' . $this->session->data['user_token'], true); + $data['main_url'] = $this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['user_token'] = $this->session->data['user_token']; + $data['no_image'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if ($this->openbay->addonLoad('openstock')) { + $this->load->model('extension/module/openstock'); + $data['options'] = $this->model_setting_module_openstock->getVariants($product_id); + } else { + $data['options'] = array(); + } + + $data['marketplaces'] = array( + array('name' => $this->language->get('text_germany'), 'id' => 'A1PA6795UKMFR9', 'code' => 'de'), + array('name' => $this->language->get('text_france'), 'id' => 'A13V1IB3VIYZZH', 'code' => 'fr'), + array('name' => $this->language->get('text_italy'), 'id' => 'APJ6JRA9NG5V4', 'code' => 'it'), + array('name' => $this->language->get('text_spain'), 'id' => 'A1RKKUPIHCS9HS', 'code' => 'es'), + array('name' => $this->language->get('text_united_kingdom'), 'id' => 'A1F83G8C2ARO7P', 'code' => 'uk'), + ); + + $marketplace_mapping = array( + 'uk' => 'A1F83G8C2ARO7P', + 'de' => 'A1PA6795UKMFR9', + 'fr' => 'A13V1IB3VIYZZH', + 'it' => 'APJ6JRA9NG5V4', + 'es' => 'A1RKKUPIHCS9HS', + ); + + if ($this->config->get('openbay_amazon_default_listing_marketplace')) { + $data['default_marketplaces'] = array($marketplace_mapping[$this->config->get('openbay_amazon_default_listing_marketplace')]); + } else { + $data['default_marketplaces'] = array(); + } + + $data['saved_marketplaces'] = isset($saved_listing_data['marketplaces']) ? (array)unserialize($saved_listing_data['marketplaces']) : false; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazon_listing_advanced', $data)); + } + + public function removeErrors() { + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + $this->load->model('extension/openbay/amazon'); + $this->model_extension_openbay_amazon->removeAdvancedErrors($product_id); + $this->session->data['success'] = 'Errors removed'; + $this->response->redirect($this->url->link('extension/openbay/amazon_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + + public function deleteSaved() { + if (!isset($this->request->get['product_id']) || !isset($this->request->get['var'])) { + return; + } + + $this->load->model('extension/openbay/amazon'); + $this->model_extension_openbay_amazon->deleteSaved($this->request->get['product_id'], $this->request->get['var']); + } + + public function uploadSaved() { + ob_start(); + $json = json_encode($this->uploadItems()); + ob_clean(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + private function uploadItems() { + $this->load->language('extension/openbay/amazon_listing'); + $this->load->model('extension/openbay/amazon'); + $logger = new Log('amazon_product.log'); + + $logger->write('Uploading process started . '); + + $saved_products = $this->model_extension_openbay_amazon->getSavedProductsData(); + + if (empty($saved_products)) { + $logger->write('No saved listings found. Uploading canceled . '); + $result['status'] = 'error'; + $result['error_message'] = 'No saved listings. Nothing to upload. Aborting . '; + return $result; + } + + foreach($saved_products as $saved_product) { + $product_data_decoded = (array)json_decode($saved_product['data']); + + $catalog = defined(HTTPS_CATALOG) ? HTTPS_CATALOG : HTTP_CATALOG; + $response_data = array("response_url" => $catalog . 'index.php?route=extension/openbay/amazon/product'); + $category_data = array('category' => (string)$saved_product['category']); + $fields_data = array('fields' => (array)$product_data_decoded['fields']); + + $mp_array = !empty($saved_product['marketplaces']) ? (array)unserialize($saved_product['marketplaces']) : array(); + $marketplaces_data = array('marketplaces' => $mp_array); + + $product_data = array_merge($category_data, $fields_data, $response_data, $marketplaces_data); + $insertion_response = $this->openbay->amazon->insertProduct($product_data); + + $logger->write("Uploading product with data:" . print_r($product_data, true) . " + Got response:" . print_r($insertion_response, true)); + + if (!isset($insertion_response['status']) || $insertion_response['status'] == 'error') { + $details = isset($insertion_response['info']) ? $insertion_response['info'] : 'Unknown'; + $result['error_message'] = sprintf($this->language->get('error_upload_failed'), $saved_product['product_sku'], $details); + $result['status'] = 'error'; + break; + } + $logger->write('Product upload success'); + $this->model_extension_openbay_amazon->setProductUploaded($saved_product['product_id'], $insertion_response['insertion_id'], $saved_product['var']); + } + + if (!isset($result['status'])) { + $result['status'] = 'ok'; + $logger->write('Uploading process completed successfully . '); + } else { + $logger->write('Uploading process failed with message: ' . $result['error_message']); + } + return $result; + } + + public function parseTemplateAjax() { + $this->load->model('tool/image'); + + $log = new Log('amazon_product.log'); + + $json = array(); + + if (isset($this->request->get['xml'])) { + $request = array('template' => $this->request->get['xml'], 'version' => 2); + $response = $this->openbay->amazon->call("productv2/GetTemplateXml", $request); + if ($response) { + $template = $this->openbay->amazon->parseCategoryTemplate($response); + if ($template) { + $variation = isset($this->request->get['sku']) ? $this->request->get['sku'] : ''; + + if (isset($this->request->get['product_id'])) { + $template['fields'] = $this->fillDefaultValues($this->request->get['product_id'], $template['fields'], $variation); + } elseif (isset($this->request->get['edit_id'])) { + $template['fields'] = $this->fillSavedValues($this->request->get['edit_id'], $template['fields'], $variation); + } + + foreach($template['fields'] as $key => $field) { + if ($field['accepted']['type'] == 'image') { + if (empty($field['value'])) { + $template['fields'][$key]['thumb'] = ''; + } else { + $template['fields'][$key]['thumb'] = $this->model_tool_image->resize(str_replace(HTTPS_CATALOG . 'image/', '', $field['value']), 100, 100); + } + } + } + + $result = array( + "category" => $template['category'], + "fields" => $template['fields'], + "tabs" => $template['tabs'] + ); + } else { + $json_decoded = json_decode($response); + if ($json_decoded) { + $result = $json_decoded; + } else { + $result = array('status' => 'error'); + $log->write("admin/openbay/amazon_product/parseTemplateAjax failed to parse template response: " . $response); + } + } + } else { + $log->write("admin/openbay/amazon_product/parseTemplateAjax failed calling productv2/GetTemplateXml with params: " . print_r($request, true)); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($result)); + } + + private function fillDefaultValues($product_id, $fields_array, $var = '') { + $this->load->model('catalog/product'); + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/amazon'); + + $openbay_settings = $this->model_setting_setting->getSetting('openbay_amazon'); + + $product_info = $this->model_catalog_product->getProduct($product_id); + $product_info['description'] = trim(utf8_encode(strip_tags(html_entity_decode($product_info['description']), "<br>"))); + $product_info['image'] = HTTPS_CATALOG . 'image/' . $product_info['image']; + + $tax_added = isset($openbay_settings['openbay_amazon_listing_tax_added']) ? $openbay_settings['openbay_amazon_listing_tax_added'] : 0; + $default_condition = isset($openbay_settings['openbay_amazon_listing_default_condition']) ? $openbay_settings['openbay_amazon_listing_default_condition'] : ''; + $product_info['price'] = number_format($product_info['price'] + $tax_added / 100 * $product_info['price'], 2, '.', ''); + + $defaults = array( + 'sku' => $product_info['sku'], + 'title' => $product_info['name'], + 'quantity' => $product_info['quantity'], + 'standardprice' => $product_info['price'], + 'description' => $product_info['description'], + 'mainimage' => $product_info['image'], + 'currency' => $this->config->get('config_currency'), + 'shippingweight' => number_format($product_info['weight'], 2, '.', ''), + 'conditiontype' => $default_condition, + ); + + $this->load->model('localisation/weight_class'); + $weight_class = $this->model_localisation_weight_class->getWeightClass($product_info['weight_class_id']); + if (!empty($weight_class)) { + $defaults['shippingweightunitofmeasure'] = $weight_class['unit']; + } + + $this->load->model('catalog/manufacturer'); + $manufacturer = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']); + if (!empty($manufacturer)) { + $defaults['manufacturer'] = $manufacturer['name']; + $defaults['brand'] = $manufacturer['name']; + } + + $product_images = $this->model_catalog_product->getProductImages($product_id); + $image_index = 1; + foreach($product_images as $product_image) { + $defaults['pt' . $image_index] = HTTPS_CATALOG . 'image/' . $product_image['image']; + $image_index ++; + } + + if (!empty($product_info['upc'])) { + $defaults['type'] = 'UPC'; + $defaults['value'] = $product_info['upc']; + } else if (!empty($product_info['ean'])) { + $defaults['type'] = 'EAN'; + $defaults['value'] = $product_info['ean']; + } + + $meta_keywords = explode(',', $product_info['meta_keyword']); + foreach ($meta_keywords as $index => $meta_keyword) { + $defaults['searchterms' . $index] = trim($meta_keyword); + } + + if ($var !== '' && $this->openbay->addonLoad('openstock')) { + $this->load->model('tool/image'); + $this->load->model('extension/module/openstock'); + $option_stocks = $this->model_setting_module_openstock->getVariants($product_id); + + $option = ''; + + foreach ($option_stocks as $option_iterator) { + if ($option_iterator['sku'] === $var) { + $option = $option_iterator; + break; + } + } + + if ($option != '') { + $defaults['sku'] = $option['sku']; + $defaults['quantity'] = $option['stock']; + $defaults['standardprice'] = number_format($option['price'] + $tax_added / 100 * $option['price'], 2, '.', ''); + $defaults['shippingweight'] = number_format($option['weight'], 2, '.', ''); + + if (!empty($option['image'])) { + $defaults['mainimage'] = HTTPS_CATALOG . 'image/' . $option['image']; + } + } + } + + if ($defaults['shippingweight'] <= 0) { + unset($defaults['shippingweight']); + unset($defaults['shippingweightunitofmeasure']); + } + + $filled_array = array(); + + foreach($fields_array as $field) { + + $value_array = array('value' => ''); + + if (isset($defaults[strtolower($field['name'])])) { + $value_array = array('value' => $defaults[strtolower($field['name'])]); + } + + $filled_item = array_merge($field, $value_array); + + $filled_array[] = $filled_item; + } + return $filled_array; + } + + private function fillSavedValues($product_id, $fields_array, $var = '') { + + $this->load->model('extension/openbay/amazon'); + $saved_listing = $this->model_extension_openbay_amazon->getProduct($product_id, $var); + + $decoded_data = (array)json_decode($saved_listing['data']); + $saved_fields = (array)$decoded_data['fields']; + + //Show current quantity instead of last uploaded + $saved_fields['Quantity'] = $this->model_extension_openbay_amazon->getProductQuantity($product_id, $var); + + $filled_array = array(); + + foreach($fields_array as $field) { + $value_array = array('value' => ''); + + if (isset($saved_fields[$field['name']])) { + $value_array = array('value' => $saved_fields[$field['name']]); + } + + $filled_item = array_merge($field, $value_array); + + $filled_array[] = $filled_item; + } + + return $filled_array; + } + + public function resetPending() { + $this->db->query("UPDATE `" . DB_PREFIX . "amazon_product` SET `status` = 'saved' WHERE `status` = 'uploaded'"); + } + + private function validateForm() { + return true; + } + + private function formatUrlsInText($text) { + $regex_url = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; + preg_match_all($regex_url, $text, $matches); + $used_patterns = array(); + foreach($matches[0] as $pattern) { + if (!array_key_exists($pattern, $used_patterns)) { + $used_patterns[$pattern]=true; + $text = str_replace($pattern, "<a target='_blank' href=" . $pattern . ">" . $pattern . "</a>", $text); + } + } + return $text; + } +} diff --git a/public/admin/controller/extension/openbay/amazonus.php b/public/admin/controller/extension/openbay/amazonus.php new file mode 100644 index 0000000..a6d79b3 --- /dev/null +++ b/public/admin/controller/extension/openbay/amazonus.php @@ -0,0 +1,1040 @@ +<?php +class ControllerExtensionOpenbayAmazonus extends Controller { + public function install() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/amazonus_listing'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/amazonus_listing'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/amazonus_product'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/amazonus_product'); + + $this->model_extension_openbay_amazonus->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_amazonus->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->language('extension/openbay/amazonus'); + + $data = $this->language->all(); + + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/amazonus'); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['validation'] = $this->openbay->amazonus->validate(); + $data['link_settings'] = $this->url->link('extension/openbay/amazonus/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_subscription'] = $this->url->link('extension/openbay/amazonus/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['link_item_link'] = $this->url->link('extension/openbay/amazonus/itemLinks', 'user_token=' . $this->session->data['user_token'], true); + $data['link_stock_updates'] = $this->url->link('extension/openbay/amazonus/stockUpdates', 'user_token=' . $this->session->data['user_token'], true); + $data['link_saved_listings'] = $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_bulk_listing'] = $this->url->link('extension/openbay/amazonus/bulkListProducts', 'user_token=' . $this->session->data['user_token'], true); + $data['link_bulk_linking'] = $this->url->link('extension/openbay/amazonus/bulkLinking', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/amazonus/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=amazonus'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus', $data)); + } + + public function stockUpdates() { + $this->load->language('extension/openbay/amazonus_stockupdates'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/stockUpdates', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['link_overview'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $request_args = array(); + + if (isset($this->request->get['filter_date_start'])) { + $request_args['date_start'] = date("Y-m-d", strtotime($this->request->get['filter_date_start'])); + } else { + $request_args['date_start'] = date("Y-m-d"); + } + + if (isset($this->request->get['filter_date_end'])) { + $request_args['date_end'] = date("Y-m-d", strtotime($this->request->get['filter_date_end'])); + } else { + $request_args['date_end'] = date("Y-m-d"); + } + + $data['date_start'] = $request_args['date_start']; + $data['date_end'] = $request_args['date_end']; + + $xml = $this->openbay->amazonus->getStockUpdatesStatus($request_args); + $simple_xml_obj = simplexml_load_string($xml); + $data['table_data'] = array(); + + if ($simple_xml_obj !== false) { + $table_data = array(); + + foreach($simple_xml_obj->update as $update_node) { + $row = array( + 'date_requested' => (string)$update_node->date_requested, + 'date_updated' => (string)$update_node->date_updated, + 'status' => (string)$update_node->status, + ); + + $data_items = array(); + + foreach($update_node->data->product as $product_node) { + $data_items[] = array( + 'sku' => (string)$product_node->sku, + 'stock' => (int)$product_node->stock + ); + } + + $row['data'] = $data_items; + $table_data[(int)$update_node->ref] = $row; + } + + $data['table_data'] = $table_data; + } else { + $data['error'] = $data['error_api_connection']; + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_stock_updates', $data)); + } + + public function subscription() { + $this->load->language('extension/openbay/amazonus_subscription'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/subscription', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['link_overview'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $response = simplexml_load_string($this->openbay->amazonus->call('plans/getPlans')); + + $data['plans'] = array(); + + if ($response) { + foreach ($response->Plan as $plan) { + $data['plans'][] = array( + 'title' => (string)$plan->Title, + 'description' => (string)$plan->Description, + 'order_frequency' => (string)$plan->OrderFrequency, + 'product_listings' => (string)$plan->ProductListings, + 'bulk_listing' => (string)$plan->BulkListing, + 'price' => (string)$plan->Price, + ); + } + } + + $response = simplexml_load_string($this->openbay->amazonus->call('plans/getUsersPlans')); + + $plan = false; + + if ($response) { + $plan = array( + 'merchant_id' => (string)$response->MerchantId, + 'user_status' => (string)$response->UserStatus, + 'title' => (string)$response->Title, + 'description' => (string)$response->Description, + 'price' => (string)$response->Price, + 'order_frequency' => (string)$response->OrderFrequency, + 'product_listings' => (string)$response->ProductListings, + 'listings_remain' => (string)$response->ListingsRemain, + 'listings_reserved' => (string)$response->ListingsReserved, + 'bulk_listing' => (string)$response->BulkListing, + ); + } + + $data['user_plan'] = $plan; + $data['link_change_plan'] = $this->openbay->amazonus->getServer() . 'account/changePlan/?token=' . $this->config->get('openbay_amazonus_token'); + $data['link_change_seller'] = $this->openbay->amazonus->getServer() . 'account/changeSellerId/?token=' . $this->config->get('openbay_amazonus_token'); + $data['link_register'] = 'https://account.openbaypro.com/amazonus/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=subscription&utm_campaign=amazonus'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_subscription', $data)); + } + + public function settings() { + $this->load->language('extension/openbay/amazonus_settings'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/amazonus'); + + $this->load->model('customer/customer_group'); + + $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); + + $settings = $this->model_setting_setting->getSetting('openbay_amazonus'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $settings = array_merge($settings, $this->request->post); + $this->model_setting_setting->editSetting('openbay_amazonus', $settings); + + $this->config->set('openbay_amazonus_token', $this->request->post['openbay_amazonus_token']); + $this->config->set('openbay_amazonus_encryption_key', $this->request->post['openbay_amazonus_encryption_key']); + $this->config->set('openbay_amazonus_encryption_iv', $this->request->post['openbay_amazonus_encryption_iv']); + + $this->openbay->amazonus->setEncryptionKey($this->request->post['openbay_amazonus_encryption_key']); + $this->openbay->amazonus->setEncryptionIv($this->request->post['openbay_amazonus_encryption_iv']); + + if (!empty($this->request->post['openbay_amazonus_token']) && !empty($this->request->post['openbay_amazonus_encryption_key']) && !empty($this->request->post['openbay_amazonus_encryption_iv'])) { + $this->model_extension_openbay_amazonus->verifyConfig($settings); + } + + $this->session->data['success'] = $this->language->get('text_settings_updated'); + $this->response->redirect($this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true)); + return; + } + + $data['cancel'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['openbay_amazonus_status'] = isset($settings['openbay_amazonus_status']) ? $settings['openbay_amazonus_status'] : ''; + $data['openbay_amazonus_token'] = isset($settings['openbay_amazonus_token']) ? $settings['openbay_amazonus_token'] : ''; + $data['openbay_amazonus_encryption_key'] = isset($settings['openbay_amazonus_encryption_key']) ? $settings['openbay_amazonus_encryption_key'] : ''; + $data['openbay_amazonus_encryption_iv'] = isset($settings['openbay_amazonus_encryption_iv']) ? $settings['openbay_amazonus_encryption_iv'] : ''; + $data['openbay_amazonus_listing_tax_added'] = isset($settings['openbay_amazonus_listing_tax_added']) ? $settings['openbay_amazonus_listing_tax_added'] : '0.00'; + $data['openbay_amazonus_order_tax'] = isset($settings['openbay_amazonus_order_tax']) ? $settings['openbay_amazonus_order_tax'] : '00'; + $data['openbay_amazonus_default_listing_marketplace'] = isset($settings['openbay_amazonus_default_listing_marketplace']) ? $settings['openbay_amazonus_default_listing_marketplace'] : ''; + $data['openbay_amazonus_listing_default_condition'] = isset($settings['openbay_amazonus_listing_default_condition']) ? $settings['openbay_amazonus_listing_default_condition'] : ''; + + $data['carriers'] = $this->openbay->amazonus->getCarriers(); + $data['openbay_amazonus_default_carrier'] = isset($settings['openbay_amazonus_default_carrier']) ? $settings['openbay_amazonus_default_carrier'] : ''; + + $unshipped_status_id = isset($settings['openbay_amazonus_order_status_unshipped']) ? $settings['openbay_amazonus_order_status_unshipped'] : ''; + $partially_shipped_status_id = isset($settings['openbay_amazonus_order_status_partially_shipped']) ? $settings['openbay_amazonus_order_status_partially_shipped'] : ''; + $shipped_status_id = isset($settings['openbay_amazonus_order_status_shipped']) ? $settings['openbay_amazonus_order_status_shipped'] : ''; + $canceled_status_id = isset($settings['openbay_amazonus_order_status_canceled']) ? $settings['openbay_amazonus_order_status_canceled'] : ''; + + $amazonus_order_statuses = array( + 'unshipped' => array('name' => $this->language->get('text_unshipped'), 'order_status_id' => $unshipped_status_id), + 'partially_shipped' => array('name' => $this->language->get('text_partially_shipped'), 'order_status_id' => $partially_shipped_status_id), + 'shipped' => array('name' => $this->language->get('text_shipped'), 'order_status_id' => $shipped_status_id), + 'canceled' => array('name' => $this->language->get('text_canceled'), 'order_status_id' => $canceled_status_id), + ); + + $data['openbay_amazonus_order_customer_group'] = isset($settings['openbay_amazonus_order_customer_group']) ? $settings['openbay_amazonus_order_customer_group'] : ''; + + $data['amazonus_order_statuses'] = $amazonus_order_statuses; + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['subscription_url'] = $this->url->link('extension/openbay/amazonus/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['itemLinks_url'] = $this->url->link('extension/openbay/amazonus_product/linkItems', 'user_token=' . $this->session->data['user_token'], true); + $data['openbay_amazonus_notify_admin'] = isset($settings['openbay_amazonus_notify_admin']) ? $settings['openbay_amazonus_notify_admin'] : ''; + $data['link_signup'] = 'https://account.openbaypro.com/amazonus/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=amazonus'; + + $api_checked = false; + $api_status = false; + $api_auth = false; + + if (!empty($data['openbay_amazonus_token']) && !empty($data['openbay_amazonus_encryption_key']) && !empty($data['openbay_amazonus_encryption_iv'])) { + $response = $this->openbay->amazonus->call('ping/info'); + + $api_checked = true; + + if (!empty($response)) { + $ping_info = simplexml_load_string($response); + + if ($ping_info === false) { + /** + * The data from the API could not be extracted from the XML + */ + } else { + $api_status = ((string)$ping_info->Api_status == 'ok') ? true : false; + $api_auth = ((string)$ping_info->Auth == 'true') ? true : false; + } + } + } + + $data['api_status'] = $api_status; + $data['api_auth'] = $api_auth; + $data['api_checked'] = $api_checked; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_settings', $data)); + } + + public function itemLinks() { + $this->load->language('extension/openbay/amazonus_links'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/itemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['user_token'] = $this->session->data['user_token']; + + $data['cancel'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_item_links', $data)); + } + + public function savedListings() { + $this->load->language('extension/openbay/amazonus_listingsaved'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['link_overview'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['user_token'] = $this->session->data['user_token']; + $this->load->model('extension/openbay/amazonus'); + $saved_products = $this->model_extension_openbay_amazonus->getSavedProducts(); + + $data['saved_products'] = array(); + + foreach($saved_products as $saved_product) { + $data['saved_products'][] = array( + 'product_id' => $saved_product['product_id'], + 'product_name' => $saved_product['product_name'], + 'product_model' => $saved_product['product_model'], + 'product_sku' => $saved_product['product_sku'], + 'amazon_sku' => $saved_product['amazonus_sku'], + 'var' => $saved_product['var'], + 'edit_link' => $this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $saved_product['product_id'] . '&sku=' . $saved_product['var'], true), + ); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_saved_listings', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/amazonus')) { + $this->error = $this->language->get('error_permission'); + } + + if (empty($this->error)) { + return true; + } + + return false; + } + + public function getVariants() { + $variants = array(); + + if ($this->openbay->addonLoad('openstock') && isset($this->request->get['product_id'])) { + $this->load->model('extension/module/openstock'); + $this->load->model('tool/image'); + $variants = $this->model_setting_module_openstock->getVariants($this->request->get['product_id']); + } + + if (empty($variants)) { + $variants = false; + } else { + foreach ($variants as $key => $variant) { + if ($variant['sku'] == '') { + unset($variants[$key]); + } + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($variants)); + } + + public function addLink() { + if (isset($this->request->get['product_id']) && isset($this->request->get['amazon_sku'])) { + $this->load->model('extension/openbay/amazonus'); + + $amazon_sku = $this->request->get['amazon_sku']; + $product_id = $this->request->get['product_id']; + $var = isset($this->request->get['var']) ? $this->request->get['var'] : ''; + + $this->model_extension_openbay_amazonus->linkProduct($amazon_sku, $product_id, $var); + + $logger = new Log('amazonus_stocks.log'); + $logger->write('addItemLink() called for product id: ' . $product_id . ', amazon sku: ' . $amazon_sku . ', var: ' . $var); + + if ($var != '' && $this->openbay->addonLoad('openstock')) { + $logger->write('Using openStock'); + $this->load->model('tool/image'); + $this->load->model('extension/module/openstock'); + $option_stocks = $this->model_setting_module_openstock->getVariants($product_id); + + $quantity_data = array(); + + foreach($option_stocks as $option_stock) { + if (isset($option_stock['sku']) && $option_stock['sku'] == $var) { + $quantity_data[$amazon_sku] = $option_stock['stock']; + break; + } + } + + if (!empty($quantity_data)) { + $logger->write('Updating quantities with data: ' . print_r($quantity_data, true)); + $this->openbay->amazonus->updateQuantities($quantity_data); + } else { + $logger->write('No quantity data will be posted . '); + } + } else { + $this->openbay->amazonus->putStockUpdateBulk(array($product_id)); + } + + $json = json_encode('ok'); + } else { + $json = json_encode('error'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function deleteLink() { + if (isset($this->request->get['amazon_sku'])) { + $this->load->model('extension/openbay/amazonus'); + + $amazon_sku = $this->request->get['amazon_sku']; + + $this->model_extension_openbay_amazonus->removeProductLink($amazon_sku); + + $json = json_encode('ok'); + } else { + $json = json_encode('error'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + public function getLinks() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + + $itemLinks = $this->model_extension_openbay_amazonus->getProductLinks(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($itemLinks)); + } + + public function getUnlinked() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + + $unlinkedProducts = $this->model_extension_openbay_amazonus->getUnlinkedProducts(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($unlinkedProducts)); + } + + public function doBulkList() { + $this->load->language('extension/openbay/amazonus_listing'); + + if (empty($this->request->post['products'])) { + $json = array( + 'message' => $this->language->get('error_not_searched'), + ); + } else { + $this->load->model('extension/openbay/amazonus_listing'); + + $delete_search_results = array(); + + $bulk_list_products = array(); + + foreach ($this->request->post['products'] as $product_id => $asin) { + $delete_search_results[] = $product_id; + + if (!empty($asin) && in_array($product_id, $this->request->post['product_ids'])) { + $bulk_list_products[$product_id] = $asin; + } + } + + $status = false; + + if ($bulk_list_products) { + $data = array(); + + $data['products'] = $bulk_list_products; + + if (!empty($this->request->post['start_selling'])) { + $data['start_selling'] = $this->request->post['start_selling']; + } + + if (!empty($this->request->post['condition']) && !empty($this->request->post['condition_note'])) { + $data['condition'] = $this->request->post['condition']; + $data['condition_note'] = $this->request->post['condition_note']; + } + + $status = $this->model_extension_openbay_amazonus_listing->doBulkListing($data); + + if ($status) { + $message = $this->language->get('text_products_sent'); + + if ($delete_search_results) { + $this->model_extension_openbay_amazonus_listing->deleteSearchResults($delete_search_results); + } + } else { + $message = $this->language->get('error_sending_products'); + } + } else { + $message = $this->language->get('error_no_products_selected'); + } + + $json = array( + 'status' => $status, + 'message' => $message, + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function doBulkSearch() { + $this->load->model('catalog/product'); + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->language('extension/openbay/amazonus_bulk_listing'); + + $json = array(); + $search_data = array(); + + if (!empty($this->request->post['product_ids'])) { + foreach ($this->request->post['product_ids'] as $product_id) { + $product = $this->model_catalog_product->getProduct($product_id); + + if (empty($product['sku'])) { + $json[$product_id] = array( + 'error' => $this->language->get('error_product_sku') + ); + } + + $key = ''; + + $id_types = array('isbn', 'upc', 'ean', 'jan', 'sku'); + + foreach ($id_types as $id_type) { + if (!empty($product[$id_type])) { + $key = $id_type; + break; + } + } + + if (!$key) { + $json[$product_id] = array( + 'error' => $this->language->get('error_searchable_fields') + ); + } + + if (!isset($json[$product_id])) { + $search_data[$key][] = array( + 'product_id' => $product['product_id'], + 'value' => trim($product[$id_type]), + ); + + $json[$product_id] = array( + 'success' => $this->language->get('text_searching') + ); + } + } + } + + if ($search_data) { + $this->model_extension_openbay_amazonus_listing->doBulkSearch($search_data); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function bulkListProducts() { + $this->load->language('extension/openbay/amazonus_bulk_listing'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/bulkListProducts', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $ping_info = simplexml_load_string($this->openbay->amazonus->call('ping/info')); + + $bulk_listing_status = false; + + if ($ping_info) { + $bulk_listing_status = ((string)$ping_info->BulkListing == 'true') ? true : false; + } + + $data['bulk_listing_status'] = $bulk_listing_status; + + $data['link_overview'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + if ($bulk_listing_status) { + $data['link_search'] = $this->url->link('extension/openbay/amazonus/doBulkSearch', 'user_token=' . $this->session->data['user_token'], true); + + $data['default_condition'] = $this->config->get('openbay_amazonus_listing_default_condition'); + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + if (!empty($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $filter = array(); + + $filter['start'] = ($page - 1) * $this->config->get('config_limit_admin'); + $filter['limit'] = $this->config->get('config_limit_admin'); + + $results = $this->model_extension_openbay_amazonus->getProductSearch($filter); + $product_total = $this->model_extension_openbay_amazonus->getProductSearchTotal($filter); + + $data['products'] = array(); + + foreach ($results as $result) { + $product = $this->model_catalog_product->getProduct($result['product_id']); + + if ($product['image'] && file_exists(DIR_IMAGE . $product['image'])) { + $image = $this->model_tool_image->resize($product['image'], 40, 40); + } else { + $image = $this->model_tool_image->resize('no_image.png', 40, 40); + } + + if ($result['status'] == 'searching') { + $search_status = $this->language->get('text_searching'); + } else if ($result['status'] == 'finished') { + $search_status = $this->language->get('text_finished'); + } else { + $search_status = '-'; + } + + $href = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true); + + $search_results = array(); + + if ($result['data']) { + foreach ($result['data'] as $search_result) { + + $link = 'https://www.amazon.com/dp/' . $search_result['asin'] . '/'; + + $search_results[] = array( + 'title' => $search_result['title'], + 'asin' => $search_result['asin'], + 'href' => $link, + ); + } + } + + $data['products'][] = array( + 'product_id' => $product['product_id'], + 'href' => $href, + 'name' => $product['name'], + 'model' => $product['model'], + 'image' => $image, + 'matches' => $result['matches'], + 'search_status' => $search_status, + 'search_results' => $search_results, + ); + } + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/amazonus/bulkListProducts', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_bulk_listing', $data)); + } + + public function bulkLinking() { + $this->load->language('extension/openbay/amazonus_bulk_linking'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('extension/openbay/amazonus'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus/bulkLinking', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $ping_info = simplexml_load_string($this->openbay->amazonus->call('ping/info')); + + $bulk_linking_status = false; + if ($ping_info) { + $bulk_linking_status = ((string)$ping_info->BulkLinking == 'true') ? true : false; + } + + $data['bulk_linking_status'] = $bulk_linking_status; + + $total_linked = $this->model_extension_openbay_amazonus->getTotalUnlinkedItemsFromReport(); + + if (isset($this->request->get['linked_item_page'])){ + $linked_item_page = (int)$this->request->get['linked_item_page']; + } else { + $linked_item_page = 1; + } + + if (isset($this->request->get['linked_item_limit'])){ + $linked_item_limit = (int)$this->request->get['linked_item_limit']; + } else { + $linked_item_limit = 25; + } + + $data['cancel_report_link'] = ''; + + if (isset($this->request->get['cancel_report']) && $this->request->get['cancel_report'] == 1) { + $this->load->model('setting/setting'); + + $settings = $this->model_setting_setting->getSetting('openbay_amazonus'); + $settings['openbay_amazonus_processing_listing_reports'] = ''; + + $this->model_setting_setting->editSetting('openbay_amazonus', $settings); + + $this->response->redirect($this->url->link('extension/openbay/amazonus/bulklinking', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['cancel_report_link'] = $this->url->link('extension/openbay/amazonus/bulklinking', 'cancel_report=1&user_token=' . $this->session->data['user_token'], true); + } + + $pagination = new Pagination(); + $pagination->total = $total_linked; + $pagination->page = $linked_item_page; + $pagination->limit = $linked_item_limit; + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/amazonus/bulkLinking', 'user_token=' . $this->session->data['user_token'] . '&linked_item_page={page}', true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($total_linked) ? (($linked_item_page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($linked_item_page - 1) * $this->config->get('config_limit_admin')) > ($total_linked - $this->config->get('config_limit_admin'))) ? $total_linked : ((($linked_item_page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $total_linked, ceil($total_linked / $this->config->get('config_limit_admin'))); + + $results = $this->model_extension_openbay_amazonus->getUnlinkedItemsFromReport($linked_item_limit, $linked_item_page); + + $products = array(); + + foreach ($results as $result) { + $products[] = array( + 'asin' => $result['asin'], + 'href_amazon' => 'https://www.amazon.com/dp/' . $result['asin'] . '/', + 'amazon_sku' => $result['amazon_sku'], + 'amazon_quantity' => $result['amazon_quantity'], + 'amazon_price' => $result['amazon_price'], + 'name' => $result['name'], + 'sku' => $result['sku'], + 'quantity' => $result['quantity'], + 'combination' => $result['combination'], + 'product_id' => $result['product_id'], + 'var' => $result['sku'], + 'href_product' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $result['product_id'], true), + ); + } + + $data['unlinked_products'] = $products; + + $data['marketplace_processing'] = $this->config->get('openbay_amazonus_processing_listing_reports'); + $data['cancel'] = $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true); + $data['link_load_listings'] = $this->url->link('extension/openbay/amazonus/loadListingReport', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_bulk_linking', $data)); + } + + public function loadListingReport() { + $this->load->model('extension/openbay/amazonus'); + $this->load->model('setting/setting'); + $this->load->language('extension/openbay/amazonus_bulk_linking'); + + $this->model_extension_openbay_amazonus->deleteListingReports(); + + $request_data = array('response_url' => HTTPS_CATALOG . 'index.php?route=extension/openbay/amazonus/listingreport'); + + $response = $this->openbay->amazonus->call('report/listing', $request_data); + + $response = json_decode($response, 1); + + $json = array(); + $json['status'] = $response['status']; + + if ($json['status']) { + $json['message'] = $this->language->get('text_report_requested'); + + $settings = $this->model_setting_setting->getSetting('openbay_amazonus'); + $settings['openbay_amazonus_processing_listing_reports'] = true; + + $this->model_setting_setting->editSetting('openbay_amazonus', $settings); + } else { + $json['message'] = $this->language->get('text_report_request_failed'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function doBulkLinking() { + $this->load->model('extension/openbay/amazonus'); + + $links = array(); + $skus = array(); + + if (!empty($this->request->post['link'])) { + foreach ($this->request->post['link'] as $link) { + if (!empty($link['product_id'])) { + $links[] = $link; + $skus[] = $link['amazon_sku']; + } + } + } + + if (!empty($links)) { + foreach ($links as $link) { + $this->model_extension_openbay_amazonus->linkProduct($link['amazon_sku'], $link['product_id'], $link['sku']); + } + + $this->model_extension_openbay_amazonus->updateAmazonSkusQuantities($skus); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('ok'))); + } + + public function doFullStockSync() { + /** + * This is used if you ever need to force a complete update of your stock levels to Amazon. + * It will get ALL products in your store then lookup any linked ones before sending to the API. + * + * This call can put serious load on your server if you have a lot of products. + * It will make a lot of database queries so ensure your php memory limit is set high enough. + */ + set_time_limit(0); + + $product_array = $this->db->query("SELECT `product_id` FROM `" . DB_PREFIX . "product`")->rows; + + $bulk_array = array(); + + foreach ($product_array as $product) { + $bulk_array[] = $product['product_id']; + } + + $this->openbay->amazonus->putStockUpdateBulk($bulk_array); + } +} diff --git a/public/admin/controller/extension/openbay/amazonus_listing.php b/public/admin/controller/extension/openbay/amazonus_listing.php new file mode 100644 index 0000000..a5ea2da --- /dev/null +++ b/public/admin/controller/extension/openbay/amazonus_listing.php @@ -0,0 +1,592 @@ +<?php +class ControllerExtensionOpenbayAmazonusListing extends Controller{ + public function create() { + $this->load->language('extension/openbay/amazonus_listing'); + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + $this->load->model('localisation/country'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if ($this->request->post) { + $result = $this->model_extension_openbay_amazonus_listing->simpleListing($this->request->post); + + if ($result['status'] === 1) { + $this->session->data['success'] = $this->language->get('text_product_sent'); + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } else { + $this->session->data['error'] = sprintf($this->language->get('text_product_not_sent'), $result['message']); + $this->response->redirect($this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->post['product_id'] . $url, true)); + } + } + + if (isset($this->request->get['product_id'])) { + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + if (empty($product_info)) { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $listing_status = $this->model_extension_openbay_amazonus->getProductStatus($this->request->get['product_id']); + + if ($listing_status === 'processing' || $listing_status === 'ok') { + $this->response->redirect($this->url->link('extension/openbay/amazonus_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true)); + } else if ($listing_status === 'error_advanced' || $listing_status === 'saved' || $listing_status === 'error_few') { + $this->response->redirect($this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true)); + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $data['url_return'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['url_search'] = $this->url->link('extension/openbay/amazonus_listing/search', 'user_token=' . $this->session->data['user_token'], true); + $data['url_advanced'] = $this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'] . $url, true); + + $data['button_search'] = $this->language->get('button_search'); + $data['button_new'] = $this->language->get('button_new'); + $data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_amazon_price'] = $this->language->get('button_amazon_price'); + $data['button_list'] = $this->language->get('button_list'); + $data['heading_title'] = $this->language->get('heading_title'); + $data['text_not_in_catalog'] = $this->language->get('text_not_in_catalog'); + $data['text_no_results'] = $this->language->get('text_no_results'); + $data['button_view_on_amazon'] = $this->language->get('button_view_on_amazon'); + $data['text_list'] = $this->language->get('text_list'); + $data['text_placeholder_search'] = $this->language->get('text_placeholder_search'); + $data['text_placeholder_condition'] = $this->language->get('text_placeholder_condition'); + $data['column_image'] = $this->language->get('column_image'); + $data['column_asin'] = $this->language->get('column_asin'); + $data['column_name'] = $this->language->get('column_name'); + $data['column_price'] = $this->language->get('column_price'); + $data['column_action'] = $this->language->get('column_action'); + $data['entry_sku'] = $this->language->get('entry_sku'); + $data['entry_condition'] = $this->language->get('entry_condition'); + $data['entry_condition_note'] = $this->language->get('entry_condition_note'); + $data['entry_price'] = $this->language->get('entry_price'); + $data['entry_sale_price'] = $this->language->get('entry_sale_price'); + $data['entry_sale_date'] = $this->language->get('entry_sale_date'); + $data['entry_quantity'] = $this->language->get('entry_quantity'); + $data['entry_start_selling'] = $this->language->get('entry_start_selling'); + $data['entry_restock_date'] = $this->language->get('entry_restock_date'); + $data['entry_from'] = $this->language->get('entry_from'); + $data['entry_to'] = $this->language->get('entry_to'); + $data['help_restock_date'] = $this->language->get('help_restock_date'); + $data['help_sku'] = $this->language->get('help_sku'); + $data['help_sale_price'] = $this->language->get('help_sale_price'); + $data['tab_required'] = $this->language->get('tab_required'); + $data['tab_additional'] = $this->language->get('tab_additional'); + $data['error_price'] = $this->language->get('error_price'); + $data['error_sku'] = $this->language->get('error_sku'); + $data['error_stock'] = $this->language->get('error_stock'); + + $data['form_action'] = $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'], true); + + $data['sku'] = trim($product_info['sku']); + + if ($this->config->get('openbay_amazonus_listing_tax_added')) { + $data['price'] = $product_info['price'] * (1 + $this->config->get('openbay_amazonus_listing_tax_added') / 100); + } else { + $data['price'] = $product_info['price']; + } + + $data['listing_errors'] = array(); + + if ($listing_status == 'error_quick') { + $data['listing_errors'] = $this->model_extension_openbay_amazonus->getProductErrors($product_info['product_id'], 3); + } + + $data['price'] = number_format($data['price'], 2, '.', ''); + $data['quantity'] = $product_info['quantity']; + $data['product_id'] = $product_info['product_id']; + + $data['conditions'] = array( + 'New' => $this->language->get('text_new'), + 'UsedLikeNew' => $this->language->get('text_used_like_new'), + 'UsedVeryGood' => $this->language->get('text_used_very_good'), + 'UsedGood' => $this->language->get('text_used_good'), + 'UsedAcceptable' => $this->language->get('text_used_acceptable'), + 'CollectibleLikeNew' => $this->language->get('text_collectible_like_new'), + 'CollectibleVeryGood' => $this->language->get('text_collectible_very_good'), + 'CollectibleGood' => $this->language->get('text_collectible_good'), + 'CollectibleAcceptable' => $this->language->get('text_collectible_acceptable'), + 'Refurbished' => $this->language->get('text_refurbished'), + ); + + $data['default_condition'] = $this->config->get('openbay_amazonus_listing_default_condition'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . $url, true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_listing', $data)); + } + + public function edit() { + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->model('extension/openbay/amazonus'); + $this->load->language('extension/openbay/amazonus_listing'); + + $this->document->setTitle($this->language->get('text_edit_heading')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus_listing/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true), + 'text' => $this->language->get('text_edit_heading'), + ); + + $status = $this->model_extension_openbay_amazonus->getProductStatus($product_id); + + if ($status === false) { + $this->response->redirect($this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + return; + } + + $data['product_links'] = $this->model_extension_openbay_amazonus->getProductLinks($product_id); + $data['url_return'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + if ($status == 'ok' || $status == 'linked') { + $data['url_create_new'] = $this->url->link('extension/openbay/amazonus_listing/createNew', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + $data['url_delete_links'] = $this->url->link('extension/openbay/amazonus_listing/deleteLinks', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + } + + if ($status == 'saved') { + $data['has_saved_listings'] = true; + } else { + $data['has_saved_listings'] = false; + } + + $data['url_saved_listings'] = $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id, true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['text_edit_heading'] = $this->language->get('text_edit_heading'); + $data['text_product_links'] = $this->language->get('text_product_links'); + $data['text_has_saved_listings'] = $this->language->get('text_has_saved_listings'); + $data['button_create_new_listing'] = $this->language->get('button_create_new_listing'); + $data['button_remove_links'] = $this->language->get('button_remove_links'); + $data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_saved_listings'] = $this->language->get('button_saved_listings'); + $data['column_name'] = $this->language->get('column_name'); + $data['column_model'] = $this->language->get('column_model'); + $data['column_combination'] = $this->language->get('column_combination'); + $data['column_sku'] = $this->language->get('column_sku'); + $data['column_amazon_sku'] = $this->language->get('column_amazon_sku'); + $data['column_sku_variant'] = $this->language->get('column_sku_variant'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_listing_edit', $data)); + } + + public function createNew() { + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + $this->load->model('extension/openbay/amazonus'); + $this->model_extension_openbay_amazonus->deleteProduct($product_id); + $this->response->redirect($this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + + public function deleteLinks() { + $this->load->language('extension/openbay/amazonus_listing'); + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->load->model('extension/openbay/amazonus'); + + $links = $this->model_extension_openbay_amazonus->getProductLinks($product_id); + foreach ($links as $link) { + $this->model_extension_openbay_amazonus->removeProductLink($link['amazonus_sku']); + } + + $this->model_extension_openbay_amazonus->deleteProduct($product_id); + $this->session->data['success'] = $this->language->get('text_links_removed'); + + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + public function search() { + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->language('extension/openbay/amazonus_listing'); + + $error = ''; + + if (empty($this->request->post['search_string'])) { + $error = $this->language->get('error_text_missing'); + } + + if ($error) { + $response = array( + 'data' => '', + 'error' => $error, + ); + } else { + $response = array( + 'data' => $this->model_extension_openbay_amazonus_listing->search($this->request->post['search_string']), + 'error' => '', + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + public function bestPrice() { + $this->load->model('extension/openbay/amazonus_listing'); + $this->load->language('extension/openbay/amazonus_listing'); + + $error = ''; + + if (empty($this->request->post['asin'])) { + $error = $this->language->get('error_missing_asin'); + } + + if (empty($this->request->post['condition'])) { + $error = $this->language->get('error_condition_missing'); + } + + if ($error) { + $response = array( + 'data' => '', + 'error' => $error, + ); + } else { + $best_price = $this->model_extension_openbay_amazonus_listing->getBestPrice($this->request->post['asin'], $this->request->post['condition']); + + if ($best_price) { + $response = array( + 'data' => $best_price, + 'error' => '', + ); + } else { + $response = array( + 'data' => '', + 'error' => $this->language->get('error_amazonus_price'), + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + public function getProductByAsin() { + $this->load->model('extension/openbay/amazonus_listing'); + + $data = $this->model_extension_openbay_amazonus_listing->getProductByAsin($this->request->post['asin']); + + $response = array( + 'title' => (string)$data['ItemAttributes']['Title'], + 'img' => (!isset($data['ItemAttributes']['SmallImage']['URL']) ? '' : $data['ItemAttributes']['SmallImage']['URL']) + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + public function getBrowseNodes() { + $this->load->model('extension/openbay/amazonus_listing'); + + $data = array( + 'node' => (isset($this->request->post['node']) ? $this->request->post['node'] : ''), + ); + + $response = $this->model_extension_openbay_amazonus_listing->getBrowseNodes($data); + + $this->response->setOutput($response); + } +} diff --git a/public/admin/controller/extension/openbay/amazonus_product.php b/public/admin/controller/extension/openbay/amazonus_product.php new file mode 100644 index 0000000..ab4f488 --- /dev/null +++ b/public/admin/controller/extension/openbay/amazonus_product.php @@ -0,0 +1,559 @@ +<?php +class ControllerExtensionOpenbayAmazonusProduct extends Controller{ + public function index() { + $this->load->language('catalog/product'); + $this->load->language('extension/openbay/amazonus_listing'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/amazonus'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $this->document->addScript('view/javascript/openbay/js/openbay.js'); + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_amazon'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus_listing/create', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_title_advanced'), + ); + + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + die('No product id'); + } + + if (isset($this->request->get['sku'])) { + $variation = $this->request->get['sku']; + } else { + $variation = ''; + } + $data['variation'] = $variation; + $data['errors'] = array(); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { + $data_array = $this->request->post; + + $this->model_extension_openbay_amazonus->saveProduct($product_id, $data_array); + + if ($data_array['upload_after'] === 'true') { + $upload_result = $this->uploadItems(); + if ($upload_result['status'] == 'ok') { + $this->session->data['success'] = $this->language->get('text_uploaded'); + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } else { + $data['errors'][] = Array('message' => $upload_result['error_message']); + } + } else { + $this->session->data['success'] = $this->language->get('text_saved_local'); + $this->response->redirect($this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $saved_listing_data = $this->model_extension_openbay_amazonus->getProduct($product_id, $variation); + if (empty($saved_listing_data)) { + $listing_saved = false; + } else { + $listing_saved = true; + } + + $errors = $this->model_extension_openbay_amazonus->getProductErrors($product_id); + foreach($errors as $error) { + $error['message'] = 'Error for SKU: "' . $error['sku'] . '" - ' . $this->formatUrlsInText($error['message']); + $data['errors'][] = $error; + } + if (!empty($errors)) { + $data['has_listing_errors'] = true; + } else { + $data['has_listing_errors'] = false; + } + + $product_info = $this->model_catalog_product->getProduct($product_id); + $data['listing_name'] = $product_info['name'] . " : " . $product_info['model']; + $data['listing_sku'] = $product_info['sku']; + $data['listing_url'] = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + + if ($listing_saved) { + $data['edit_product_category'] = $saved_listing_data['category']; + } else { + $data['edit_product_category'] = ''; + } + + $data['amazonus_categories'] = array(); + + $amazonus_templates = $this->openbay->amazonus->getCategoryTemplates(); + + foreach($amazonus_templates as $template) { + $template = (array)$template; + $category_data = array( + 'friendly_name' => $template['friendly_name'], + 'name' => $template['name'], + 'template' => $template['xml'] + ); + $data['amazonus_categories'][] = $category_data; + } + + if ($listing_saved) { + $data['template_parser_url'] = html_entity_decode($this->url->link('extension/openbay/amazonus_product/parseTemplateAjax&edit_id=' . $product_id, 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['template_parser_url'] = html_entity_decode($this->url->link('extension/openbay/amazonus_product/parseTemplateAjax&product_id=' . $product_id, 'user_token=' . $this->session->data['user_token'], true)); + } + + $data['url_remove_errors'] = $this->url->link('extension/openbay/amazonus_product/removeErrors', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true); + $data['cancel_url'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['saved_listings_url'] = $this->url->link('extension/openbay/amazonus/savedListings', 'user_token=' . $this->session->data['user_token'], true); + $data['main_url'] = $this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . $url, true); + $data['user_token'] = $this->session->data['user_token']; + $data['no_image'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + if ($this->openbay->addonLoad('openstock')) { + $this->load->model('extension/module/openstock'); + $data['options'] = $this->model_setting_module_openstock->getVariants($product_id); + } else { + $data['options'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/amazonus_listing_advanced', $data)); + } + + public function removeErrors() { + $url = ''; + + if (isset($this->request->get['filter_name'])) { + $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_model'])) { + $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_price'])) { + $url .= '&filter_price=' . $this->request->get['filter_price']; + } + + if (isset($this->request->get['filter_price_to'])) { + $url .= '&filter_price_to=' . $this->request->get['filter_price_to']; + } + + if (isset($this->request->get['filter_quantity'])) { + $url .= '&filter_quantity=' . $this->request->get['filter_quantity']; + } + + if (isset($this->request->get['filter_quantity_to'])) { + $url .= '&filter_quantity_to=' . $this->request->get['filter_quantity_to']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_sku'])) { + $url .= '&filter_sku=' . $this->request->get['filter_sku']; + } + + if (isset($this->request->get['filter_desc'])) { + $url .= '&filter_desc=' . $this->request->get['filter_desc']; + } + + if (isset($this->request->get['filter_category'])) { + $url .= '&filter_category=' . $this->request->get['filter_category']; + } + + if (isset($this->request->get['filter_manufacturer'])) { + $url .= '&filter_manufacturer=' . $this->request->get['filter_manufacturer']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + if (isset($this->request->get['product_id'])) { + $product_id = $this->request->get['product_id']; + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'] . $url, true)); + } + + $this->load->model('extension/openbay/amazonus'); + $this->model_extension_openbay_amazonus->removeAdvancedErrors($product_id); + $this->session->data['success'] = 'Errors removed'; + $this->response->redirect($this->url->link('extension/openbay/amazonus_product', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_id . $url, true)); + } + + public function deleteSaved() { + if (!isset($this->request->get['product_id']) || !isset($this->request->get['var'])) { + return; + } + + $this->load->model('extension/openbay/amazonus'); + $this->model_extension_openbay_amazonus->deleteSaved($this->request->get['product_id'], $this->request->get['var']); + } + + public function uploadSaved() { + ob_start(); + $json = json_encode($this->uploadItems()); + ob_clean(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput($json); + } + + private function uploadItems() { + $this->load->language('extension/openbay/amazonus_listing'); + $this->load->model('extension/openbay/amazonus'); + $logger = new Log('amazonus_product.log'); + + $logger->write('Uploading process started . '); + + $saved_products = $this->model_extension_openbay_amazonus->getSavedProductsData(); + + if (empty($saved_products)) { + $logger->write('No saved listings found. Uploading canceled . '); + $result['status'] = 'error'; + $result['error_message'] = 'No saved listings. Nothing to upload. Aborting . '; + return $result; + } + + foreach($saved_products as $saved_product) { + $product_data_decoded = (array)json_decode($saved_product['data']); + + $catalog = defined(HTTPS_CATALOG) ? HTTPS_CATALOG : HTTP_CATALOG; + $response_data = array("response_url" => $catalog . 'index.php?route=extension/openbay/amazonus/product'); + $category_data = array('category' => (string)$saved_product['category']); + $fields_data = array('fields' => (array)$product_data_decoded['fields']); + + $mp_array = array(); //Amazon US does not have marketplace selection + $marketplaces_data = array('marketplaces' => $mp_array); + + $product_data = array_merge($category_data, $fields_data, $response_data, $marketplaces_data); + $insertion_response = $this->openbay->amazonus->insertProduct($product_data); + + $logger->write("Uploading product with data:" . print_r($product_data, true) . " + Got response:" . print_r($insertion_response, true)); + + if (!isset($insertion_response['status']) || $insertion_response['status'] == 'error') { + $details = isset($insertion_response['info']) ? $insertion_response['info'] : 'Unknown'; + $result['error_message'] = sprintf($this->language->get('error_upload_failed'), $saved_product['product_sku'], $details); + $result['status'] = 'error'; + break; + } + $logger->write('Product upload success'); + $this->model_extension_openbay_amazonus->setProductUploaded($saved_product['product_id'], $insertion_response['insertion_id'], $saved_product['var']); + } + + if (!isset($result['status'])) { + $result['status'] = 'ok'; + $logger->write('Uploading process completed successfully . '); + } else { + $logger->write('Uploading process failed with message: ' . $result['error_message']); + } + return $result; + } + + public function parseTemplateAjax() { + $this->load->model('tool/image'); + $log = new Log('amazonus_product.log'); + + $result = array(); + + if (isset($this->request->get['xml'])) { + $request = array('template' => $this->request->get['xml'], 'version' => 2); + $response = $this->openbay->amazonus->call("productv2/GetTemplateXml", $request); + if ($response) { + $template = $this->openbay->amazonus->parseCategoryTemplate($response); + if ($template) { + $variation = isset($this->request->get['sku']) ? $this->request->get['sku'] : ''; + + if (isset($this->request->get['product_id'])) { + $template['fields'] = $this->fillDefaultValues($this->request->get['product_id'], $template['fields'], $variation); + } elseif (isset($this->request->get['edit_id'])) { + $template['fields'] = $this->fillSavedValues($this->request->get['edit_id'], $template['fields'], $variation); + } + + foreach($template['fields'] as $key => $field) { + if ($field['accepted']['type'] == 'image') { + if (empty($field['value'])) { + $template['fields'][$key]['thumb'] = ''; + } else { + $template['fields'][$key]['thumb'] = $this->model_tool_image->resize(str_replace(HTTPS_CATALOG . 'image/', '', $field['value']), 100, 100); + } + } + } + + $result = array( + "category" => $template['category'], + "fields" => $template['fields'], + "tabs" => $template['tabs'] + ); + } else { + $json_decoded = json_decode($response); + if ($json_decoded) { + $result = $json_decoded; + } else { + $result = array('status' => 'error'); + $log->write("admin/openbay/amazon_product/parseTemplateAjax failed to parse template response: " . $response); + } + } + } else { + $log->write("admin/openbay/amazonus_product/parseTemplateAjax failed calling productv2/GetTemplateXml with params: " . print_r($request, true)); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($result)); + } + + private function fillDefaultValues($product_id, $fields_array, $var = '') { + $this->load->model('catalog/product'); + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/amazonus'); + + $openbay_settings = $this->model_setting_setting->getSetting('openbay_amazonus'); + + $product_info = $this->model_catalog_product->getProduct($product_id); + $product_info['description'] = trim(utf8_encode(strip_tags(html_entity_decode($product_info['description']), "<br>"))); + $product_info['image'] = HTTPS_CATALOG . 'image/' . $product_info['image']; + + $tax_added = isset($openbay_settings['openbay_amazonus_listing_tax_added']) ? $openbay_settings['openbay_amazonus_listing_tax_added'] : 0; + $default_condition = isset($openbay_settings['openbay_amazonus_listing_default_condition']) ? $openbay_settings['openbay_amazonus_listing_default_condition'] : ''; + $product_info['price'] = number_format($product_info['price'] + $tax_added / 100 * $product_info['price'], 2, '.', ''); + + /*Key must be lowecase */ + $defaults = array( + 'sku' => $product_info['sku'], + 'title' => $product_info['name'], + 'quantity' => $product_info['quantity'], + 'standardprice' => $product_info['price'], + 'description' => $product_info['description'], + 'mainimage' => $product_info['image'], + 'currency' => $this->config->get('config_currency'), + 'shippingweight' => number_format($product_info['weight'], 2, '.', ''), + 'conditiontype' => $default_condition, + ); + + $this->load->model('localisation/weight_class'); + $weight_class = $this->model_localisation_weight_class->getWeightClass($product_info['weight_class_id']); + if (!empty($weight_class)) { + $defaults['shippingweightunitofmeasure'] = $weight_class['unit']; + } + + $this->load->model('catalog/manufacturer'); + $manufacturer = $this->model_catalog_manufacturer->getManufacturer($product_info['manufacturer_id']); + if (!empty($manufacturer)) { + $defaults['manufacturer'] = $manufacturer['name']; + $defaults['brand'] = $manufacturer['name']; + } + + $product_images = $this->model_catalog_product->getProductImages($product_id); + $image_index = 1; + foreach($product_images as $product_image) { + $defaults['pt' . $image_index] = HTTPS_CATALOG . 'image/' . $product_image['image']; + $image_index ++; + } + + if (!empty($product_info['upc'])) { + $defaults['type'] = 'UPC'; + $defaults['value'] = $product_info['upc']; + } else if (!empty($product_info['ean'])) { + $defaults['type'] = 'EAN'; + $defaults['value'] = $product_info['ean']; + } + + $meta_keywords = explode(',', $product_info['meta_keyword']); + foreach ($meta_keywords as $index => $meta_keyword) { + $defaults['searchterms' . $index] = trim($meta_keyword); + } + + if ($var !== '' && $this->openbay->addonLoad('openstock')) { + $this->load->model('tool/image'); + $this->load->model('extension/module/openstock'); + $option_stocks = $this->model_setting_module_openstock->getVariants($product_id); + + $option = ''; + foreach ($option_stocks as $option_iterator) { + if ($option_iterator['sku'] === $var) { + $option = $option_iterator; + break; + } + } + + if ($option != null) { + $defaults['sku'] = $option['sku']; + $defaults['quantity'] = $option['stock']; + $defaults['standardprice'] = number_format($option['price'] + $tax_added / 100 * $option['price'], 2, '.', ''); + $defaults['shippingweight'] = number_format($option['weight'], 2, '.', ''); + + if (!empty($option['image'])) { + $defaults['mainimage'] = HTTPS_CATALOG . 'image/' . $option['image']; + } + } + } + + if ($defaults['shippingweight'] <= 0) { + unset($defaults['shippingweight']); + unset($defaults['shippingweightunitofmeasure']); + } + + $filled_array = array(); + + foreach($fields_array as $field) { + + $value_array = array('value' => ''); + + if (isset($defaults[strtolower($field['name'])])) { + $value_array = array('value' => $defaults[strtolower($field['name'])]); + } + + $filled_item = array_merge($field, $value_array); + + $filled_array[] = $filled_item; + } + return $filled_array; + } + + private function fillSavedValues($product_id, $fields_array, $var = '') { + $this->load->model('extension/openbay/amazonus'); + $saved_listing = $this->model_extension_openbay_amazonus->getProduct($product_id, $var); + + $decoded_data = (array)json_decode($saved_listing['data']); + $saved_fields = (array)$decoded_data['fields']; + + $saved_fields['Quantity'] = $this->model_extension_openbay_amazonus->getProductQuantity($product_id, $var); + + $filled_array = array(); + + foreach($fields_array as $field) { + $value_array = array('value' => ''); + + if (isset($saved_fields[$field['name']])) { + $value_array = array('value' => $saved_fields[$field['name']]); + } + + $filled_item = array_merge($field, $value_array); + + $filled_array[] = $filled_item; + } + + return $filled_array; + } + + public function resetPending() { + $this->db->query("UPDATE `" . DB_PREFIX . "amazonus_product` SET `status` = 'saved' WHERE `status` = 'uploaded'"); + } + + private function validateForm() { + return true; + } + + private function formatUrlsInText($text) { + $regex_url = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; + preg_match_all($regex_url, $text, $matches); + $used_patterns = array(); + foreach($matches[0] as $pattern) { + if (!array_key_exists($pattern, $used_patterns)) { + $used_patterns[$pattern]=true; + $text = str_replace($pattern, "<a target='_blank' href=" . $pattern . ">" . $pattern . "</a>", $text); + } + } + return $text; + } +} diff --git a/public/admin/controller/extension/openbay/ebay.php b/public/admin/controller/extension/openbay/ebay.php new file mode 100644 index 0000000..b0687bf --- /dev/null +++ b/public/admin/controller/extension/openbay/ebay.php @@ -0,0 +1,2421 @@ +<?php +class ControllerExtensionOpenbayEbay extends Controller { + public function install() { + $this->load->language('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/ebay_profile'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/ebay_profile'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/ebay_template'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/ebay_template'); + + $this->model_extension_openbay_ebay->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/ebay'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_ebay->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->language('extension/openbay/ebay'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['validation'] = $this->openbay->ebay->validate(); + $data['links_settings'] = $this->url->link('extension/openbay/ebay/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['links_itemlink'] = $this->url->link('extension/openbay/ebay/viewItemLinks', 'user_token=' . $this->session->data['user_token'], true); + $data['links_subscribe'] = $this->url->link('extension/openbay/ebay/subscription', 'user_token=' . $this->session->data['user_token'], true); + $data['links_usage'] = $this->url->link('extension/openbay/ebay/viewUsage', 'user_token=' . $this->session->data['user_token'], true); + $data['links_itemimport'] = $this->url->link('extension/openbay/ebay/viewItemImport', 'user_token=' . $this->session->data['user_token'], true); + $data['links_orderimport'] = $this->url->link('extension/openbay/ebay/viewOrderImport', 'user_token=' . $this->session->data['user_token'], true); + $data['links_usage'] = $this->url->link('extension/openbay/ebay/viewUsage', 'user_token=' . $this->session->data['user_token'], true); + $data['links_sync'] = $this->url->link('extension/openbay/ebay/syncronise', 'user_token=' . $this->session->data['user_token'], true); + $data['links_linkmaintenance'] = $this->url->link('extension/openbay/ebay/viewItemLinkMaintenance', 'user_token=' . $this->session->data['user_token'], true); + $data['links_summary'] = $this->url->link('extension/openbay/ebay/summary', 'user_token=' . $this->session->data['user_token'], true); + $data['links_profile'] = $this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true); + $data['links_template'] = $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/ebay/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=ebay'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay', $data)); + } + + public function settings() { + $this->load->language('extension/openbay/ebay_settings'); + + $data = $this->language->all(); + + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('localisation/currency'); + $this->load->model('localisation/order_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { + $this->model_setting_setting->editSetting('ebay', $this->request->post); + $this->session->data['success'] = $this->language->get('text_success'); + $this->response->redirect($this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['action'] = $this->url->link('extension/openbay/ebay/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/ebay/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=ebay'; + $data['link_token_renew'] = 'https://account.openbaypro.com/ebay/apiRenew/?utm_source=opencart_install&utm_medium=settings&utm_campaign=ebaytoken'; + $data['link_update'] = 'https://account.openbaypro.com/ebay/apiUpdate/?utm_source=opencart_install&utm_medium=settings&utm_campaign=ebayupdate'; + + if (isset($this->request->post['ebay_def_currency'])) { + $data['ebay_def_currency'] = $this->request->post['ebay_def_currency']; + } else { + $data['ebay_def_currency'] = $this->config->get('ebay_def_currency'); + } + $data['currency_list'] = $this->model_localisation_currency->getCurrencies(); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->request->post['ebay_status'])) { + $data['ebay_status'] = $this->request->post['ebay_status']; + } else { + $data['ebay_status'] = $this->config->get('ebay_status'); + } + + if (isset($this->request->post['ebay_token'])) { + $data['ebay_token'] = trim($this->request->post['ebay_token']); + } else { + $data['ebay_token'] = trim($this->config->get('ebay_token')); + } + + if (isset($this->request->post['ebay_secret'])) { + $data['ebay_secret'] = trim($this->request->post['ebay_secret']); + } else { + $data['ebay_secret'] = trim($this->config->get('ebay_secret')); + } + + if (isset($this->request->post['ebay_encryption_key'])) { + $data['ebay_encryption_key'] = trim($this->request->post['ebay_encryption_key']); + } else { + $data['ebay_encryption_key'] = trim($this->config->get('ebay_encryption_key')); + } + + if (isset($this->request->post['ebay_encryption_iv'])) { + $data['ebay_encryption_iv'] = trim($this->request->post['ebay_encryption_iv']); + } else { + $data['ebay_encryption_iv'] = trim($this->config->get('ebay_encryption_iv')); + } + + if (isset($this->request->post['ebay_enditems'])) { + $data['ebay_enditems'] = $this->request->post['ebay_enditems']; + } else { + $data['ebay_enditems'] = $this->config->get('ebay_enditems'); + } + + if (isset($this->request->post['ebay_relistitems'])) { + $data['ebay_relistitems'] = $this->request->post['ebay_relistitems']; + } else { + $data['ebay_relistitems'] = $this->config->get('ebay_relistitems'); + } + + if (isset($this->request->post['ebay_disable_nostock'])) { + $data['ebay_disable_nostock'] = $this->request->post['ebay_disable_nostock']; + } else { + $data['ebay_disable_nostock'] = $this->config->get('ebay_disable_nostock'); + } + if (isset($this->request->post['ebay_logging'])) { + $data['ebay_logging'] = $this->request->post['ebay_logging']; + } else { + $data['ebay_logging'] = $this->config->get('ebay_logging'); + } + + if (isset($this->request->post['ebay_created_hours'])) { + $data['ebay_created_hours'] = $this->request->post['ebay_created_hours']; + } else { + $data['ebay_created_hours'] = $this->config->get('ebay_created_hours'); + } + + if (isset($this->request->post['ebay_time_offset'])) { + $data['ebay_time_offset'] = $this->request->post['ebay_time_offset']; + } else { + $data['ebay_time_offset'] = $this->config->get('ebay_time_offset'); + } + + if (isset($this->request->post['ebay_update_notify'])) { + $data['ebay_update_notify'] = $this->request->post['ebay_update_notify']; + } else { + $data['ebay_update_notify'] = $this->config->get('ebay_update_notify'); + } + + if (isset($this->request->post['ebay_confirm_notify'])) { + $data['ebay_confirm_notify'] = $this->request->post['ebay_confirm_notify']; + } else { + $data['ebay_confirm_notify'] = $this->config->get('ebay_confirm_notify'); + } + + if (isset($this->request->post['ebay_confirmadmin_notify'])) { + $data['ebay_confirmadmin_notify'] = $this->request->post['ebay_confirmadmin_notify']; + } else { + $data['ebay_confirmadmin_notify'] = $this->config->get('ebay_confirmadmin_notify'); + } + + if (isset($this->request->post['ebay_itm_link'])) { + $data['ebay_itm_link'] = $this->request->post['ebay_itm_link']; + } else { + $data['ebay_itm_link'] = $this->config->get('ebay_itm_link'); + } + + if (isset($this->request->post['ebay_stock_allocate'])) { + $data['ebay_stock_allocate'] = $this->request->post['ebay_stock_allocate']; + } else { + $data['ebay_stock_allocate'] = $this->config->get('ebay_stock_allocate'); + } + + if (isset($this->request->post['ebay_create_date'])) { + $data['ebay_create_date'] = $this->request->post['ebay_create_date']; + } else { + $data['ebay_create_date'] = $this->config->get('ebay_create_date'); + } + + $data['durations'] = array( + 'Days_1' => $data['text_listing_1day'], + 'Days_3' => $data['text_listing_3day'], + 'Days_5' => $data['text_listing_5day'], + 'Days_7' => $data['text_listing_7day'], + 'Days_10' => $data['text_listing_10day'], + 'Days_30' => $data['text_listing_30day'], + 'GTC' => $data['text_listing_gtc'] + ); + + if (isset($this->request->post['ebay_duration'])) { + $data['ebay_duration'] = $this->request->post['ebay_duration']; + } else { + $data['ebay_duration'] = $this->config->get('ebay_duration'); + } + + if (isset($this->request->post['ebay_measurement'])) { + $data['ebay_measurement'] = $this->request->post['ebay_measurement']; + } else { + $data['ebay_measurement'] = $this->config->get('ebay_measurement'); + } + + if (isset($this->request->post['ebay_default_addressformat'])) { + $data['ebay_default_addressformat'] = $this->request->post['ebay_default_addressformat']; + } else { + $data['ebay_default_addressformat'] = $this->config->get('ebay_default_addressformat'); + } + + $data['payment_options'] = $this->model_extension_openbay_ebay->getPaymentTypes(); + + if (isset($this->request->post['ebay_payment_types'])) { + $data['ebay_payment_types'] = $this->request->post['ebay_payment_types']; + } else { + $data['ebay_payment_types'] = $this->config->get('ebay_payment_types'); + } + + if (isset($this->request->post['ebay_payment_instruction'])) { + $data['ebay_payment_instruction'] = $this->request->post['ebay_payment_instruction']; + } else { + $data['ebay_payment_instruction'] = $this->config->get('ebay_payment_instruction'); + } + + if (isset($this->request->post['ebay_payment_paypal_address'])) { + $data['ebay_payment_paypal_address'] = $this->request->post['ebay_payment_paypal_address']; + } else { + $data['ebay_payment_paypal_address'] = $this->config->get('ebay_payment_paypal_address'); + } + + if (isset($this->request->post['ebay_payment_immediate'])) { + $data['ebay_payment_immediate'] = $this->request->post['ebay_payment_immediate']; + } else { + $data['ebay_payment_immediate'] = $this->config->get('ebay_payment_immediate'); + } + + if (isset($this->request->post['ebay_tax_listing'])) { + $data['ebay_tax_listing'] = $this->request->post['ebay_tax_listing']; + } else { + $data['ebay_tax_listing'] = $this->config->get('ebay_tax_listing'); + } + + if (isset($this->request->post['ebay_tax'])) { + $data['ebay_tax'] = $this->request->post['ebay_tax']; + } else { + $data['ebay_tax'] = $this->config->get('ebay_tax'); + } + + if (isset($this->request->post['ebay_import_unpaid'])) { + $data['ebay_import_unpaid'] = $this->request->post['ebay_import_unpaid']; + } else { + $data['ebay_import_unpaid'] = $this->config->get('ebay_import_unpaid'); + } + + if (isset($this->request->post['ebay_status_partial_refund_id'])) { + $data['ebay_status_partial_refund_id'] = $this->request->post['ebay_status_partial_refund_id']; + } else { + $data['ebay_status_partial_refund_id'] = $this->config->get('ebay_status_partial_refund_id'); + } + + if (isset($this->request->post['ebay_status_import_id'])) { + $data['ebay_status_import_id'] = $this->request->post['ebay_status_import_id']; + } else { + $data['ebay_status_import_id'] = $this->config->get('ebay_status_import_id'); + } + + if (isset($this->request->post['ebay_status_paid_id'])) { + $data['ebay_status_paid_id'] = $this->request->post['ebay_status_paid_id']; + } else { + $data['ebay_status_paid_id'] = $this->config->get('ebay_status_paid_id'); + } + + if (isset($this->request->post['ebay_status_shipped_id'])) { + $data['ebay_status_shipped_id'] = $this->request->post['ebay_status_shipped_id']; + } else { + $data['ebay_status_shipped_id'] = $this->config->get('ebay_status_shipped_id'); + } + + if (isset($this->request->post['ebay_status_cancelled_id'])) { + $data['ebay_status_cancelled_id'] = $this->request->post['ebay_status_cancelled_id']; + } else { + $data['ebay_status_cancelled_id'] = $this->config->get('ebay_status_cancelled_id'); + } + + if (isset($this->request->post['ebay_status_refunded_id'])) { + $data['ebay_status_refunded_id'] = $this->request->post['ebay_status_refunded_id']; + } else { + $data['ebay_status_refunded_id'] = $this->config->get('ebay_status_refunded_id'); + } + + $data['api_server'] = $this->openbay->ebay->getServer(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['measurement_types'] = $this->openbay->ebay->getSetting('measurement_types'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_settings', $data)); + } + + public function updateSettings() { + set_time_limit(0); + + $json = $this->openbay->ebay->updateSettings(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function updateCategories() { + set_time_limit(0); + + $json = $this->openbay->ebay->updateCategories(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function updateStore() { + set_time_limit(0); + + $json = $this->openbay->ebay->updateStore(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getCategories() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getCategory($this->request->get['parent']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getSuggestedCategories() { + $this->load->model('extension/openbay/ebay'); + + $this->load->language('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getSuggestedCategories($this->request->get['qry']); + + if (empty($json['data'])) { + $json['msg'] = $this->language->get('error_category_nosuggestions'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getShippingService() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getShippingService($this->request->get['loc'], $this->request->get['type']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getEbayCategorySpecifics() { + $this->load->model('extension/openbay/ebay'); + $this->load->model('catalog/product'); + $this->load->model('catalog/attribute'); + + $response = $this->model_extension_openbay_ebay->getEbayCategorySpecifics($this->request->get['category_id']); + + $recommendation_data = array(); + + if (isset($response['data']['Recommendations']['NameRecommendation'])) { + if (isset($response['data']['Recommendations']['NameRecommendation']['Name'])) { + $recommendations = array($response['data']['Recommendations']['NameRecommendation']); + } else { + $recommendations = $response['data']['Recommendations']['NameRecommendation']; + } + + foreach ($recommendations as $name_recommendation_key => $name_recommendation) { + $recommendation_data_option = array( + 'name' => $name_recommendation['Name'], + 'validation' => + array( + 'max_values' => $name_recommendation['ValidationRules']['MaxValues'], + 'selection_mode' => $name_recommendation['ValidationRules']['SelectionMode'], + ), + 'unmatched_value' => '', + ); + + if (isset($name_recommendation['ValueRecommendation'])) { + if (!isset($name_recommendation['ValueRecommendation']['Value'])) { + foreach($name_recommendation['ValueRecommendation'] as $value_recommendation_key => $value_recommendation) { + $recommendation_data_option['options'][] = $value_recommendation['Value']; + } + } + } + + $recommendation_data[] = $recommendation_data_option; + } + + if (isset($this->request->get['product_id'])) { + $product_attributes = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']); + + foreach ($product_attributes as $product_attribute) { + $attribute_info = $this->model_catalog_attribute->getAttribute($product_attribute['attribute_id']); + + if ($attribute_info) { + // search the ebay attribute results for a match + foreach($recommendation_data as $name_recommendation_key => $name_recommendation) { + if (strtolower($attribute_info['name']) == strtolower($name_recommendation['name'])) { + $preset_match_found = false; + + if (isset($name_recommendation['options'])) { + foreach($name_recommendation['options'] as $value_recommendation_key => $value_recommendation) { + if (strtolower($value_recommendation) == strtolower($product_attribute['product_attribute_description'][$this->config->get('config_language_id')]['text'])) { + $preset_match_found = $value_recommendation_key; + } + } + } + + if ($preset_match_found === false) { + if ($name_recommendation['validation']['selection_mode'] == 'FreeText') { + $recommendation_data[$name_recommendation_key]['unmatched_value'] = $product_attribute['product_attribute_description'][$this->config->get('config_language_id')]['text']; + } + } else { + $recommendation_data[$name_recommendation_key]['matched_value_key'] = $preset_match_found; + } + } + } + } + } + } + } + + $json = array( + 'data' => $recommendation_data, + 'msg' => $response['msg'], + 'error' => $response['error'], + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getCategoryFeatures() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getCategoryFeatures($this->request->get['category']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function searchEbayCatalog() { + $this->load->language('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_product'); + + $response = $this->model_extension_openbay_ebay_product->searchEbayCatalog($this->request->post['search'], $this->request->post['category_id']); + + $json = array('error' => false, 'error_message' => ''); + + if (isset($response['ack'])) { + if ($response['ack'] == 'Success') { + $json['results'] = (int)$response['productSearchResult']['paginationOutput']['totalEntries']; + $json['page'] = (int)$response['productSearchResult']['paginationOutput']['pageNumber']; + $json['page_total'] = (int)$response['productSearchResult']['paginationOutput']['totalPages']; + + if (isset($response['productSearchResult']['products'])) { + $json['products'] = $response['productSearchResult']['products']; + } else { + $json = array('error' => true, 'error_message' => $this->language->get('error_no_products')); + } + } else { + if (isset($response['errorMessage']['error']['message'])) { + $json = array('error' => true, 'error_message' => $response['errorMessage']['error']['message']); + } else { + $json = array('error' => true, 'error_message' => $this->language->get('error_loading_catalog')); + } + } + } else { + $json = array('error' => true, 'error_message' => $this->language->get('error_generic_fail')); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function summary() { + $this->load->language('extension/openbay/ebay_summary'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/summary', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_summary', $data)); + } + + public function getSellerSummary() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getSellerSummary(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function verifyCredentials() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->verifyCredentials(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function viewItemImport() { + $this->load->language('extension/openbay/ebay_import'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_product'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/viewItemImport', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + $data['maintenance'] = $this->config->get('config_maintenance'); + $data['image_import'] = $this->model_extension_openbay_ebay_product->countImportImages(); + $data['ini_setting_post_max_size'] = ini_get('post_max_size'); + $data['ini_setting_memory_limit'] = ini_get('memory_limit'); + $data['image_import_link'] = $this->url->link('extension/openbay/ebay/getImportImages', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_item_import', $data)); + } + + public function importItems() { + $data = array( + 'adv' => $this->request->get['advanced'], + 'c' => 1, + 'd' => $this->request->get['desc'], + 'n' => $this->request->get['note'], + 'cat' => $this->request->get['categories'], + ); + + $this->openbay->ebay->callNoResponse('setup/getItemsMain/', $data); + + $json = array('msg' => 'ok'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getImportImages() { + set_time_limit(0); + $this->openbay->ebay->getImages(); + + $json = array('error' => false, 'msg' => 'OK'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function importOrdersManual() { + $this->openbay->ebay->callNoResponse('order/getOrdersManual/'); + + $json = array('msg' => 'ok'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getProductStock() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getProductStock($this->request->get['pid']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function setProductStock() { + $this->load->model('extension/openbay/ebay'); + $this->load->model('catalog/product'); + + $product = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + $json = array(); + + if ($product['subtract'] == 1) { + $this->openbay->ebay->productUpdateListen($this->request->get['product_id']); + + $json['error'] = false; + $json['msg'] = 'ok'; + } else { + $this->load->language('extension/openbay/ebay_links'); + + $json['error'] = true; + $json['msg'] = $this->language->get('error_subtract_setting'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getPlans() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getPlans(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getMyPlan() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getMyPlan(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function subscription() { + $this->load->language('extension/openbay/ebay_subscription'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/subscription', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + $data['obp_token'] = $this->config->get('ebay_token'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_subscription', $data)); + } + + public function viewUsage() { + $this->load->language('extension/openbay/ebay_usage'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/view_usage', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + $data['obp_token'] = $this->config->get('ebay_token'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_usage', $data)); + } + + public function getUsage() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->getUsage(); + $json['html'] = base64_decode($json['html']); + $json['lasterror'] = $this->openbay->ebay->lasterror; + $json['lastmsg'] = $this->openbay->ebay->lastmsg; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function viewOrderImport() { + $this->load->language('extension/openbay/ebay_orders'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/viewOrderImport', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_order_import', $data)); + } + + public function syncronise() { + $this->load->language('extension/openbay/ebay_syncronise'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/syncronise', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['warning'])) { + $data['error_warning'] = $this->session->data['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_syncronise', $data)); + } + + public function viewItemLinks() { + $this->load->language('extension/openbay/ebay_links'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('extension/openbay/ebay'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/viewItemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['cancel'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + $data['edit_url'] = $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=', true); + $data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + $total_linked = $this->model_extension_openbay_ebay->totalLinked(); + + if (isset($this->request->get['linked_item_page'])){ + $linked_item_page = (int)$this->request->get['linked_item_page']; + } else { + $linked_item_page = 1; + } + + if (isset($this->request->get['linked_item_limit'])){ + $linked_item_limit = (int)$this->request->get['linked_item_limit']; + } else { + $linked_item_limit = 100; + } + + $pagination = new Pagination(); + $pagination->total = $total_linked; + $pagination->page = $linked_item_page; + $pagination->limit = 100; + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/ebay/viewItemLinks', 'user_token=' . $this->session->data['user_token'] . '&linked_item_page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['linked_items'] = $this->model_extension_openbay_ebay->loadLinked($linked_item_limit, $linked_item_page); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_item_link', $data)); + } + + public function saveItemLink() { + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->saveItemLink($this->request->get); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function removeItemLink() { + $this->load->language('extension/openbay/ebay'); + + $this->openbay->ebay->removeItemByProductId($this->request->get['product_id']); + + $json = array('error' => false, 'msg' => $this->language->get('item_link_removed')); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function loadUnlinked(){ + set_time_limit(0); + + $this->load->model('extension/openbay/ebay'); + + $filter = array(); + + if (isset($this->request->post['filter_variant']) && !empty($this->request->post['filter_variant'])) { + $filter['variants'] = (int)$this->request->post['filter_variant']; + } + + if (isset($this->request->post['filter_title']) && !empty($this->request->post['filter_title'])) { + $filter['title'] = (string)$this->request->post['filter_title']; + } + + if (isset($this->request->post['filter_qty_min']) && !empty($this->request->post['filter_qty_min'])) { + $filter['qty_min'] = (int)$this->request->post['filter_qty_min']; + } + + if (isset($this->request->post['filter_qty_max']) && !empty($this->request->post['filter_qty_max'])) { + $filter['qty_max'] = (int)$this->request->post['filter_qty_max']; + } + + $data = $this->model_extension_openbay_ebay->loadUnlinked(200, $this->request->get['page'], $filter); + + if (!empty($data)) { + $data['more_pages'] = 1; + + if ($data['next_page'] > $data['max_page']){ + $data['more_pages'] = 0; + } + + $json['data'] = $data; + } else { + $json['data'] = null; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function loadLinkedStatus(){ + set_time_limit(0); + + $this->load->model('extension/openbay/ebay'); + + $json['data'] = ''; + if (isset($this->request->post['item_id']) && !empty($this->request->post['item_id'])){ + $data = $this->model_extension_openbay_ebay->loadLinkedStatus($this->request->post['item_id']); + + if (!empty($data)) { + $json['data'] = $data; + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + private function checkConfig() { + if ($this->config->get('ebay_token') == '' || $this->config->get('ebay_secret') == '') { + return false; + } else { + return true; + } + } + + public function edit() { + if ($this->checkConfig() == true) { + if (!empty($this->request->get['product_id'])) { + $this->load->language('extension/openbay/ebay_edit'); + + $data = $this->language->all(); + + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/manufacturer'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_product'); + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['action'] = $this->url->link('extension/openbay/ebay/create', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['view_link'] = $this->config->get('ebay_itm_link') . $this->openbay->ebay->getEbayItemId($this->request->get['product_id']); + $data['user_token'] = $this->session->data['user_token']; + $data['product_id'] = $this->request->get['product_id']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_edit', $data)); + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + } + } + } + + public function editLoad() { + $this->load->model('catalog/product'); + $this->load->model('extension/openbay/ebay_product'); + $this->load->model('tool/image'); + + $item_id = $this->openbay->ebay->getEbayItemId($this->request->get['product_id']); + + if (!empty($item_id)) { + $listings = $this->openbay->ebay->getEbayListing($item_id); + $stock = $this->openbay->ebay->getProductStockLevel($this->request->get['product_id']); + $reserve = $this->openbay->ebay->getReserve($this->request->get['product_id'], $item_id); + $options = array(); + + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + if ($this->openbay->addonLoad('openstock') && $product_info['has_option'] == 1) { + $this->load->model('extension/module/openstock'); + $data['addon']['openstock'] = true; + $product_info['options'] = $this->model_setting_module_openstock->getVariants($this->request->get['product_id']); + $product_info['option_groups'] = $this->model_extension_openbay_ebay_product->getProductOptions($this->request->get['product_id']); + + $t = array(); + $t_rel = array(); + + foreach($product_info['option_groups'] as $group) { + $t_tmp = array(); + + foreach($group['product_option_value'] as $group_node) { + $t_tmp[$group_node['option_value_id']] = $group_node['name']; + $t_rel[$group_node['product_option_value_id']] = $group['name']; + } + + $t[] = array('name' => $group['name'], 'child' => $t_tmp); + } + + if (!isset($listings['variations']['Variation'][1])) { + $listings['variations']['Variation'] = array($listings['variations']['Variation']); + } + + foreach($product_info['options'] as $option) { + $option['base64'] = base64_encode(serialize($option['option_values'])); + $option_reserve = $this->openbay->ebay->getReserve($this->request->get['product_id'], $item_id, $option['sku']); + if ($option_reserve == false) { + $option['reserve'] = 0; + } else { + $option['reserve'] = $this->openbay->ebay->getReserve($this->request->get['product_id'], $item_id, $option['sku']); + } + + $ebay_listing = ''; + + foreach($listings['variations']['Variation'] as $listing) { + + $sku = (isset($listing['SKU']) ? $listing['SKU'] : ''); + + if ($sku != '' && $sku == $option['sku']) { + $listing['StartPrice'] = number_format($listing['StartPrice'], 2, '.', ''); + $listing['Quantity'] = $listing['Quantity'] - $listing['SellingStatus']['QuantitySold']; + + $ebay_listing = $listing; + } + } + + $options[] = array('ebay' => $ebay_listing, 'local' => $option, 'sku' => $option['sku'], 'product_option_variant_id' => $option['product_option_variant_id']); + } + + //unset variants that dont appear on eBay + $options_inactive = array(); + foreach($options as $k => $option) { + if (empty($option['ebay'])) { + $options_inactive[] = $options[$k]; + unset($options[$k]); + } + } + + $variant = array( + 'variant' => 1, + 'data' => array( + 'group_information' => array( + 'option_groups' => base64_encode(serialize($t)), + 'option_group_relationship' => base64_encode(serialize($t_rel)), + ), + 'options' => $options, + 'options_inactive' => $options_inactive + ) + ); + + } else { + $variant = array('variant' => 0, 'data' => ''); + } + + if ($reserve == false) { + $reserve = 0; + } + + $data = array( + 'listing' => $listings, + 'stock' => $stock, + 'reserve' => $reserve, + 'variant' => $variant, + 'product' => $product_info + ); + + if (!empty($listings)) { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false, 'data' => $data))); + } else { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => true))); + } + } else { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => true))); + } + } + + public function editSave() { + if ($this->checkConfig() == true && $this->request->server['REQUEST_METHOD'] == 'POST') { + + $this->load->model('extension/openbay/ebay'); + + $json = $this->model_extension_openbay_ebay->editSave($this->request->post); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function create() { + if ($this->checkConfig() == true) { + if (!empty($this->request->get['product_id'])) { + $this->load->language('extension/openbay/ebay_new'); + + $data = $this->language->all(); + + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/manufacturer'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('extension/openbay/ebay_product'); + $this->load->model('extension/openbay/ebay_profile'); + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['action'] = $this->url->link('extension/openbay/ebay/create', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/create', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'], true), + 'text' => $this->language->get('heading_title'), + ); + + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + $setting = array(); + + $setting['dispatch_times'] = $this->openbay->ebay->getSetting('dispatch_time_max'); + + if (is_array($setting['dispatch_times'])) { + ksort($setting['dispatch_times']); + } + + $setting['countries'] = $this->openbay->ebay->getSetting('countries'); + + if (is_array($setting['countries'])) { + ksort($setting['countries']); + } + + $setting['returns'] = $this->openbay->ebay->getSetting('returns'); + $setting['package_type'] = $this->openbay->ebay->getSetting('package_type'); + $setting['shipping_types'] = $this->openbay->ebay->getSetting('shipping_types'); + $setting['measurement_types'] = $this->openbay->ebay->getSetting('measurement_types'); + $setting['measurement_types'] = $this->openbay->ebay->getSetting('measurement_types'); + $setting['product_details'] = $this->openbay->ebay->getSetting('product_details'); + $setting['listing_restrictions'] = $this->openbay->ebay->getSetting('listing_restrictions'); + + if (!isset($setting['product_details']['product_identifier_unavailable_text'])) { + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise&user_token=' . $this->session->data['user_token'], true)); + } + + if (empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){ + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise&token=' . $this->session->data['user_token'], true)); + } + + $data['setting'] = $setting; + + if ($this->openbay->addonLoad('openstock') && $product_info['has_option'] == 1) { + $this->load->model('extension/module/openstock'); + $data['addon']['openstock'] = true; + $product_info['options'] = $this->model_setting_module_openstock->getVariants($this->request->get['product_id']); + + $product_info['options_array'] = base64_encode(serialize($product_info['options'][0]['option_values'])); + + $product_info['option_groups'] = $this->model_extension_openbay_ebay_product->getProductOptions($this->request->get['product_id']); + + $option_group_array = array(); + $option_group_relation_array = array(); + + foreach($product_info['option_groups'] as $option_group) { + $child_option = array(); + + foreach($option_group['product_option_value'] as $group_node) { + $child_option[$group_node['option_value_id']] = $group_node['name']; + $option_group_relation_array[$group_node['product_option_value_id']] = $option_group['name']; + } + + $option_group_array[] = array('name' => $option_group['name'], 'child' => $child_option); + } + + $product_info['option_group_array'] = base64_encode(serialize($option_group_array)); + $product_info['option_group_relation_array'] = base64_encode(serialize($option_group_relation_array)); + } + + // get the product tax rate from opencart + if (isset($product_info['tax_class_id'])) { + $product_info['defaults']['tax'] = $this->model_extension_openbay_ebay_product->getTaxRate($product_info['tax_class_id']); + } else { + $product_info['defaults']['tax'] = 0.00; + } + + //get the popular categories the user has used + $product_info['popular_cats'] = $this->model_extension_openbay_ebay->getPopularCategories(); + + //get shipping profiles + $product_info['profiles_shipping'] = $this->model_extension_openbay_ebay_profile->getAll(0); + //get default shipping profile + $product_info['profiles_shipping_def'] = $this->model_extension_openbay_ebay_profile->getDefault(0); + + //get returns profiles + $product_info['profiles_returns'] = $this->model_extension_openbay_ebay_profile->getAll(1); + //get default returns profile + $product_info['profiles_returns_def'] = $this->model_extension_openbay_ebay_profile->getDefault(1); + $data['data']['shipping_international_zones'] = $this->model_extension_openbay_ebay->getShippingLocations(); + + //get theme profiles + $product_info['profiles_theme'] = $this->model_extension_openbay_ebay_profile->getAll(2); + //get default returns profile + $product_info['profiles_theme_def'] = $this->model_extension_openbay_ebay_profile->getDefault(2); + + //get generic profiles + $product_info['profiles_generic'] = $this->model_extension_openbay_ebay_profile->getAll(3); + //get default generic profile + $product_info['profiles_generic_def'] = $this->model_extension_openbay_ebay_profile->getDefault(3); + + //product attributes - this is just a direct pass through used with the template tag + $product_info['attributes'] = base64_encode(json_encode($this->model_extension_openbay_ebay->getProductAttributes($this->request->get['product_id']))); + + //post edit link + $product_info['edit_link'] = $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'], true); + + //images + $product_images = $this->model_catalog_product->getProductImages($this->request->get['product_id']); + $product_info['product_images'] = array(); + + if (!empty($product_info['image'])) { + $img_info = getimagesize(DIR_IMAGE . $product_info['image']); + + $product_info['product_images'][] = array( + 'image' => $product_info['image'], + 'preview' => $this->model_tool_image->resize($product_info['image'], 100, 100), + 'full' => HTTPS_CATALOG . 'image/' . $product_info['image'], + 'width' => $img_info[0], + 'height' => $img_info[1], + ); + } + + foreach ($product_images as $product_image) { + if ($product_image['image'] && file_exists(DIR_IMAGE . $product_image['image'])) { + $img_info = getimagesize(DIR_IMAGE . $product_image['image']); + + $product_info['product_images'][] = array( + 'image' => $product_image['image'], + 'preview' => $this->model_tool_image->resize($product_image['image'], 100, 100), + 'full' => HTTPS_CATALOG . 'image/' . $product_image['image'], + 'width' => $img_info[0], + 'height' => $img_info[1], + ); + } + } + + $product_info['manufacturers'] = $this->model_catalog_manufacturer->getManufacturers(); + $product_info['payments'] = $this->model_extension_openbay_ebay->getPaymentTypes(); + $product_info['templates'] = $this->model_extension_openbay_ebay_template->getAll(); + $product_info['store_cats'] = $this->model_extension_openbay_ebay->getSellerStoreCategories(); + + $product_info['defaults']['cod_surcharge'] = 0; + + foreach($product_info['payments'] as $payment) { + if ($payment['ebay_name'] == 'COD') { + $product_info['defaults']['cod_surcharge'] = 1; + } + } + + $product_info['defaults']['ebay_payment_types'] = $this->config->get('ebay_payment_types'); + $product_info['defaults']['paypal_address'] = $this->config->get('ebay_payment_paypal_address'); + $product_info['defaults']['payment_instruction'] = $this->config->get('ebay_payment_instruction'); + $product_info['defaults']['ebay_payment_immediate'] = $this->config->get('ebay_payment_immediate'); + + $product_info['defaults']['gallery_height'] = '400'; + $product_info['defaults']['gallery_width'] = '400'; + $product_info['defaults']['thumb_height'] = '100'; + $product_info['defaults']['thumb_width'] = '100'; + + $product_info['defaults']['ebay_measurement'] = $this->config->get('ebay_measurement'); + + $product_info['defaults']['listing_duration'] = $this->config->get('ebay_duration'); + if ($product_info['defaults']['listing_duration'] == '') { + $product_info['defaults']['listing_duration'] = 'Days_30'; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if ($product_info['quantity'] < 1 && (!isset($product_info['has_option']) || $product_info['has_option'] == 0)) { + $data['error_warning'] = $this->language->get('error_no_stock'); + } + + $data['no_image'] = $this->model_tool_image->resize('no_image.png', 100, 100); + + $weight_parts = explode('.', $product_info['weight']); + $product_info['weight_major'] = (int)$weight_parts[0]; + $product_info['weight_minor'] = (int)substr($weight_parts[1], 0, 3); + + $data['product'] = $product_info; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_new', $data)); + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true)); + } + } + } + + public function createBulk() { + if ($this->checkConfig() == true) { + if (!empty($this->request->post['selected'])) { + $this->load->language('extension/openbay/ebay_newbulk'); + + $data = $this->language->all(); + + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/manufacturer'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_profile'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay/createBulk', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['error_warning'] = array(); + + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['image_directory'] = DIR_IMAGE; + + $active_list = $this->model_extension_openbay_ebay->getLiveListingArray(); + + $products = array(); + + if ($this->openbay->addonLoad('openstock')) { + $openstock = 1; + } else { + $openstock = 0; + } + + foreach ($this->request->post['selected'] as $product_id) { + if (!array_key_exists($product_id, $active_list)) { + + $prod = $this->model_catalog_product->getProduct($product_id); + + if ($openstock == 1 && isset($prod['has_option']) && $prod['has_option'] == 1) { + $data['error_warning']['os'] = $this->language->get('text_error_variants'); + } else { + if ($prod['quantity'] > 0) { + if ($prod['image'] && file_exists(DIR_IMAGE . $prod['image'])) { + $prod['image'] = $this->model_tool_image->resize($prod['image'], 80, 80); + } else { + $prod['image'] = $this->model_tool_image->resize('no_image.png', 80, 80); + } + + $products[] = $prod; + } else { + $data['error_warning']['stock'] = $this->language->get('text_error_stock'); + } + } + } else { + $data['error_warning']['exists'] = $this->language->get('text_exists'); + } + } + + $data['count'] = count($products); + $data['user_token'] = $this->session->data['user_token']; + $data['listing_link'] = $this->config->get('ebay_itm_link'); + + $plan = $this->model_extension_openbay_ebay->getMyPlan(); + + if ($plan['plan']['listing_bulk'] == 1) { + if ($data['count'] == 0) { + $data['error_fail'][] = $this->language->get('text_error_no_product'); + } else { + if (($plan['plan']['listing_limit'] == 0) || (($plan['usage']['items'] + $data['count']) <= $plan['plan']['listing_limit'])) { + if ($data['count'] > 5) { + $data['error_warning']['count'] = sprintf($this->language->get('text_error_count'), $data['count']); + } + + //load the settings from eBay + $setting = array(); + + $setting['product_details'] = $this->openbay->ebay->getSetting('product_details'); + + if (!isset($setting['product_details']['product_identifier_unavailable_text'])) { + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise&token=' . $this->session->data['user_token'], true)); + } + + $setting['dispatch_times'] = $this->openbay->ebay->getSetting('dispatch_time_max'); + if (is_array($setting['dispatch_times'])) { + ksort($setting['dispatch_times']); + } + + $setting['countries'] = $this->openbay->ebay->getSetting('countries'); + if (is_array($setting['countries'])) { + ksort($setting['countries']); + } + + $setting['returns'] = $this->openbay->ebay->getSetting('returns'); + + if (empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){ + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise&token=' . $this->session->data['user_token'], true)); + } + + $data['setting'] = $setting; + + //get generic profiles + $product_info['profiles_generic'] = $this->model_extension_openbay_ebay_profile->getAll(3); + //get default generic profile + $product_info['profiles_generic_def'] = $this->model_extension_openbay_ebay_profile->getDefault(3); + if ($product_info['profiles_generic_def'] === false) { + $data['error_fail'][] = $this->language->get('text_error_generic_profile'); + } + + //get shipping profiles + $product_info['profiles_shipping'] = $this->model_extension_openbay_ebay_profile->getAll(0); + //get default shipping profile + $product_info['profiles_shipping_def'] = $this->model_extension_openbay_ebay_profile->getDefault(0); + //check it has a default profile + if ($product_info['profiles_shipping_def'] === false) { + $data['error_fail'][] = $this->language->get('text_error_ship_profile'); + } + + //get returns profiles + $product_info['profiles_returns'] = $this->model_extension_openbay_ebay_profile->getAll(1); + //get default returns profile + $product_info['profiles_returns_def'] = $this->model_extension_openbay_ebay_profile->getDefault(1); + //check it has a default profile + if ($product_info['profiles_returns_def'] === false) { + $data['error_fail'][] = $this->language->get('text_error_return_profile'); + } + + //get returns profiles + $product_info['profiles_theme'] = $this->model_extension_openbay_ebay_profile->getAll(2); + //get default returns profile + $product_info['profiles_theme_def'] = $this->model_extension_openbay_ebay_profile->getDefault(2); + //check it has a default profile + if ($product_info['profiles_theme_def'] === false) { + $data['error_fail'][] = $this->language->get('text_error_theme_profile'); + } + + // get the product tax rate + if (isset($product_info['tax_class_id'])) { + $product_info['defaults']['tax'] = $this->model_extension_openbay_ebay_product->getTaxRate($product_info['tax_class_id']); + } else { + $product_info['defaults']['tax'] = 0.00; + } + + $data['products'] = $products; + + $product_info['manufacturers'] = $this->model_catalog_manufacturer->getManufacturers(); + $product_info['payments'] = $this->model_extension_openbay_ebay->getPaymentTypes(); + $product_info['store_cats'] = $this->model_extension_openbay_ebay->getSellerStoreCategories(); + + $product_info['defaults']['ebay_template'] = $this->config->get('ebay_template'); + + $product_info['defaults']['listing_duration'] = $this->config->get('ebay_duration'); + if ($product_info['defaults']['listing_duration'] == '') { + $product_info['defaults']['listing_duration'] = 'Days_30'; + } + + $data['default'] = $product_info; + } else { + $data['error_fail']['plan'] = sprintf($this->language->get('text_item_limit'), $this->url->link('extension/openbay/ebay/subscription', 'user_token=' . $this->session->data['user_token'], true)); + } + } + } else { + $data['error_fail']['plan'] = sprintf($this->language->get('text_bulk_plan_error'), $this->url->link('extension/openbay/ebay/subscription', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + $this->document->addScript('view/javascript/openbay/js/openbay.js'); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_new_bulk', $data)); + } else { + $this->load->language('extension/openbay/ebay_newbulk'); + $this->session->data['warning'] = $this->language->get('text_error_no_selection'); + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + } + + public function verify() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('catalog/product'); + $this->load->model('catalog/filter'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + if ($this->checkConfig() == true) { + $this->model_extension_openbay_ebay->logCategoryUsed($this->request->post['finalCat']); + + $item_id = $this->openbay->ebay->getEbayItemId($this->request->post['product_id']); + + if ($item_id == false) { + $data = $this->request->post; + + if ($data['template'] != 'None') { + $template = $this->model_extension_openbay_ebay_template->get($data['template']); + $data['template_html'] = (isset($template['html']) ? base64_encode($template['html']) : ''); + } else { + $data['template_html'] = ''; + } + + // set shipping data + $data['national'] = $data['data']['national']; + $data['international'] = $data['data']['international']; + unset($data['data']); + + if (!empty($data['img_tpl'])) { + $tmp_gallery_array = array(); + $tmp_thumbnail_array = array(); + $this->load->model('tool/image'); + + foreach ($data['img_tpl'] as $k => $v) { + $tmp_gallery_array[$k] = $this->model_extension_openbay_openbay->storeImage($v, $data['gallery_width'], $data['gallery_height'], 'ebay'); + $tmp_thumbnail_array[$k] = $this->model_extension_openbay_openbay->storeImage($v, $data['thumb_width'], $data['thumb_height'], 'ebay'); + } + + $data['img_tpl'] = $tmp_gallery_array; + $data['img_tpl_thumb'] = $tmp_thumbnail_array; + } + + $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$data['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $data['product_info'] = $query->row; + + $data['product_info']['product_filters'] = array(); + + $filters = $this->model_catalog_product->getProductFilters($this->request->post['product_id']); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_info']['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'group' => $filter_info['group'], + 'name' => $filter_info['name'] + ); + } + } + + if (!empty($data['product_info']['sku'])){ + $data['sku'] = $data['product_info']['sku']; + } + + $json = $this->model_extension_openbay_ebay->ebayVerifyAddItem($data, $this->request->get['options']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } else { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => true, 'msg' => 'This item is already listed in your eBay account', 'item' => $item_id))); + } + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + + public function verifyBulk() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay_profile'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/filter'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + if ($this->checkConfig() == true) { + $post = $this->request->post; + $data = array(); + + //load all of the listing defaults and assign to correct variable names + $profile_shipping = $this->model_extension_openbay_ebay_profile->get($post['shipping_profile']); + $profile_return = $this->model_extension_openbay_ebay_profile->get($post['return_profile']); + $profile_template = $this->model_extension_openbay_ebay_profile->get($post['theme_profile']); + $profile_generic = $this->model_extension_openbay_ebay_profile->get($post['generic_profile']); + + $payments = $this->model_extension_openbay_ebay->getPaymentTypes(); + $payments_accepted = $this->config->get('ebay_payment_types'); + $product_info = $this->model_catalog_product->getProduct($post['product_id']); + + // set shipping data + $data['national'] = $profile_shipping['data']['national']; + $data['international'] = $profile_shipping['data']['international']; + + $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$post['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $data['product_info'] = $query->row; + + $data['product_info']['product_filters'] = array(); + + $filters = $this->model_catalog_product->getProductFilters($this->request->post['product_id']); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_info']['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'group' => $filter_info['group'], + 'name' => $filter_info['name'] + ); + } + } + + + $data['description'] = $product_info['description']; + $data['name'] = $post['title']; + $data['sub_name'] = ''; + $data['bestoffer'] = 0; + $data['finalCat'] = $post['finalCat']; + $data['price'][0] = $post['price']; + $data['qty'][0] = (int)$post['qty']; + $data['product_id'] = (int)$post['product_id']; + + $data['feat'] = $post['feat']; + $data['featother'] = $post['featother']; + + if (!empty($product_info['sku'])){ + $data['sku'] = $product_info['sku']; + } + + if (isset($post['identifier_ean']) && !empty($post['identifier_ean'])){ + $data['identifier_ean'] = $post['identifier_ean']; + } + + if (isset($post['identifier_isbn']) && !empty($post['identifier_isbn'])){ + $data['identifier_isbn'] = $post['identifier_isbn']; + } + + if (isset($post['identifier_upc']) && !empty($post['identifier_upc'])){ + $data['identifier_upc'] = $post['identifier_upc']; + } + + $data['auction_duration'] = $post['duration']; + $data['condition'] = (isset($post['condition']) && $post['condition'] != 0 ? $post['condition'] : ''); + $data['auction_type'] = 'FixedPriceItem'; + $data['catalog_epid'] = (isset($post['catalog_epid']) && $post['catalog_epid'] != 0 ? $post['catalog_epid'] : ''); + $data['identifier_upc'] = (isset($post['identifier_upc']) && $post['identifier_upc'] != '' ? $post['identifier_upc'] : ''); + $data['identifier_isbn'] = (isset($post['identifier_isbn']) && $post['identifier_isbn'] != '' ? $post['identifier_isbn'] : ''); + $data['identifier_ean'] = (isset($post['identifier_ean']) && $post['identifier_ean'] != '' ? $post['identifier_ean'] : ''); + + $data['ebay_payment_immediate'] = $this->config->get('ebay_payment_immediate'); + $data['paypal_email'] = $this->config->get('ebay_payment_paypal_address'); + $data['payment_instruction'] = $this->config->get('ebay_payment_instruction'); + + if (isset($profile_return['data']['returns_accepted'])) { + $data['returns_accepted'] = $profile_return['data']['returns_accepted']; + } + if (isset($profile_return['data']['returns_policy'])) { + $data['return_policy'] = $profile_return['data']['returns_policy']; + } + if (isset($profile_return['data']['returns_option'])) { + $data['returns_option'] = $profile_return['data']['returns_option']; + } + if (isset($profile_return['data']['returns_within'])) { + $data['returns_within'] = $profile_return['data']['returns_within']; + } + if (isset($profile_return['data']['returns_shipping'])) { + $data['returns_shipping'] = $profile_return['data']['returns_shipping']; + } + if (isset($profile_return['data']['returns_restocking_fee'])) { + $data['returns_restocking_fee'] = $profile_return['data']['returns_restocking_fee']; + } + + $data['location'] = $profile_shipping['data']['location']; + $data['postcode'] = $profile_shipping['data']['postcode']; + $data['dispatch_time'] = $profile_shipping['data']['dispatch_time']; + + if (isset($profile_shipping['data']['country'])) { + $data['country'] = $profile_shipping['data']['country']; + } + + if (isset($profile_shipping['data']['eligible_for_pickup_dropoff'])) { + $data['eligible_for_pickup_dropoff'] = $profile_shipping['data']['eligible_for_pickup_dropoff']; + } + + if (isset($profile_shipping['data']['eligible_for_pickup_instore'])) { + $data['eligible_for_pickup_instore'] = $profile_shipping['data']['eligible_for_pickup_instore']; + } + + if (isset($profile_shipping['data']['global_shipping'])) { + $data['global_shipping'] = $profile_shipping['data']['global_shipping']; + } + + if (isset($profile_shipping['data']['promotional_shipping_discount'])) { + $data['promotional_shipping_discount'] = $profile_shipping['data']['promotional_shipping_discount']; + } + + if (isset($profile_shipping['data']['promotional_shipping_discount_international'])) { + $data['promotional_shipping_discount_international'] = $profile_shipping['data']['promotional_shipping_discount_international']; + } + + $data['get_it_fast'] = (isset($profile_shipping['data']['get_it_fast']) ? $profile_shipping['data']['get_it_fast'] : 0); + + if (isset($profile_template['data']['ebay_template_id'])) { + $template = $this->model_extension_openbay_ebay_template->get($profile_template['data']['ebay_template_id']); + $data['template_html'] = (isset($template['html']) ? base64_encode($template['html']) : ''); + $data['template'] = $profile_template['data']['ebay_template_id']; + } else { + $data['template_html'] = ''; + $data['template'] = ''; + } + + $data['gallery_plus'] = $profile_template['data']['ebay_gallery_plus']; + $data['gallery_super'] = $profile_template['data']['ebay_supersize']; + + $data['private_listing'] = $profile_generic['data']['private_listing']; + + //product attributes - this is just a direct pass through used with the template tag + $data['attributes'] = base64_encode(json_encode($this->model_extension_openbay_ebay->getProductAttributes($post['product_id']))); + + $data['payments'] = array(); + foreach($payments as $payment) { + if ($payments_accepted[$payment['ebay_name']] == 1) { + $data['payments'][$payment['ebay_name']] = 1; + } + } + + $data['main_image'] = 0; + $data['img'] = array(); + + $product_images = $this->model_catalog_product->getProductImages($post['product_id']); + + $product_info['product_images'] = array(); + + if (!empty($product_info['image'])) { + $data['img'][] = $product_info['image']; + } + + if (isset($profile_template['data']['ebay_img_ebay']) && $profile_template['data']['ebay_img_ebay'] == 1) { + foreach ($product_images as $product_image) { + if ($product_image['image'] && file_exists(DIR_IMAGE . $product_image['image'])) { + $data['img'][] = $product_image['image']; + } + } + } + + if (isset($profile_template['data']['ebay_img_template']) && $profile_template['data']['ebay_img_template'] == 1) { + $tmp_gallery_array = array(); + $tmp_thumbnail_array = array(); + + //if the user has not set the exclude default image, add it to the array for theme images. + $key_offset = 0; + if (!isset($profile_template['data']['default_img_exclude']) || $profile_template['data']['default_img_exclude'] != 1) { + $tmp_gallery_array[0] = $this->model_extension_openbay_openbay->storeImage($product_info['image'], $profile_template['data']['ebay_gallery_width'], $profile_template['data']['ebay_gallery_height'], 'ebay'); + $tmp_thumbnail_array[0] = $this->model_extension_openbay_openbay->storeImage($product_info['image'], $profile_template['data']['ebay_thumb_width'], $profile_template['data']['ebay_thumb_height'], 'ebay'); + $key_offset = 1; + } + + //loop through the product images and add them. + foreach ($product_images as $k => $v) { + $tmp_gallery_array[$k+$key_offset] = $this->model_extension_openbay_openbay->storeImage($v['image'], $profile_template['data']['ebay_gallery_width'], $profile_template['data']['ebay_gallery_height'], 'ebay'); + $tmp_thumbnail_array[$k+$key_offset] = $this->model_extension_openbay_openbay->storeImage($v['image'], $profile_template['data']['ebay_thumb_width'], $profile_template['data']['ebay_thumb_height'], 'ebay'); + } + + $data['img_tpl'] = $tmp_gallery_array; + $data['img_tpl_thumb'] = $tmp_thumbnail_array; + } + + $weight_parts = explode('.', $product_info['weight']); + + // package size and weights + $data['package']['depth'] = $product_info['height']; + $data['package']['irregular'] = 0; + $data['package']['length'] = $product_info['length']; + $data['package']['unit'] = $this->config->get('ebay_measurement'); + $data['package']['weight_major'] = (int)$weight_parts[0]; + $data['package']['weight_minor'] = (int)substr($weight_parts[1], 0, 3); + $data['package']['width'] = $product_info['width']; + + $package_types = $this->openbay->ebay->getSetting('package_type'); + + foreach ($package_types as $package_type) { + if ($package_type['default'] == 1) { + $data['package']['package'] = $package_type['code']; + } + } + + $data = array_merge($data, $profile_shipping['data']); + + $verify_response = $this->model_extension_openbay_ebay->ebayVerifyAddItem($data, 'no'); + + $json = array( + 'errors' => $verify_response['data']['Errors'], + 'fees' => $verify_response['data']['Fees'], + 'itemid' => (string)$verify_response['data']['ItemID'], + 'preview' => (string)$verify_response['data']['link'], + 'i' => $this->request->get['i'], + 'ack' => (string)$verify_response['data']['Ack'], + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + + public function listItem() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('catalog/product'); + $this->load->model('catalog/filter'); + + if ($this->checkConfig() == true && $this->request->server['REQUEST_METHOD'] == 'POST') { + $data = $this->request->post; + + if ($data['template'] != 'None') { + $template = $this->model_extension_openbay_ebay_template->get($data['template']); + $data['template_html'] = (isset($template['html']) ? base64_encode($template['html']) : ''); + } else { + $data['template_html'] = ''; + } + + // set shipping data + $data['national'] = $data['data']['national']; + $data['international'] = $data['data']['international']; + unset($data['data']); + + if (!empty($data['img_tpl'])) { + $tmp_gallery_array = array(); + $tmp_thumbnail_array = array(); + $this->load->model('tool/image'); + + foreach ($data['img_tpl'] as $k => $v) { + $tmp_gallery_array[$k] = $this->model_extension_openbay_openbay->storeImage($v, $data['gallery_width'], $data['gallery_height'], 'ebay'); + $tmp_thumbnail_array[$k] = $this->model_extension_openbay_openbay->storeImage($v, $data['thumb_width'], $data['thumb_height'], 'ebay'); + } + + $data['img_tpl'] = $tmp_gallery_array; + $data['img_tpl_thumb'] = $tmp_thumbnail_array; + } + + $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$data['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $data['product_info'] = $query->row; + + $data['product_info']['product_filters'] = array(); + + $filters = $this->model_catalog_product->getProductFilters($this->request->post['product_id']); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_info']['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'group' => $filter_info['group'], + 'name' => $filter_info['name'] + ); + } + } + + if (!empty($data['product_info']['sku'])){ + $data['sku'] = $data['product_info']['sku']; + } + + $json = $this->model_extension_openbay_ebay->ebayAddItem($data, $this->request->get['options']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + + public function listItemBulk() { + $this->load->model('extension/openbay/openbay'); + $this->load->model('extension/openbay/ebay_profile'); + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + $this->load->model('catalog/filter'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + if ($this->checkConfig() == true) { + $post = $this->request->post; + $data = array(); + + //load all of the listing defaults and assign to correct variable names + $profile_shipping = $this->model_extension_openbay_ebay_profile->get($post['shipping_profile']); + $profile_return = $this->model_extension_openbay_ebay_profile->get($post['return_profile']); + $profile_template = $this->model_extension_openbay_ebay_profile->get($post['theme_profile']); + $profile_generic = $this->model_extension_openbay_ebay_profile->get($post['generic_profile']); + $payments = $this->model_extension_openbay_ebay->getPaymentTypes(); + $payments_accepted = $this->config->get('ebay_payment_types'); + $product_info = $this->model_catalog_product->getProduct($post['product_id']); + + // set shipping data + $data['national'] = $profile_shipping['data']['national']; + $data['international'] = $profile_shipping['data']['international']; + + $query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, p.sort_order FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$post['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "'"); + + $data['product_info'] = $query->row; + + $data['product_info']['product_filters'] = array(); + + $filters = $this->model_catalog_product->getProductFilters($this->request->post['product_id']); + + foreach ($filters as $filter_id) { + $filter_info = $this->model_catalog_filter->getFilter($filter_id); + + if ($filter_info) { + $data['product_info']['product_filters'][] = array( + 'filter_id' => $filter_info['filter_id'], + 'group' => $filter_info['group'], + 'name' => $filter_info['name'] + ); + } + } + + $data['description'] = $product_info['description']; + $data['name'] = $post['title']; + $data['sub_name'] = ''; + $data['bestoffer'] = 0; + $data['finalCat'] = $post['finalCat']; + $data['price'][0] = $post['price']; + $data['qty'][0] = $post['qty']; + $data['product_id'] = $post['product_id']; + + $data['feat'] = $post['feat']; + $data['featother'] = $post['featother']; + + if (!empty($product_info['sku'])){ + $data['sku'] = $product_info['sku']; + } + + if (isset($post['identifier_ean']) && !empty($post['identifier_ean'])){ + $data['identifier_ean'] = $post['identifier_ean']; + } + + if (isset($post['identifier_isbn']) && !empty($post['identifier_isbn'])){ + $data['identifier_isbn'] = $post['identifier_isbn']; + } + + if (isset($post['identifier_upc']) && !empty($post['identifier_upc'])){ + $data['identifier_upc'] = $post['identifier_upc']; + } + + $data['auction_duration'] = $post['duration']; + $data['condition'] = (isset($post['condition']) && $post['condition'] != 0 ? $post['condition'] : ''); + $data['auction_type'] = 'FixedPriceItem'; + $data['catalog_epid'] = (isset($post['catalog_epid']) && $post['catalog_epid'] != 0 ? $post['catalog_epid'] : ''); + $data['identifier_upc'] = (isset($post['identifier_upc']) && $post['identifier_upc'] != '' ? $post['identifier_upc'] : ''); + $data['identifier_isbn'] = (isset($post['identifier_isbn']) && $post['identifier_isbn'] != '' ? $post['identifier_isbn'] : ''); + $data['identifier_ean'] = (isset($post['identifier_ean']) && $post['identifier_ean'] != '' ? $post['identifier_ean'] : ''); + + $data['ebay_payment_immediate'] = $this->config->get('ebay_payment_immediate'); + $data['paypal_email'] = $this->config->get('ebay_payment_paypal_address'); + $data['payment_instruction'] = $this->config->get('ebay_payment_instruction'); + + if (isset($profile_return['data']['returns_accepted'])) { + $data['returns_accepted'] = $profile_return['data']['returns_accepted']; + } + if (isset($profile_return['data']['returns_policy'])) { + $data['return_policy'] = $profile_return['data']['returns_policy']; + } + if (isset($profile_return['data']['returns_option'])) { + $data['returns_option'] = $profile_return['data']['returns_option']; + } + if (isset($profile_return['data']['returns_within'])) { + $data['returns_within'] = $profile_return['data']['returns_within']; + } + if (isset($profile_return['data']['returns_shipping'])) { + $data['returns_shipping'] = $profile_return['data']['returns_shipping']; + } + if (isset($profile_return['data']['returns_restocking_fee'])) { + $data['returns_restocking_fee'] = $profile_return['data']['returns_restocking_fee']; + } + + $data['location'] = $profile_shipping['data']['location']; + $data['postcode'] = $profile_shipping['data']['postcode']; + $data['dispatch_time'] = $profile_shipping['data']['dispatch_time']; + + if (isset($profile_shipping['data']['country'])) { + $data['country'] = $profile_shipping['data']['country']; + } + + if (isset($profile_shipping['data']['eligible_for_pickup_dropoff'])) { + $data['eligible_for_pickup_dropoff'] = $profile_shipping['data']['eligible_for_pickup_dropoff']; + } + + if (isset($profile_shipping['data']['eligible_for_pickup_instore'])) { + $data['eligible_for_pickup_instore'] = $profile_shipping['data']['eligible_for_pickup_instore']; + } + + if (isset($profile_shipping['data']['global_shipping'])) { + $data['global_shipping'] = $profile_shipping['data']['global_shipping']; + } + + if (isset($profile_shipping['data']['promotional_shipping_discount'])) { + $data['promotional_shipping_discount'] = $profile_shipping['data']['promotional_shipping_discount']; + } + + if (isset($profile_shipping['data']['promotional_shipping_discount_international'])) { + $data['promotional_shipping_discount_international'] = $profile_shipping['data']['promotional_shipping_discount_international']; + } + + $data['get_it_fast'] = (isset($profile_shipping['data']['get_it_fast']) ? $profile_shipping['data']['get_it_fast'] : 0); + + if (isset($profile_template['data']['ebay_template_id'])) { + $template = $this->model_extension_openbay_ebay_template->get($profile_template['data']['ebay_template_id']); + $data['template_html'] = (isset($template['html']) ? base64_encode($template['html']) : ''); + $data['template'] = $profile_template['data']['ebay_template_id']; + } else { + $data['template_html'] = ''; + $data['template'] = ''; + } + + $data['gallery_plus'] = $profile_template['data']['ebay_gallery_plus']; + $data['gallery_super'] = $profile_template['data']['ebay_supersize']; + + $data['private_listing'] = $profile_generic['data']['private_listing']; + + //product attributes - this is just a direct pass through used with the template tag + $data['attributes'] = base64_encode(json_encode($this->model_extension_openbay_ebay->getProductAttributes($post['product_id']))); + + $data['payments'] = array(); + foreach($payments as $payment) { + if ($payments_accepted[$payment['ebay_name']] == 1) { + $data['payments'][$payment['ebay_name']] = 1; + } + } + + $data['main_image'] = 0; + $data['img'] = array(); + + $product_images = $this->model_catalog_product->getProductImages($post['product_id']); + + $product_info['product_images'] = array(); + + if (!empty($product_info['image'])) { + $data['img'][] = $product_info['image']; + } + + if (isset($profile_template['data']['ebay_img_ebay']) && $profile_template['data']['ebay_img_ebay'] == 1) { + foreach ($product_images as $product_image) { + if ($product_image['image'] && file_exists(DIR_IMAGE . $product_image['image'])) { + $data['img'][] = $product_image['image']; + } + } + } + + if (isset($profile_template['data']['ebay_img_template']) && $profile_template['data']['ebay_img_template'] == 1) { + $tmp_gallery_array = array(); + $tmp_thumbnail_array = array(); + + //if the user has not set the exclude default image, add it to the array for theme images. + $key_offset = 0; + if (!isset($profile_template['data']['default_img_exclude']) || $profile_template['data']['default_img_exclude'] != 1) { + $tmp_gallery_array[0] = $this->model_extension_openbay_openbay->storeImage($product_info['image'], $profile_template['data']['ebay_gallery_width'], $profile_template['data']['ebay_gallery_height'], 'ebay'); + $tmp_thumbnail_array[0] = $this->model_extension_openbay_openbay->storeImage($product_info['image'], $profile_template['data']['ebay_thumb_width'], $profile_template['data']['ebay_thumb_height'], 'ebay'); + $key_offset = 1; + } + + //loop through the product images and add them. + foreach ($product_images as $k => $v) { + $tmp_gallery_array[$k+$key_offset] = $this->model_extension_openbay_openbay->storeImage($v['image'], $profile_template['data']['ebay_gallery_width'], $profile_template['data']['ebay_gallery_height'], 'ebay'); + $tmp_thumbnail_array[$k+$key_offset] = $this->model_extension_openbay_openbay->storeImage($v['image'], $profile_template['data']['ebay_thumb_width'], $profile_template['data']['ebay_thumb_height'], 'ebay'); + } + + $data['img_tpl'] = $tmp_gallery_array; + $data['img_tpl_thumb'] = $tmp_thumbnail_array; + } + + $weight_parts = explode('.', $product_info['weight']); + + // package size and weights + $data['package']['depth'] = $product_info['height']; + $data['package']['irregular'] = 0; + $data['package']['length'] = $product_info['length']; + $data['package']['unit'] = $this->config->get('ebay_measurement'); + $data['package']['weight_major'] = (int)$weight_parts[0]; + $data['package']['weight_minor'] = (int)substr($weight_parts[1], 0, 3); + $data['package']['width'] = $product_info['width']; + + $package_types = $this->openbay->ebay->getSetting('package_type'); + + foreach ($package_types as $package_type) { + if ($package_type['default'] == 1) { + $data['package']['package'] = $package_type['code']; + } + } + + $data = array_merge($data, $profile_shipping['data']); + + $verify_response = $this->model_extension_openbay_ebay->ebayAddItem($data, 'no'); + + $json = array( + 'errors' => $verify_response['data']['Errors'], + 'fees' => $verify_response['data']['Fees'], + 'itemid' => (string)$verify_response['data']['ItemID'], + 'preview' => (string)$verify_response['data']['link'], + 'i' => $this->request->get['i'], + 'ack' => (string)$verify_response['data']['Ack'], + ); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + } else { + $this->response->redirect($this->url->link('marketplace/openbay/items&token=' . $this->session->data['user_token'])); + } + } + + public function repairLinks() { + $this->load->model('extension/openbay/ebay_product'); + + $this->model_extension_openbay_ebay_product->repairLinks(); + + $json = array('msg' => 'Links repaired'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function deleteAllLocks() { + $this->openbay->ebay->log('deleteAllLocks() - Deleting all locks'); + $this->db->query("DELETE FROM `" . DB_PREFIX . "ebay_order_lock`"); + + $json = array('msg' => 'Locks deleted'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function endItem() { + $json = $this->openbay->ebay->endItem($this->request->get['item_id']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getPartsCompatibilityOptions() { + $this->load->model('extension/openbay/ebay_product'); + + $json = $this->model_extension_openbay_ebay_product->getPartsCompatibilityOptions($this->request->get['category_id']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getPartsCompatibilityValues() { + $this->load->model('extension/openbay/ebay_product'); + + $property_filter = array(); + + if (isset($this->request->post['filters']) && !empty($this->request->post['filters'])) { + $post_filters = $this->request->post['filters']; + + foreach ($post_filters as $filter) { + $property_filter[] = array( + 'property_filter_name' => $filter['property_filter_name'], + 'property_filter_value' => $filter['property_filter_value'], + ); + } + } + + $filters = array( + 'category_id' => $this->request->get['category_id'], + 'property_name' => $this->request->get['option_name'], + 'property_filter' => $property_filter, + ); + + $json = $this->model_extension_openbay_ebay_product->getPartsCompatibilityValues($filters); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function getItemRecommendations() { + $this->load->language('extension/openbay/ebay_edit'); + $this->load->model('extension/openbay/ebay_product'); + + if (!isset($this->request->get['item_id']) || empty($this->request->get['item_id'])) { + $json = array( + 'error' => true, + 'msg' => $this->language->get('error_no_item_id'), + ); + } else { + $filters = array(); + + $filters['item_id'] = $this->request->get['item_id']; + + if (isset($this->request->get['recommendation_type'])) { + $filters['recommendation_type'] = $this->request->get['recommendation_type']; + } + + $json = $this->model_extension_openbay_ebay_product->getItemRecommendations($filters); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +} diff --git a/public/admin/controller/extension/openbay/ebay_profile.php b/public/admin/controller/extension/openbay/ebay_profile.php new file mode 100644 index 0000000..082ddb2 --- /dev/null +++ b/public/admin/controller/extension/openbay/ebay_profile.php @@ -0,0 +1,364 @@ +<?php +class ControllerExtensionOpenbayEbayProfile extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/openbay/ebay_profile'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_profile'); + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['add'] = $this->url->link('extension/openbay/ebay_profile/add', 'user_token=' . $this->session->data['user_token'], true); + $data['types'] = $this->model_extension_openbay_ebay_profile->getTypes(); + $data['profiles'] = $this->model_extension_openbay_ebay_profile->getAll(); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_profile_list', $data)); + + } + + public function add() { + $this->load->language('extension/openbay/ebay_profile'); + + $data = $this->language->all(); + + $this->document->setTitle($data['heading_title']); + + $this->load->model('extension/openbay/ebay_profile'); + + if (!isset($this->request->post['step1'])) { + if ($this->request->post && $this->profileValidate()) { + $this->session->data['success'] = $data['text_added']; + + $this->model_extension_openbay_ebay_profile->add($this->request->post); + + $this->response->redirect($this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + $this->form($data); + } + + public function delete() { + $this->load->model('extension/openbay/ebay_profile'); + + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay_profile')) { + $this->error['warning'] = $this->language->get('error_permission'); + } else { + if (isset($this->request->get['ebay_profile_id'])) { + $this->model_extension_openbay_ebay_profile->delete($this->request->get['ebay_profile_id']); + } + } + + $this->response->redirect($this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function edit() { + $this->load->language('extension/openbay/ebay_profile'); + + $data = $this->language->all(); + + $this->document->setTitle($data['heading_title']); + + $this->load->model('extension/openbay/ebay_profile'); + + if ($this->request->post && $this->profileValidate()) { + $this->session->data['success'] = $data['text_updated']; + + $this->model_extension_openbay_ebay_profile->edit($this->request->post['ebay_profile_id'], $this->request->post); + + $this->response->redirect($this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->form($data); + } + + public function form($data) { + $this->load->model('extension/openbay/ebay'); + $this->load->model('extension/openbay/ebay_template'); + + $data['user_token'] = $this->session->data['user_token']; + $data['shipping_international_zones'] = $this->model_extension_openbay_ebay->getShippingLocations(); + $data['templates'] = $this->model_extension_openbay_ebay_template->getAll(); + $data['types'] = $this->model_extension_openbay_ebay_profile->getTypes(); + + $setting = array(); + $setting['returns'] = $this->openbay->ebay->getSetting('returns'); + $setting['dispatch_times'] = $this->openbay->ebay->getSetting('dispatch_time_max'); + $setting['countries'] = $this->openbay->ebay->getSetting('countries'); + $setting['shipping_types'] = $this->openbay->ebay->getSetting('shipping_types'); + $setting['listing_restrictions'] = $this->openbay->ebay->getSetting('listing_restrictions'); + + if (empty($setting['dispatch_times']) || empty($setting['countries']) || empty($setting['returns'])){ + $this->session->data['warning'] = $this->language->get('error_missing_settings'); + $this->response->redirect($this->url->link('extension/openbay/ebay/syncronise', 'user_token=' . $this->session->data['user_token'], true)); + } + + if (is_array($setting['dispatch_times'])) { + ksort($setting['dispatch_times']); + } + if (is_array($setting['countries'])) { + ksort($setting['countries']); + } + + $data['setting'] = $setting; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $profile_info = array(); + if (isset($this->request->get['ebay_profile_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $profile_info = $this->model_extension_openbay_ebay_profile->get($this->request->get['ebay_profile_id']); + $data['text_manage'] = $this->language->get('text_edit'); + $data['action'] = $this->url->link('extension/openbay/ebay_profile/edit', 'user_token=' . $this->session->data['user_token'], true); + } else { + $data['action'] = $this->url->link('extension/openbay/ebay_profile/add', 'user_token=' . $this->session->data['user_token'], true); + $data['text_manage'] = $this->language->get('text_add'); + } + + $data['cancel'] = $this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['type'])) { + $type = $this->request->post['type']; + } else { + $type = $profile_info['type']; + } + + if (!array_key_exists($type, $data['types'])) { + $this->session->data['error'] = $data['error_no_template']; + + $this->response->redirect($this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay_profile', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title') + ); + + if (isset($this->request->post['default'])) { + $data['default'] = $this->request->post['default']; + } elseif (!empty($profile_info)) { + $data['default'] = $profile_info['default']; + } else { + $data['default'] = 0; + } + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($profile_info)) { + $data['name'] = $profile_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['description'])) { + $data['description'] = $this->request->post['description']; + } elseif (!empty($profile_info)) { + $data['description'] = $profile_info['description']; + } else { + $data['description'] = ''; + } + + if (isset($this->request->post['type'])) { + $data['type'] = $this->request->post['type']; + } else { + $data['type'] = $profile_info['type']; + } + + if (isset($this->request->get['ebay_profile_id'])) { + $data['ebay_profile_id'] = $this->request->get['ebay_profile_id']; + } else { + $data['ebay_profile_id'] = ''; + } + + if (isset($this->request->post['data'])) { + $data['data'] = $this->request->post['data']; + } elseif (!empty($profile_info)) { + $data['data'] = $profile_info['data']; + } else { + $data['data'] = array(); + } + + if ($type == 0) { + $data['zones'] = $this->model_extension_openbay_ebay->getShippingLocations(); + + $data['data']['national']['calculated']['types'] = $this->model_extension_openbay_ebay->getShippingService(0, 'calculated'); + $data['data']['national']['flat']['types'] = $this->model_extension_openbay_ebay->getShippingService(0, 'flat'); + $data['data']['international']['calculated']['types'] = $this->model_extension_openbay_ebay->getShippingService(1, 'calculated'); + $data['data']['international']['flat']['types'] = $this->model_extension_openbay_ebay->getShippingService(1, 'flat'); + + $data['data']['national']['calculated']['count'] = isset($data['data']['national']['calculated']['service_id']) ? max(array_keys($data['data']['national']['calculated']['service_id']))+1 : 0; + $data['data']['national']['flat']['count'] = isset($data['data']['national']['flat']['service_id']) ? max(array_keys($data['data']['national']['flat']['service_id']))+1 : 0; + $data['data']['international']['calculated']['count'] = isset($data['data']['international']['calculated']['service_id']) ? max(array_keys($data['data']['international']['calculated']['service_id']))+1 : 0; + $data['data']['international']['flat']['count'] = isset($data['data']['international']['flat']['service_id']) ? max(array_keys($data['data']['international']['flat']['service_id']))+1 : 0; + + $payment_types = $this->model_extension_openbay_ebay->getPaymentTypes(); + $data['cod_surcharge'] = 0; + + foreach($payment_types as $payment) { + if ($payment['ebay_name'] == 'COD') { + $data['cod_surcharge'] = 1; + } + } + + if (!isset($data['data']['national']['shipping_type'])) { + $data['data']['national']['shipping_type'] = 'flat'; + } + + if (!isset($data['data']['international']['shipping_type'])) { + $data['data']['international']['shipping_type'] = 'flat'; + } + + $data['html_national_flat'] = $this->load->view('extension/openbay/ebay_profile_shipping_national_flat', $data); + $data['html_international_flat'] = $this->load->view('extension/openbay/ebay_profile_shipping_international_flat', $data); + $data['html_national_calculated'] = $this->load->view('extension/openbay/ebay_profile_shipping_national_calculated', $data); + $data['html_international_calculated'] = $this->load->view('extension/openbay/ebay_profile_shipping_international_calculated', $data); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view($data['types'][$type]['template'], $data)); + } + + public function get() { + $this->load->model('extension/openbay/ebay_profile'); + $this->load->model('extension/openbay/ebay'); + $this->load->language('extension/openbay/ebay_profile'); + + $profile_info = $this->model_extension_openbay_ebay_profile->get($this->request->get['ebay_profile_id']); + $data = array(); + + if ($profile_info['type'] == 0) { + $data['data'] = $profile_info['data']; + $data['data']['national']['calculated']['types'] = $this->model_extension_openbay_ebay->getShippingService(0, 'calculated'); + $data['data']['international']['calculated']['types'] = $this->model_extension_openbay_ebay->getShippingService(1, 'calculated'); + $data['data']['national']['flat']['types'] = $this->model_extension_openbay_ebay->getShippingService(0, 'flat'); + $data['data']['international']['flat']['types'] = $this->model_extension_openbay_ebay->getShippingService(1, 'flat'); + + $data['data']['national']['calculated']['count'] = isset($data['data']['national']['calculated']['service_id']) ? max(array_keys($data['data']['national']['calculated']['service_id']))+1 : 0; + $data['data']['national']['flat']['count'] = isset($data['data']['national']['flat']['service_id']) ? max(array_keys($data['data']['national']['flat']['service_id']))+1 : 0; + $data['data']['international']['calculated']['count'] = isset($data['data']['international']['calculated']['service_id']) ? max(array_keys($data['data']['international']['calculated']['service_id']))+1 : 0; + $data['data']['international']['flat']['count'] = isset($data['data']['international']['flat']['service_id']) ? max(array_keys($data['data']['international']['flat']['service_id']))+1 : 0; + + $data['zones'] = $this->model_extension_openbay_ebay->getShippingLocations(); + + $data['text_shipping_service'] = $this->language->get('text_shipping_service'); + $data['text_shipping_first'] = $this->language->get('text_shipping_first'); + $data['button_delete'] = $this->language->get('button_delete'); + $data['text_shipping_zones'] = $this->language->get('text_shipping_zones'); + $data['text_shipping_worldwide'] = $this->language->get('text_shipping_worldwide'); + $data['text_shipping_add'] = $this->language->get('text_shipping_add'); + $data['text_cod_surcharge'] = $this->language->get('text_cod_surcharge'); + + $payment_types = $this->model_extension_openbay_ebay->getPaymentTypes(); + $data['cod_surcharge'] = 0; + + if (!empty($payment_types)) { + foreach($payment_types as $payment) { + if ($payment['ebay_name'] == 'COD') { + $data['cod_surcharge'] = 1; + } + } + } + $return['national']['type'] = $data['data']['national']['shipping_type']; + $return['international']['type'] = $data['data']['international']['shipping_type']; + + $return['national_flat_count'] = (int)$data['data']['national']['flat']['count']; + $return['national_flat'] = $this->load->view('extension/openbay/ebay_profile_shipping_national_flat', $data); + + $return['international_flat_count'] = (int)$data['data']['international']['flat']['count']; + $return['international_flat'] = $this->load->view('extension/openbay/ebay_profile_shipping_international_flat', $data); + + $return['national_calculated_count'] = (int)$data['data']['national']['calculated']['count']; + $return['national_calculated'] = $this->load->view('extension/openbay/ebay_profile_shipping_national_calculated', $data); + + $return['international_calculated_count'] = (int)$data['data']['international']['flat']['count']; + $return['international_calculated'] = $this->load->view('extension/openbay/ebay_profile_shipping_international_calculated', $data); + + $profile_info['html'] = $return; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($profile_info)); + } + + private function profileValidate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay_profile')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ($this->request->post['name'] == '') { + $this->error['name'] = $this->language->get('error_name'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/openbay/ebay_template.php b/public/admin/controller/extension/openbay/ebay_template.php new file mode 100644 index 0000000..131ac14 --- /dev/null +++ b/public/admin/controller/extension/openbay/ebay_template.php @@ -0,0 +1,216 @@ +<?php +class ControllerExtensionOpenbayEbayTemplate extends Controller { + private $error = array(); + + public function listAll() { + $this->load->language('extension/openbay/ebay_template'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_template'); + + $this->document->setTitle($data['heading_title']); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['add'] = $this->url->link('extension/openbay/ebay_template/add', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true); + + $data['templates'] = $this->model_extension_openbay_ebay_template->getAll(); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_ebay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_template_list', $data)); + } + + public function add() { + $this->load->language('extension/openbay/ebay_template'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_template'); + + $data['page_title'] = $data['heading_title']; + $data['btn_save'] = $this->url->link('extension/openbay/ebay_template/add', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true); + + if ($this->request->post && $this->templateValidate()) { + $this->session->data['success'] = $data['text_added']; + + $this->model_extension_openbay_ebay_template->add($this->request->post); + + $this->response->redirect($this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->templateForm($data); + } + + public function delete() { + $this->load->language('extension/openbay/ebay_template'); + $this->load->model('extension/openbay/ebay_template'); + + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay_template')) { + $this->error['warning'] = $this->language->get('error_permission'); + } else { + if (isset($this->request->get['template_id'])) { + $this->model_extension_openbay_ebay_template->delete($this->request->get['template_id']); + + $this->session->data['success'] = $this->language->get('text_deleted'); + } + } + $this->response->redirect($this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function edit() { + $this->load->language('extension/openbay/ebay_template'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/ebay_template'); + + $this->document->setTitle($data['heading_title']); + + $data['btn_save'] = $this->url->link('extension/openbay/ebay_template/edit', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true); + + if ($this->request->post && $this->templateValidate()) { + + $this->session->data['success'] = $data['text_updated']; + + $this->model_extension_openbay_ebay_template->edit($this->request->post['template_id'], $this->request->post); + + $this->response->redirect($this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->templateForm($data); + } + + public function templateForm($data) { + $this->load->model('extension/openbay/ebay'); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->request->get['template_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $template_info = $this->model_extension_openbay_ebay_template->get($this->request->get['template_id']); + $data['text_manage'] = $this->language->get('text_edit'); + } else { + $data['text_manage'] = $this->language->get('text_add'); + } + + $this->document->setTitle($data['heading_title']); + + $this->document->addStyle('view/javascript/codemirror/lib/codemirror.css'); + $this->document->addStyle('view/javascript/codemirror/theme/monokai.css'); + $this->document->addScript('view/javascript/codemirror/lib/codemirror.js'); + $this->document->addScript('view/javascript/codemirror/lib/formatting.js'); + $this->document->addScript('view/javascript/codemirror/lib/xml.js'); + + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => 'OpenBay Pro', + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => 'eBay', + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/ebay_template/listAll', 'user_token=' . $this->session->data['user_token'], true), + 'text' => 'Profiles', + ); + + if (isset($this->request->post['name'])) { + $data['name'] = $this->request->post['name']; + } elseif (!empty($template_info)) { + $data['name'] = $template_info['name']; + } else { + $data['name'] = ''; + } + + if (isset($this->request->post['html'])) { + $data['html'] = $this->request->post['html']; + } elseif (!empty($template_info)) { + $data['html'] = $template_info['html']; + } else { + $data['html'] = ''; + } + + if (isset($this->request->get['template_id'])) { + $data['template_id'] = $this->request->get['template_id']; + } else { + $data['template_id'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/ebay_template_form', $data)); + } + + private function templateValidate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/ebay_template')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ($this->request->post['name'] == '') { + $this->error['warning'] = $this->language->get('error_name'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/openbay/etsy.php b/public/admin/controller/extension/openbay/etsy.php new file mode 100644 index 0000000..125dae6 --- /dev/null +++ b/public/admin/controller/extension/openbay/etsy.php @@ -0,0 +1,233 @@ +<?php +class ControllerExtensionOpenbayEtsy extends Controller { + public function install() { + $this->load->language('extension/openbay/etsy'); + $this->load->model('extension/openbay/etsy'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_product'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_product'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_shipping'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_shipping'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/etsy_shop'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/etsy_shop'); + + $this->model_extension_openbay_etsy->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/etsy'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_etsy->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->language('extension/openbay/etsy'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + $data['validation'] = $this->openbay->etsy->validate(); + $data['links_settings'] = $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['links_products'] = $this->url->link('extension/openbay/etsy_product/links', 'user_token=' . $this->session->data['user_token'], true); + $data['links_listings'] = $this->url->link('extension/openbay/etsy_product/listings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/etsy/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=etsy'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy', $data)); + } + + public function settings() { + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/etsy'); + $this->load->model('localisation/order_status'); + + $this->load->language('extension/openbay/etsy_settings'); + + $data = $this->language->all(); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { + $this->model_setting_setting->editSetting('etsy', $this->request->post); + + $this->openbay->etsy->resetConfig($this->request->post['etsy_token'], $this->request->post['etsy_encryption_key']); + + $account_info = $this->model_extension_openbay_etsy->verifyAccount(); + + if (isset($account_info['header_code']) && $account_info['header_code'] == 200) { + $this->openbay->etsy->settingsUpdate(); + + $this->session->data['success'] = $this->language->get('text_success'); + } else { + $this->session->data['error'] = $this->language->get('error_account_info'); + } + + $this->response->redirect($this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['action'] = $this->url->link('extension/openbay/etsy/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true); + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->request->post['etsy_status'])) { + $data['etsy_status'] = $this->request->post['etsy_status']; + } else { + $data['etsy_status'] = $this->config->get('etsy_status'); + } + + if (isset($this->request->post['etsy_token'])) { + $data['etsy_token'] = $this->request->post['etsy_token']; + } else { + $data['etsy_token'] = $this->config->get('etsy_token'); + } + + if (isset($this->request->post['etsy_encryption_key'])) { + $data['etsy_encryption_key'] = $this->request->post['etsy_encryption_key']; + } else { + $data['etsy_encryption_key'] = $this->config->get('etsy_encryption_key'); + } + + if (isset($this->request->post['etsy_encryption_iv'])) { + $data['etsy_encryption_iv'] = $this->request->post['etsy_encryption_iv']; + } else { + $data['etsy_encryption_iv'] = $this->config->get('etsy_encryption_iv'); + } + + if (isset($this->request->post['etsy_address_format'])) { + $data['etsy_address_format'] = $this->request->post['etsy_address_format']; + } else { + $data['etsy_address_format'] = $this->config->get('etsy_address_format'); + } + + if (isset($this->request->post['etsy_order_status_new'])) { + $data['etsy_order_status_new'] = $this->request->post['etsy_order_status_new']; + } else { + $data['etsy_order_status_new'] = $this->config->get('etsy_order_status_new'); + } + + if (isset($this->request->post['etsy_order_status_paid'])) { + $data['etsy_order_status_paid'] = $this->request->post['etsy_order_status_paid']; + } else { + $data['etsy_order_status_paid'] = $this->config->get('etsy_order_status_paid'); + } + + if (isset($this->request->post['etsy_order_status_shipped'])) { + $data['etsy_order_status_shipped'] = $this->request->post['etsy_order_status_shipped']; + } else { + $data['etsy_order_status_shipped'] = $this->config->get('etsy_order_status_shipped'); + } + + if (isset($this->request->post['etsy_logging'])) { + $data['etsy_logging'] = $this->request->post['etsy_logging']; + } else { + $data['etsy_logging'] = $this->config->get('etsy_logging'); + } + + $data['api_server'] = $this->openbay->etsy->getServer(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['account_info'] = $this->model_extension_openbay_etsy->verifyAccount(); + $data['link_signup'] = 'https://account.openbaypro.com/etsy/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=etsy'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_settings', $data)); + } + + public function settingsUpdate() { + $this->openbay->etsy->settingsUpdate(); + + $response = array('header_code' => 200); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + public function getOrders() { + $response = $this->openbay->etsy->call('v1/etsy/order/get/all/', 'GET'); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/etsy')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/openbay/etsy_product.php b/public/admin/controller/extension/openbay/etsy_product.php new file mode 100644 index 0000000..c1076da --- /dev/null +++ b/public/admin/controller/extension/openbay/etsy_product.php @@ -0,0 +1,761 @@ +<?php +class ControllerExtensionOpenbayEtsyProduct extends Controller { + private $error; + + public function create() { + $this->load->language('extension/openbay/etsy_create'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('catalog/product'); + $this->load->model('tool/image'); + + $data['action'] = $this->url->link('extension/openbay/etsy_product/create', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy_product/create', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']); + + $this->load->model('tool/image'); + + if (!empty($product_info) && is_file(DIR_IMAGE . $product_info['image'])) { + $product_info['image_url'] = $this->model_tool_image->resize($product_info['image'], 800, 800); + $product_info['thumb'] = $this->model_tool_image->resize($product_info['image'], 100, 100); + } else { + $product_info['image_url'] = ''; + $product_info['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100); + } + + // Images + if (isset($this->request->get['product_id'])) { + $product_images = $this->model_catalog_product->getProductImages($this->request->get['product_id']); + } else { + $product_images = array(); + } + + $data['product_images'] = array(); + + foreach ($product_images as $product_image) { + if (is_file(DIR_IMAGE . $product_image['image'])) { + $image = $product_image['image']; + } else { + $image = ''; + } + + $product_info['product_images'][] = array( + 'image_url' => $this->model_tool_image->resize($image, 800, 800), + 'thumb' => $this->model_tool_image->resize($image, 100, 100), + 'sort_order' => $product_image['sort_order'] + ); + } + + $data['product'] = $product_info; + $data['product']['description_raw'] = trim(strip_tags(html_entity_decode($data['product']['description'], ENT_QUOTES, 'UTF-8'))); + + $setting = array(); + + $setting['who_made'] = $this->openbay->etsy->getSetting('who_made'); + if (is_array($setting['who_made'])) { + ksort($setting['who_made']); + } + + $setting['when_made'] = $this->openbay->etsy->getSetting('when_made'); + if (is_array($setting['when_made'])) { + ksort($setting['when_made']); + } + + $setting['recipient'] = $this->openbay->etsy->getSetting('recipient'); + if (is_array($setting['recipient'])) { + ksort($setting['recipient']); + } + + $setting['occasion'] = $this->openbay->etsy->getSetting('occasion'); + if (is_array($setting['occasion'])) { + ksort($setting['occasion']); + } + + $setting['state'] = array('active', 'draft'); + + $data['setting'] = $setting; + + if ($product_info['quantity'] > 999) { + $this->error['warning'] = sprintf($this->language->get('error_stock_max'), $product_info['quantity']); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if ($this->openbay->addonLoad('openstock') && $product_info['has_option'] == 1) { + $data['error_variant'] = $this->language->get('error_variant'); + } else { + $data['error_variant'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_create', $data)); + } + + public function createSubmit() { + $this->load->language('extension/openbay/etsy_create'); + $this->load->model('extension/openbay/etsy_product'); + + $data = $this->request->post; + + // validation + if (!isset($data['title']) || empty($data['title']) || strlen($data['title']) > 255) { + if (strlen($data['title']) > 255) { + $this->error['title'] = $this->language->get('error_title_length'); + } else { + $this->error['title'] = $this->language->get('error_title_missing'); + } + } + + if (!isset($data['description']) || empty($data['description'])) { + $this->error['title'] = $this->language->get('error_desc_missing'); + } + + if (!isset($data['price']) || empty($data['price'])) { + $this->error['price'] = $this->language->get('error_price_missing'); + } + + if (!isset($data['taxonomy_id']) || empty($data['taxonomy_id']) || $data['taxonomy_id'] == 0) { + $this->error['taxonomy_id'] = $this->language->get('error_category'); + } + + if (isset($data['tags']) && count($data['tags']) > 13) { + $this->error['tags'] = $this->language->get('error_tags'); + } + + if (isset($data['materials']) && count($data['materials']) > 13) { + $this->error['materials'] = $this->language->get('error_materials'); + } + + if (isset($data['style_1']) && !empty($data['style_1'])) { + if (preg_match('/[^\p{L}\p{Nd}\p{Zs}]/u', $data['style_1']) == 1) { + $this->error['style_1'] = $this->language->get('error_style_1_tag'); + } + } + + if (isset($data['style_2']) && !empty($data['style_2'])) { + if (preg_match('/[^\p{L}\p{Nd}\p{Zs}]/u', $data['style_2']) == 1) { + $this->error['style_2'] = $this->language->get('error_style_2_tag'); + } + } + + if ($data['quantity'] > 999) { + $this->error['quantity'] = sprintf($this->language->get('error_stock_max'), $data['quantity']); + } + + if (isset($data['product_image']) && count($data['product_image']) > 4) { + $this->error['images'] = sprintf($this->language->get('error_image_max'), count($data['product_image'])+1); + } + + if (!$this->error) { + // process the request + $response = $this->openbay->etsy->call('v1/etsy/product/listing/create/', 'POST', $data); + + $this->response->addHeader('Content-Type: application/json'); + + if (isset($response['data']['results'][0]['listing_id'])) { + $this->model_extension_openbay_etsy_product->addLink($data['product_id'], $response['data']['results'][0]['listing_id'], 1); + } + + if (isset($response['data']['error'])) { + $this->response->setOutput(json_encode($response['data'])); + } else { + $this->response->setOutput(json_encode($response['data']['results'][0])); + } + } else { + $this->response->setOutput(json_encode(array('error' => $this->error))); + } + } + + public function edit() { + $this->load->language('extension/openbay/etsy_edit'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/etsy_product'); + $this->load->model('tool/image'); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['action'] = $this->url->link('extension/openbay/etsy_product/editSubmit', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy_product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $this->request->get['product_id'], true), + 'text' => $this->language->get('heading_title'), + ); + + $links = $this->openbay->etsy->getLinks($this->request->get['product_id'], 1, 1); + + $data['listing'] = $this->openbay->etsy->getEtsyItem($links[0]['etsy_item_id']); + + $data['etsy_item_id'] = $links[0]['etsy_item_id']; + $data['product_id'] = $this->request->get['product_id']; + + $setting['state'] = array('active', 'inactive', 'draft'); + + $data['setting'] = $setting; + + if ($data['listing']['state'] == 'edit') { + $data['listing']['state'] = 'inactive'; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_edit', $data)); + } + + public function editSubmit() { + $this->load->language('extension/openbay/etsy_edit'); + $this->load->model('extension/openbay/etsy_product'); + + $data = $this->request->post; + + // validation + if (!isset($data['title']) || empty($data['title']) || strlen($data['title']) > 255) { + if (strlen($data['title']) > 255) { + $this->error['title'] = $this->language->get('error_title_length'); + } else { + $this->error['title'] = $this->language->get('error_title_missing'); + } + } + + if (!isset($data['description']) || empty($data['description'])) { + $this->error['title'] = $this->language->get('error_desc_missing'); + } + + if (!isset($data['price']) || empty($data['price'])) { + $this->error['price'] = $this->language->get('error_price_missing'); + } + + if (!isset($data['state']) || empty($data['state'])) { + $this->error['state'] = $this->language->get('error_state_missing'); + } + + if (!$this->error) { + // process the request + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . $data['etsy_item_id'] . '/update/', 'POST', $data); + + $this->response->addHeader('Content-Type: application/json'); + + if (isset($response['data']['error'])) { + $this->response->setOutput(json_encode($response['data'])); + } else { + $this->response->setOutput(json_encode($response['data']['results'][0])); + } + } else { + $this->response->setOutput(json_encode(array('error' => $this->error))); + } + } + + public function addImage() { + $this->load->language('extension/openbay/etsy_create'); + + $data = $this->request->post; + + if (!isset($data['image']) || empty($data['image'])) { + $this->error['image'] = $this->language->get('error_no_img_url'); + } + + if (!isset($data['listing_id']) || empty($data['listing_id'])) { + $this->error['listing_id'] = $this->language->get('error_no_listing_id'); + } + + if (!$this->error) { + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . (int)$data['listing_id'] . '/image/', 'POST', $data); + + $this->response->addHeader('Content-Type: application/json'); + + if (isset($response['data']['error'])) { + $this->response->setOutput(json_encode($response['data'])); + } else { + $this->response->setOutput(json_encode($response['data']['results'][0])); + } + } + } + + public function getCategories() { + $categories = $this->cache->get('etsy_categories'); + + if (!$categories) { + $response = $this->openbay->etsy->call('v1/etsy/product/taxonomy/', 'GET'); + + if (isset($response['header_code']) && $response['header_code'] == 200) { + $categories = $this->formatCategories($response['data']['data']['results']); + + /** + * Need to create cache instance here due to bug where all caches expire after 3600 seconds. + **/ + $etsy_cache = new Cache('file', 3000000); + + $etsy_cache->set('etsy_categories', $categories); + } + } + + $response = array(); + $parent_categories = array(); + $last_id = 0; + + if (isset($this->request->get['id_path']) && $this->request->get['id_path'] != '' && $this->request->get['id_path'] != 0) { + $id_path_parts = explode(',', $this->request->get['id_path']); + + + foreach ($id_path_parts as $id_path) { + $parent_categories[] = $categories[$id_path]['name']; + + $categories = $categories[$id_path]['children']; + + $last_id = $id_path; + } + } + + if (empty($categories)) { + $final_category = true; + } else { + foreach ($categories as $id => $category) { + $response[$id] = array( + 'name' => $category['name'], + 'id_path' => $category['id_path'], + 'children_count' => (is_array($category['children']) ? count($category['children']) : 0), + ); + } + + $final_category = false; + } + + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('data' => $response, 'parent_text' => implode(' > ', $parent_categories), 'final_category' => $final_category, 'last_id' => $last_id))); + } + + private function formatCategories($category_data) { + $response = array(); + + foreach ($category_data as $category) { + $response[$category['id']] = array( + 'name' => $category['name'], + 'id_path' => implode(',', $category['full_path_taxonomy_ids']), + 'children' => (isset($category['children']) && !empty($category['children']) ? $this->formatCategories($category['children']) : ''), + ); + } + + return $response; + } + + public function addLink() { + $this->load->language('extension/openbay/etsy_links'); + $this->load->model('extension/openbay/etsy_product'); + $this->load->model('catalog/product'); + + $data = $this->request->post; + + if (!isset($data['product_id'])) { + echo json_encode(array('error' => $this->language->get('error_product_id'))); + die(); + } + + if (!isset($data['etsy_id'])) { + echo json_encode(array('error' => $this->language->get('error_etsy_id'))); + die(); + } + + $links = $this->openbay->etsy->getLinks($data['product_id'], 1); + + if ($links != false) { + echo json_encode(array('error' => $this->language->get('error_link_exists'))); + die(); + } + + $product = $this->model_catalog_product->getProduct($data['product_id']); + + if (!$product) { + echo json_encode(array('error' => $this->language->get('error_product'))); + die(); + } + + if ($product['quantity'] <= 0) { + echo json_encode(array('error' => $this->language->get('error_stock'))); + die(); + } + + // check the etsy item exists + $get_response = $this->openbay->etsy->getEtsyItem($data['etsy_id']); + + if (isset($get_response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $get_response['data']['error'])); + die(); + } else { + if ((int)$get_response['quantity'] != (int)$product['quantity']) { + // if the stock is different than the item being linked update the etsy stock level + $update_response = $this->openbay->etsy->updateListingStock($data['etsy_id'], $product['quantity'], $get_response['state']); + + if (isset($update_response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $update_response['data']['error'])); + die(); + } + } + } + + $this->model_extension_openbay_etsy_product->addLink($data['product_id'], $data['etsy_id'], 1); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false))); + } + + public function deleteLink() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->request->post; + + if (!isset($data['etsy_link_id'])) { + echo json_encode(array('error' => $this->language->get('error_link_id'))); + die(); + } + + $this->openbay->etsy->deleteLink($data['etsy_link_id']); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false))); + } + + public function links() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->language->all(); + + $this->load->model('extension/openbay/etsy_product'); + + $data['cancel'] = $this->url->link('marketplace/openbay/items', 'user_token=' . $this->session->data['user_token'], true); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy_product/itemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['return'] = $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true); + //$data['edit_url'] = $this->url->link('extension/openbay/ebay/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=', true); + //$data['validation'] = $this->openbay->ebay->validate(); + $data['user_token'] = $this->session->data['user_token']; + + $total_linked = $this->model_extension_openbay_etsy_product->totalLinked(); + + if (isset($this->request->get['page'])){ + $page = (int)$this->request->get['page']; + } else { + $page = 1; + } + + $limit = $this->config->get('config_limit_admin'); + + $pagination = new Pagination(); + $pagination->total = $total_linked; + $pagination->page = $page; + $pagination->limit = $limit; + $pagination->text = $this->language->get('text_pagination'); + $pagination->url = $this->url->link('extension/openbay/etsy/itemLinks', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($total_linked) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($total_linked - $limit)) ? $total_linked : ((($page - 1) * $limit) + $limit), $total_linked, ceil($total_linked / $limit)); + + $data['items'] = $this->model_extension_openbay_etsy_product->loadLinked($limit, $page); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_links', $data)); + } + + public function listings() { + $this->load->language('extension/openbay/etsy_listings'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('extension/openbay/etsy_product'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_etsy'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/etsy_product/itemLinks', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $filter = array(); + + if (!isset($this->request->get['status'])) { + $filter['status'] = 'active'; + } else { + $filter['status'] = $this->request->get['status']; + } + + if (!isset($this->request->get['page'])) { + $filter['page'] = 1; + } else { + $filter['page'] = $this->request->get['page']; + } + + if (isset($this->request->get['keywords'])) { + $filter['keywords'] = $this->request->get['keywords']; + } + + $filter['limit'] = (int)$this->config->get('config_limit_admin'); + + $data['filter'] = $filter; + + $response = $this->openbay->etsy->call('v1/etsy/product/listing/all/?' . http_build_query($filter), 'GET'); + + unset($filter['page']); + + if (isset($response['data']['error'])) { + $data['listings'] = array(); + $data['pagination'] = ''; + $data['results'] = ''; + $this->error['warning'] = $this->language->get('error_etsy') . $response['data']['error']; + } else { + $listings = array(); + + foreach($response['data']['results'] as $listing) { + $product_link = $this->openbay->etsy->getLinkedProduct($listing['listing_id']); + + $actions = array(); + + if ($filter['status'] == 'inactive') { + $actions[] = 'activate_item'; + } + + if ($filter['status'] == 'active') { + $actions[] = 'end_item'; + $actions[] = 'deactivate_item'; + } + + if ($filter['status'] == 'active' && empty($product_link)) { + $actions[] = 'add_link'; + } + + if (!empty($product_link)) { + $actions[] = 'delete_link'; + } + + if ($product_link != false) { + $listings[] = array('link' => $product_link, 'listing' => $listing, 'actions' => $actions); + } else { + $listings[] = array('link' => '', 'listing' => $listing, 'actions' => $actions); + } + } + + $data['listings'] = $listings; + + $pagination = new Pagination(); + $pagination->total = $response['data']['count']; + $pagination->page = $response['data']['pagination']['effective_page']; + $pagination->limit = $response['data']['pagination']['effective_limit']; + $pagination->url = $this->url->link('extension/openbay/etsy_product/listings', 'user_token=' . $this->session->data['user_token'] . '&page={page}&' . http_build_query($filter), true); + + $data['pagination'] = $pagination->render(); + $data['results'] = sprintf($this->language->get('text_pagination'), ($response['data']['count']) ? (($response['data']['pagination']['effective_page'] - 1) * $response['data']['pagination']['effective_limit']) + 1 : 0, ((($response['data']['pagination']['effective_page'] - 1) * $response['data']['pagination']['effective_limit']) > ($response['data']['count'] - $response['data']['pagination']['effective_limit'])) ? $response['data']['count'] : ((($response['data']['pagination']['effective_page'] - 1) * $response['data']['pagination']['effective_limit']) + $response['data']['pagination']['effective_limit']), $response['data']['count'], ceil($response['data']['count'] / $response['data']['pagination']['effective_limit'])); + } + + $data['success'] = ''; + + if (isset($this->request->get['item_ended'])) { + $data['success'] = $this->language->get('text_item_ended'); + } + + if (isset($this->request->get['item_activated'])) { + $data['success'] = $this->language->get('text_item_activated'); + } + + if (isset($this->request->get['item_deactivated'])) { + $data['success'] = $this->language->get('text_item_deactivated'); + } + + if (isset($this->request->get['link_added'])) { + $data['success'] = $this->language->get('text_link_added'); + } + + if (isset($this->request->get['link_deleted'])) { + $data['success'] = $this->language->get('text_link_deleted'); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/etsy_listings', $data)); + } + + public function endListing() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->request->post; + + if (!isset($data['etsy_item_id'])) { + echo json_encode(array('error' => $this->language->get('error_etsy_id'))); + die(); + } + + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . (int)$data['etsy_item_id'] . '/delete/', 'POST', array()); + + if (isset($response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $response['data']['error'])); + die(); + } else { + $linked_item = $this->openbay->etsy->getLinkedProduct($data['etsy_item_id']); + + if ($linked_item != false) { + $this->openbay->etsy->deleteLink($linked_item['etsy_listing_id']); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false))); + } + } + + public function deactivateListing() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->request->post; + + if (!isset($data['etsy_item_id'])) { + echo json_encode(array('error' => $this->language->get('error_etsy_id'))); + die(); + } + + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . (int)$data['etsy_item_id'] . '/inactive/', 'POST', array()); + + if (isset($response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $response['data']['error'])); + die(); + } else { + $linked_item = $this->openbay->etsy->getLinkedProduct($data['etsy_item_id']); + + if ($linked_item != false) { + $this->openbay->etsy->deleteLink($linked_item['etsy_listing_id']); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode(array('error' => false))); + } + } + + public function activateListing() { + $this->load->language('extension/openbay/etsy_links'); + + $data = $this->request->post; + + $this->response->addHeader('Content-Type: application/json'); + + if (!isset($data['etsy_item_id'])) { + echo json_encode(array('error' => $this->language->get('error_etsy_id'))); + die(); + } + + $response = $this->openbay->etsy->call('v1/etsy/product/listing/' . (int)$data['etsy_item_id'] . '/active/', 'POST', array()); + + if (isset($response['data']['error'])) { + echo json_encode(array('error' => $this->language->get('error_etsy') . $response['data']['error'])); + die(); + } else { + $this->response->setOutput(json_encode(array('error' => false))); + } + } +} diff --git a/public/admin/controller/extension/openbay/etsy_shipping.php b/public/admin/controller/extension/openbay/etsy_shipping.php new file mode 100644 index 0000000..ecf0fe9 --- /dev/null +++ b/public/admin/controller/extension/openbay/etsy_shipping.php @@ -0,0 +1,9 @@ +<?php +class ControllerExtensionOpenbayEtsyShipping extends Controller { + public function getAll() { + $response = $this->openbay->etsy->call('v1/etsy/product/shipping/getAllTemplates/', 'GET'); + + $this->response->addHeader('Content-Type: application/json'); + return $this->response->setOutput(json_encode($response)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/openbay/etsy_shop.php b/public/admin/controller/extension/openbay/etsy_shop.php new file mode 100644 index 0000000..598edd9 --- /dev/null +++ b/public/admin/controller/extension/openbay/etsy_shop.php @@ -0,0 +1,9 @@ +<?php +class ControllerExtensionOpenbayEtsyShop extends Controller { + public function getSections() { + $response = $this->openbay->etsy->call('v1/etsy/shop/getSections/', 'GET'); + + $this->response->addHeader('Content-Type: application/json'); + return $this->response->setOutput(json_encode($response)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/openbay/fba.php b/public/admin/controller/extension/openbay/fba.php new file mode 100644 index 0000000..660e49b --- /dev/null +++ b/public/admin/controller/extension/openbay/fba.php @@ -0,0 +1,923 @@ +<?php +class ControllerExtensionOpenbayFba extends Controller { + public function install() { + $this->load->model('extension/openbay/fba'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + $this->load->model('user/user_group'); + + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/openbay/fba'); + $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/openbay/fba'); + + $this->model_extension_openbay_fba->install(); + } + + public function uninstall() { + $this->load->model('extension/openbay/fba'); + $this->load->model('setting/setting'); + $this->load->model('setting/extension'); + + $this->model_extension_openbay_fba->uninstall(); + $this->model_setting_extension->uninstall('openbay', $this->request->get['extension']); + $this->model_setting_setting->deleteSetting($this->request->get['extension']); + } + + public function index() { + $this->load->language('extension/openbay/fba'); + + $data = $this->language->all(); + + $this->load->model('setting/setting'); + $this->load->model('localisation/order_status'); + $this->load->model('extension/openbay/fba'); + + $this->document->setTitle($this->language->get('text_dashboard')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_dashboard'), + ); + + $data['success'] = ''; + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['validation'] = $this->openbay->fba->validate(); + $data['link_settings'] = $this->url->link('extension/openbay/fba/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['link_account'] = 'https://account.openbaypro.com/fba/index/'; + $data['link_fulfillments'] = $this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'], true); + $data['link_orders'] = $this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/fba/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=dashboard&utm_campaign=fba'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba', $data)); + } + + public function settings() { + $this->load->language('extension/openbay/fba_settings'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('setting/setting'); + $this->load->model('extension/openbay/fba'); + $this->load->model('localisation/order_status'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { + $this->model_setting_setting->editSetting('openbay_fba', $this->request->post); + $this->session->data['success'] = $this->language->get('text_success'); + $this->response->redirect($this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_fba'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba/settings', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('heading_title'), + ); + + $data['action'] = $this->url->link('extension/openbay/fba/settings', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true); + $data['link_signup'] = 'https://account.openbaypro.com/fba/apiRegister/?endpoint=2&utm_source=opencart_install&utm_medium=settings&utm_campaign=fba'; + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->request->post['openbay_fba_status'])) { + $data['openbay_fba_status'] = $this->request->post['openbay_fba_status']; + } else { + $data['openbay_fba_status'] = $this->config->get('openbay_fba_status'); + } + + if (isset($this->request->post['openbay_fba_api_key'])) { + $data['openbay_fba_api_key'] = trim($this->request->post['openbay_fba_api_key']); + } else { + $data['openbay_fba_api_key'] = trim($this->config->get('openbay_fba_api_key')); + } + + if (isset($this->request->post['openbay_fba_encryption_key'])) { + $data['openbay_fba_encryption_key'] = trim($this->request->post['openbay_fba_encryption_key']); + } else { + $data['openbay_fba_encryption_key'] = trim($this->config->get('openbay_fba_encryption_key')); + } + + if (isset($this->request->post['openbay_fba_encryption_iv'])) { + $data['openbay_fba_encryption_iv'] = trim($this->request->post['openbay_fba_encryption_iv']); + } else { + $data['openbay_fba_encryption_iv'] = trim($this->config->get('openbay_fba_encryption_iv')); + } + + if (isset($this->request->post['openbay_fba_api_account_id'])) { + $data['openbay_fba_api_account_id'] = trim($this->request->post['openbay_fba_api_account_id']); + } else { + $data['openbay_fba_api_account_id'] = trim($this->config->get('openbay_fba_api_account_id')); + } + + if (isset($this->request->post['openbay_fba_send_orders'])) { + $data['openbay_fba_send_orders'] = $this->request->post['openbay_fba_send_orders']; + } else { + $data['openbay_fba_send_orders'] = $this->config->get('openbay_fba_send_orders'); + } + + if (isset($this->request->post['openbay_fba_debug_log'])) { + $data['openbay_fba_debug_log'] = $this->request->post['openbay_fba_debug_log']; + } else { + $data['openbay_fba_debug_log'] = $this->config->get('openbay_fba_debug_log'); + } + + $order_total = $this->model_extension_openbay_fba->countFbaOrders(); + + if ($order_total > 0) { + $data['prefix_can_edit'] = false; + } else { + $data['prefix_can_edit'] = true; + } + + if (isset($this->request->post['openbay_fba_order_prefix'])) { + $data['openbay_fba_order_prefix'] = $this->request->post['openbay_fba_order_prefix']; + } else { + $data['openbay_fba_order_prefix'] = $this->config->get('openbay_fba_order_prefix'); + } + + if (isset($this->request->post['openbay_fba_order_trigger_status'])) { + $data['openbay_fba_order_trigger_status'] = $this->request->post['openbay_fba_order_trigger_status']; + } else { + $data['openbay_fba_order_trigger_status'] = $this->config->get('openbay_fba_order_trigger_status'); + } + + if (isset($this->request->post['openbay_fba_only_fill_complete'])) { + $data['openbay_fba_only_fill_complete'] = $this->request->post['openbay_fba_only_fill_complete']; + } else { + $data['openbay_fba_only_fill_complete'] = $this->config->get('openbay_fba_only_fill_complete'); + } + + $data['fulfillment_policy'] = array( + 'FillOrKill' => $this->language->get('text_fillorkill'), + 'FillAll' => $this->language->get('text_fillall'), + 'FillAllAvailable' => $this->language->get('text_fillallavailable'), + ); + + if (isset($this->request->post['openbay_fba_fulfill_policy'])) { + $data['openbay_fba_fulfill_policy'] = $this->request->post['openbay_fba_fulfill_policy']; + } else { + $data['openbay_fba_fulfill_policy'] = $this->config->get('openbay_fba_fulfill_policy'); + } + + $data['shipping_speed'] = array( + 'Standard' => $this->language->get('text_standard'), + 'Expedited' => $this->language->get('text_expedited'), + 'Priority' => $this->language->get('text_priority'), + ); + + if (isset($this->request->post['openbay_fba_shipping_speed'])) { + $data['openbay_fba_shipping_speed'] = $this->request->post['openbay_fba_shipping_speed']; + } else { + $data['openbay_fba_shipping_speed'] = $this->config->get('openbay_fba_shipping_speed'); + } + + $data['api_server'] = $this->openbay->fba->getServerUrl(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_settings', $data)); + } + + public function verifyCredentials() { + $this->load->language('extension/openbay/fba_settings'); + + $errors = array(); + + if (!isset($this->request->post['openbay_fba_api_key']) || empty($this->request->post['openbay_fba_api_key'])) { + $errors[] = array('message' => $this->language->get('error_api_key')); + } + + if (!isset($this->request->post['openbay_fba_api_account_id']) || empty($this->request->post['openbay_fba_api_account_id'])) { + $errors[] = array('message' => $this->language->get('error_api_account_id')); + } + + if (!isset($this->request->post['openbay_fba_encryption_key']) || empty($this->request->post['openbay_fba_encryption_key'])) { + $errors[] = array('message' => $this->language->get('error_encryption_key')); + } + + if (!isset($this->request->post['openbay_fba_encryption_iv']) || empty($this->request->post['openbay_fba_encryption_iv'])) { + $errors[] = array('message' => $this->language->get('error_encryption_iv')); + } + + if (!$errors) { + $this->openbay->fba->setApiKey($this->request->post['openbay_fba_api_key']); + $this->openbay->fba->setAccountId($this->request->post['openbay_fba_api_account_id']); + $this->openbay->fba->setEncryptionKey($this->request->post['openbay_fba_encryption_key']); + $this->openbay->fba->setEncryptionIv($this->request->post['openbay_fba_encryption_iv']); + + $response = $this->openbay->fba->call("v1/fba/status/", array(), 'GET'); + } else { + $response = array( + "result" => null, + "error" => true, + "error_messages" => $errors, + ); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/openbay/fba')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['openbay_fba_api_key']) { + $this->error['api_key'] = $this->language->get('error_api_key'); + } + + if (!$this->request->post['openbay_fba_api_account_id']) { + $this->error['api_account_id'] = $this->language->get('error_api_account_id'); + } + + return !$this->error; + } + + public function fulfillment() { + $this->load->language('extension/openbay/fba_fulfillment'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + if (!isset($this->request->get['fulfillment_id'])) { + $this->response->redirect($this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'] . (!empty($this->request->get['filter_date']) ? '&filter_date=' . $this->request->get['filter_date'] : ''), true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['text_fba'], + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'] . (!empty($this->request->get['filter_date']) ? '&filter_date=' . $this->request->get['filter_date'] : ''), true), + 'text' => $data['heading_title'], + ); + + $response = $this->openbay->fba->call("v1/fba/fulfillments/" . $this->request->get['fulfillment_id'] . "/", array()); + $data['response'] = $response['body']; + + if ($response['error'] == true || $response['response_http'] != 200) { + $this->session->data['error'] = $this->language->get('error_loading_fulfillment'); + + $this->response->redirect($this->url->link('extension/openbay/fba/fulfillmentlist', 'user_token=' . $this->session->data['user_token'], true)); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_fulfillment_form', $data)); + } + + public function fulfillmentList() { + $this->load->language('extension/openbay/fba_fulfillment_list'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['text_fba'], + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + if (isset($this->request->get['filter_date'])) { + $data['filter_date'] = $this->request->get['filter_date']; + $request_url = "?query_start_date_time=".urlencode($this->request->get['filter_date'] . "T00:00:00Z"); + } else { + $data['filter_date'] = ''; + $request_url = ""; + } + + $data['fulfillments'] = array(); + + $response = $this->openbay->fba->call("v1/fba/fulfillments/".$request_url, array(), 'GET'); + + if (isset($response['body']) && is_array($response['body'])) { + foreach ($response['body'] as $fulfillment_order) { + $data['fulfillments'][] = array( + 'seller_fulfillment_order_id' => $fulfillment_order['seller_fulfillment_order_id'], + 'displayable_order_id' => $fulfillment_order['displayable_order_id'], + 'displayable_order_date_time' => $fulfillment_order['displayable_order_date_time'], + 'shipping_speed_category' => $fulfillment_order['shipping_speed_category'], + 'fulfillment_order_status' => $fulfillment_order['fulfillment_order_status'], + 'edit' => $this->url->link('extension/openbay/fba/fulfillment', 'user_token=' . $this->session->data['user_token'] . '&fulfillment_id=' . $fulfillment_order['seller_fulfillment_order_id'] . (!empty($data['filter_date']) ? '&filter_date=' . $data['filter_date'] : ''), true), + ); + } + } + + $data['cancel'] = $this->url->link('extension/openbay/fba/index', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_fulfillment_list', $data)); + } + + public function shipFulfillment() { + $this->load->language('extension/openbay/fba_fulfillment'); + + $errors = array(); + + if (empty($this->request->get['order_id']) || empty($this->request->get['fba_order_fulfillment_id'])) { + $this->session->data['error'] = $this->language->get('error_missing_id'); + + $this->response->redirect($this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $order_id = (int)$this->request->get['order_id']; + $fba_order_fulfillment_id = (int)$this->request->get['fba_order_fulfillment_id']; + + $this->openbay->fba->log('shipFulfillment request for order ID: ' . $order_id . ', Fulfillment ID: ' . $fba_order_fulfillment_id); + + $fba_fulfillment_id = $this->openbay->fba->createFBAFulfillmentID($order_id, 1); + + $response = $this->openbay->fba->call("v1/fba/fulfillments/" . $this->config->get('openbay_fba_order_prefix') . $order_id . '-' . $fba_order_fulfillment_id . "/ship/", array(), 'GET'); + + + + if (!isset($response['response_http']) || $response['response_http'] != 200) { + /** + * @todo notify the admin about any errors + */ + $errors[] = $this->language->get('error_amazon_request'); + + //$this->openbay->fba->updateFBAOrderStatus($order_id, 1); + } else { + $this->openbay->fba->populateFBAFulfillment(json_encode(array()), json_encode($response), $response['response_http'], $fba_fulfillment_id); + + $this->openbay->fba->updateFBAOrderStatus($order_id, 3); + + $this->session->data['success'] = $this->language->get('text_fulfillment_shipped'); + } + } + + if ($errors) { + $this->session->data['error'] = $errors; + } + + $this->response->redirect($this->url->link('extension/openbay/fba/order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true)); + } + + public function cancelFulfillment() { + $this->load->language('extension/openbay/fba_fulfillment'); + + $errors = array(); + + if (empty($this->request->get['order_id']) || empty($this->request->get['fba_order_fulfillment_id'])) { + $this->session->data['error'] = $this->language->get('error_missing_id'); + + $this->response->redirect($this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $order_id = (int)$this->request->get['order_id']; + $fba_order_fulfillment_id = (int)$this->request->get['fba_order_fulfillment_id']; + + $this->openbay->fba->log('cancelFulfillment request for order ID: ' . $order_id . ', Fulfillment ID: ' . $fba_order_fulfillment_id); + + $fba_fulfillment_id = $this->openbay->fba->createFBAFulfillmentID($order_id, 2); + + $response = $this->openbay->fba->call("v1/fba/fulfillments/" . $this->config->get('openbay_fba_order_prefix') . $order_id . '-' . $fba_order_fulfillment_id . "/cancel/", array(), 'POST'); + + if (!isset($response['response_http']) || $response['response_http'] != 200) { + /** + * @todo notify the admin about any errors + */ + $errors[] = $this->language->get('error_amazon_request'); + } else { + $this->openbay->fba->populateFBAFulfillment(json_encode(array()), json_encode($response), $response['response_http'], $fba_fulfillment_id); + + $this->openbay->fba->updateFBAOrderStatus($order_id, 4); + + $this->session->data['success'] = $this->language->get('text_fulfillment_cancelled'); + } + } + + if ($errors) { + $this->session->data['error'] = $errors; + } + + $this->response->redirect($this->url->link('extension/openbay/fba/order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true)); + } + + public function resendFulfillment() { + $this->load->language('extension/openbay/fba_fulfillment'); + + $errors = array(); + + if (empty($this->request->get['order_id'])) { + $this->session->data['error'] = $this->language->get('error_missing_id'); + + $this->response->redirect($this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $order_id = (int)$this->request->get['order_id']; + + $this->openbay->fba->log('resendFulfillment request for order ID: ' . $order_id); + + $this->load->model('sale/order'); + $this->load->model('catalog/product'); + + $order = $this->model_sale_order->getOrder($order_id); + + if ($order['shipping_method']) { + if ($this->config->get('openbay_fba_order_trigger_status') == $order['order_status_id']) { + $fba_fulfillment_id = $this->openbay->fba->createFBAFulfillmentID($order_id, 1); + + $order_products = $this->model_sale_order->getOrderProducts($order_id); + + $fulfillment_items = array(); + + foreach ($order_products as $order_product) { + $product = $this->model_catalog_product->getProduct($order_product['product_id']); + + if ($product['location'] == 'FBA') { + $fulfillment_items[] = array( + 'seller_sku' => $product['sku'], + 'quantity' => $order_product['quantity'], + 'seller_fulfillment_order_item_id' => $this->config->get('openbay_fba_order_prefix') . $fba_fulfillment_id . '-' . $order_product['order_product_id'], + 'per_unit_declared_value' => array( + 'currency_code' => $order['currency_code'], + 'value' => number_format($order_product['price'], 2) + ), + ); + } + } + + $total_fulfillment_items = count($fulfillment_items); + + if (!empty($fulfillment_items)) { + $request = array(); + + $datetime = new DateTime($order['date_added']); + $request['displayable_order_datetime'] = $datetime->format(DateTime::ISO8601); + + $request['seller_fulfillment_order_id'] = $this->config->get('openbay_fba_order_prefix') . $order_id . '-' . $fba_fulfillment_id; + $request['displayable_order_id'] = $order_id; + $request['displayable_order_comment'] = 'none'; + $request['shipping_speed_category'] = $this->config->get('openbay_fba_shipping_speed'); + $request['fulfillment_action'] = ($this->config->get('openbay_fba_send_orders') == 1 ? 'Ship' : 'Hold'); + $request['fulfillment_policy'] = $this->config->get('openbay_fba_fulfill_policy'); + + $request['destination_address'] = array( + 'name' => $order['shipping_firstname'] . ' ' . $order['shipping_lastname'], + 'line_1' => (!empty($order['shipping_company']) ? $order['shipping_company'] : $order['shipping_address_1']), + 'line_2' => (!empty($order['shipping_company']) ? $order['shipping_address_1'] : $order['shipping_address_2']), + 'line_3' => (!empty($order['shipping_company']) ? $order['shipping_address_2'] : ''), + 'state_or_province_code' => $order['shipping_zone'], + 'city' => $order['shipping_city'], + 'country_code' => $order['shipping_iso_code_2'], + 'postal_code' => $order['shipping_postcode'], + ); + + $request['items'] = $fulfillment_items; + + $response = $this->openbay->fba->call("v1/fba/fulfillments/", $request, 'POST'); + + if ($response['response_http'] != 201) { + /** + * @todo notify the admin about any errors + */ + $errors[] = $this->language->get('error_amazon_request'); + + $this->openbay->fba->updateFBAOrderStatus($order_id, 1); + } else { + if ($this->config->get('openbay_fba_send_orders') == 1) { + $this->openbay->fba->updateFBAOrderStatus($order_id, 3); + } else { + $this->openbay->fba->updateFBAOrderStatus($order_id, 2); + } + + $this->openbay->fba->updateFBAOrderRef($order_id, $this->config->get('openbay_fba_order_prefix') . $order_id . '-' . $fba_fulfillment_id); + + $this->session->data['success'] = $this->language->get('text_fulfillment_sent'); + } + + $this->openbay->fba->populateFBAFulfillment(json_encode($request), json_encode($response), $response['response_http'], $fba_fulfillment_id); + $this->openbay->fba->updateFBAOrderFulfillmentID($order_id, $fba_fulfillment_id); + } else { + $errors[] = $this->language->get('error_no_items'); + } + } + } else { + $errors[] = $this->language->get('error_no_shipping'); + } + } + + if ($errors) { + $this->session->data['error'] = $errors; + } + + $this->response->redirect($this->url->link('extension/openbay/fba/order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true)); + } + + public function orderList() { + $this->load->language('extension/openbay/fba_order'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['text_fba'], + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + $filters = array(); + + $url = ''; + + if (isset($this->request->get['filter_start'])) { + $filters['filter_start'] = $this->request->get['filter_start']; + $data['filter_start'] = $this->request->get['filter_start']; + $url .= "&filter_start=".urlencode($this->request->get['filter_start']); + } else { + $filters['filter_start'] = null; + $data['filter_start'] = null; + } + + if (isset($this->request->get['filter_end'])) { + $filters['filter_end'] = $this->request->get['filter_end']; + $data['filter_end'] = $this->request->get['filter_end']; + $url .= "&filter_end=".urlencode($this->request->get['filter_end']); + } else { + $filters['filter_end'] = null; + $data['filter_end'] = null; + } + + if (isset($this->request->get['filter_status'])) { + $filters['filter_status'] = $this->request->get['filter_status']; + $data['filter_status'] = $this->request->get['filter_status']; + $url .= "&filter_status=".urlencode($this->request->get['filter_status']); + } else { + $filters['filter_status'] = null; + $data['filter_status'] = null; + } + + $data['orders'] = array(); + + $orders = $this->openbay->fba->getFBAOrders($filters); + + if (!empty($orders)) { + foreach ($orders as $order) { + $data['orders'][] = array( + 'order_id' => $order['order_id'], + 'order_link' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order['order_id'] . $url, true), + 'status' => $order['status'], + 'created' => $order['created'], + 'fba_item_count' => $this->openbay->fba->hasOrderFBAItems($order['order_id']), + 'view' => $this->url->link('extension/openbay/fba/order', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order['order_id'] . $url, true) + ); + } + } + + $data['cancel'] = $this->url->link('extension/openbay/fba/index', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['status_options'] = array( + 0 => $this->language->get('text_option_new'), + 1 => $this->language->get('text_option_error'), + 2 => $this->language->get('text_option_held'), + 3 => $this->language->get('text_option_shipped'), + ); + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_order_list', $data)); + } + + public function order() { + $this->load->language('extension/openbay/fba_order'); + + $data = $this->language->all(); + + $this->document->setTitle($this->language->get('heading_title')); + $this->document->addScript('view/javascript/openbay/js/faq.js'); + + $this->load->model('sale/order'); + $this->load->model('catalog/product'); + + if (!isset($this->request->get['order_id'])) { + $this->response->redirect($this->url->link('extension/openbay/fba/orderList', 'user_token=' . $this->session->data['user_token'], true)); + } + + $order_id = (int)$this->request->get['order_id']; + $order_fba = $this->openbay->fba->getFBAOrder($order_id); + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($order_fba['status'] == 2 || $order_fba['status'] == 3 || $order_fba['status'] == 4) { + $data['fulfillment_id'] = $order_fba['fba_order_fulfillment_ref']; + $data['fulfillment_link'] = $this->url->link('extension/openbay/fba/fulfillment', 'user_token=' . $this->session->data['user_token'] . '&fulfillment_id=' . $data['fulfillment_id'], true); + } else { + $data['fulfillment_id'] = ''; + $data['fulfillment_link'] = ''; + } + + $data['fba_order_status'] = $order_fba['status']; + $data['order_id'] = $order_id; + $data['order_link'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true); + $data['resend_link'] = $this->url->link('extension/openbay/fba/resendfulfillment', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id, true); + $data['ship_link'] = $this->url->link('extension/openbay/fba/shipfulfillment', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id . '&fba_order_fulfillment_id=' . $order_fba['fba_order_fulfillment_id'], true); + $data['cancel_link'] = $this->url->link('extension/openbay/fba/cancelfulfillment', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order_id . '&fba_order_fulfillment_id=' . $order_fba['fba_order_fulfillment_id'], true); + + $data['cancel'] = $this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_home'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('marketplace/openbay', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $this->language->get('text_openbay'), + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['text_fba'], + ); + + $data['breadcrumbs'][] = array( + 'href' => $this->url->link('extension/openbay/fba/orderlist', 'user_token=' . $this->session->data['user_token'], true), + 'text' => $data['heading_title'], + ); + + $data['fulfillments'] = array(); + + if (is_array($order_fba['fulfillments'])) { + foreach ($order_fba['fulfillments'] as $fulfillment) { + $response_body = json_decode($fulfillment['response_body'], true); + + $fulfillment_errors = array(); + + if (isset($response_body['error']) && $response_body['error'] == true) { + if (is_array($response_body['error_messages']) && !empty($response_body['error_messages'])) { + $fulfillment_errors = $response_body['error_messages']; + } + } + + $data['fulfillments'][] = array( + 'fba_order_fulfillment_id' => $fulfillment['fba_order_fulfillment_id'], + 'created' => $fulfillment['created'], + 'request_body' => json_decode($fulfillment['request_body']), + 'request_body_output' => print_r(json_decode($fulfillment['request_body']), true), + 'response_body' => json_decode($fulfillment['response_body']), + 'response_body_output' => print_r(json_decode($fulfillment['response_body']), true), + 'response_header_code' => $fulfillment['response_header_code'], + 'errors' => $fulfillment_errors, + 'type' => $fulfillment['type'], + ); + } + } + + // Shipping Address + if ($order_info['shipping_address_format']) { + $format = $order_info['shipping_address_format']; + } else { + $format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}'; + } + + $find = array( + '{firstname}', + '{lastname}', + '{company}', + '{address_1}', + '{address_2}', + '{city}', + '{postcode}', + '{zone}', + '{zone_code}', + '{country}' + ); + + $replace = array( + 'firstname' => $order_info['shipping_firstname'], + 'lastname' => $order_info['shipping_lastname'], + 'company' => $order_info['shipping_company'], + 'address_1' => $order_info['shipping_address_1'], + 'address_2' => $order_info['shipping_address_2'], + 'city' => $order_info['shipping_city'], + 'postcode' => $order_info['shipping_postcode'], + 'zone' => $order_info['shipping_zone'], + 'zone_code' => $order_info['shipping_zone_code'], + 'country' => $order_info['shipping_country'] + ); + + $data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + $data['status_options'] = array( + 0 => $this->language->get('text_option_new'), + 1 => $this->language->get('text_option_error'), + 2 => $this->language->get('text_option_held'), + 3 => $this->language->get('text_option_shipped'), + 4 => $this->language->get('text_option_cancelled'), + ); + + $data['type_options'] = array( + 0 => $this->language->get('text_type_new'), + 1 => $this->language->get('text_type_ship'), + 2 => $this->language->get('text_type_cancel'), + ); + + $data['products'] = array(); + + $products = $this->model_sale_order->getOrderProducts($this->request->get['order_id']); + + foreach ($products as $product) { + $option_data = array(); + + $product_info = $this->model_catalog_product->getProduct($product['product_id']); + + $options = $this->model_sale_order->getOrderOptions($this->request->get['order_id'], $product['order_product_id']); + + foreach ($options as $option) { + if ($option['type'] != 'file') { + $option_data[] = array( + 'name' => $option['name'], + 'value' => $option['value'], + 'type' => $option['type'] + ); + } + } + + $data['products'][] = array( + 'order_product_id' => $product['order_product_id'], + 'product_id' => $product['product_id'], + 'name' => $product['name'], + 'sku' => $product_info['sku'], + 'option' => $option_data, + 'quantity' => $product['quantity'], + 'fba' => ($product_info['location'] == 'FBA' ? 1 : 0), + 'href' => $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true), + ); + } + + if (isset($this->session->data['error'])) { + $data['error_warning'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/openbay/fba_order_info', $data)); + } +} diff --git a/public/admin/controller/extension/payment/alipay.php b/public/admin/controller/extension/payment/alipay.php new file mode 100644 index 0000000..ce549b1 --- /dev/null +++ b/public/admin/controller/extension/payment/alipay.php @@ -0,0 +1,153 @@ +<?php +class ControllerExtensionPaymentAlipay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/alipay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_alipay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['app_id'])) { + $data['error_app_id'] = $this->error['app_id']; + } else { + $data['error_app_id'] = ''; + } + + if (isset($this->error['merchant_private_key'])) { + $data['error_merchant_private_key'] = $this->error['merchant_private_key']; + } else { + $data['error_merchant_private_key'] = ''; + } + + if (isset($this->error['alipay_public_key'])) { + $data['error_alipay_public_key'] = $this->error['alipay_public_key']; + } else { + $data['error_alipay_public_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/alipay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/alipay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_alipay_app_id'])) { + $data['payment_alipay_app_id'] = $this->request->post['payment_alipay_app_id']; + } else { + $data['payment_alipay_app_id'] = $this->config->get('payment_alipay_app_id'); + } + + if (isset($this->request->post['payment_alipay_merchant_private_key'])) { + $data['payment_alipay_merchant_private_key'] = $this->request->post['payment_alipay_merchant_private_key']; + } else { + $data['payment_alipay_merchant_private_key'] = $this->config->get('payment_alipay_merchant_private_key'); + } + + if (isset($this->request->post['payment_alipay_alipay_public_key'])) { + $data['payment_alipay_alipay_public_key'] = $this->request->post['payment_alipay_alipay_public_key']; + } else { + $data['payment_alipay_alipay_public_key'] = $this->config->get('payment_alipay_alipay_public_key'); + } + + if (isset($this->request->post['payment_alipay_total'])) { + $data['payment_alipay_total'] = $this->request->post['payment_alipay_total']; + } else { + $data['payment_alipay_total'] = $this->config->get('payment_alipay_total'); + } + + if (isset($this->request->post['payment_alipay_order_status_id'])) { + $data['payment_alipay_order_status_id'] = $this->request->post['payment_alipay_order_status_id']; + } else { + $data['payment_alipay_order_status_id'] = $this->config->get('payment_alipay_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_alipay_geo_zone_id'])) { + $data['payment_alipay_geo_zone_id'] = $this->request->post['payment_alipay_geo_zone_id']; + } else { + $data['payment_alipay_geo_zone_id'] = $this->config->get('payment_alipay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_alipay_test'])) { + $data['payment_alipay_test'] = $this->request->post['payment_alipay_test']; + } else { + $data['payment_alipay_test'] = $this->config->get('payment_alipay_test'); + } + + if (isset($this->request->post['payment_alipay_status'])) { + $data['payment_alipay_status'] = $this->request->post['payment_alipay_status']; + } else { + $data['payment_alipay_status'] = $this->config->get('payment_alipay_status'); + } + + if (isset($this->request->post['payment_alipay_sort_order'])) { + $data['payment_alipay_sort_order'] = $this->request->post['payment_alipay_sort_order']; + } else { + $data['payment_alipay_sort_order'] = $this->config->get('payment_alipay_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/alipay', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/alipay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_alipay_app_id']) { + $this->error['app_id'] = $this->language->get('error_app_id'); + } + + if (!$this->request->post['payment_alipay_merchant_private_key']) { + $this->error['merchant_private_key'] = $this->language->get('error_merchant_private_key'); + } + + if (!$this->request->post['payment_alipay_alipay_public_key']) { + $this->error['alipay_public_key'] = $this->language->get('error_alipay_public_key'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/alipay_cross.php b/public/admin/controller/extension/payment/alipay_cross.php new file mode 100644 index 0000000..2026023 --- /dev/null +++ b/public/admin/controller/extension/payment/alipay_cross.php @@ -0,0 +1,163 @@ +<?php +class ControllerExtensionPaymentAlipayCross extends Controller { + private $error = array(); + private $currencies = array('GBP', 'HKD', 'USD', 'CHF', 'SGD', 'SEK', 'DKK', 'NOK', 'JPY', 'CAD', 'AUD', 'EUR', 'NZD', 'KRW', 'THB'); + + public function index() { + $this->load->language('extension/payment/alipay_cross'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_alipay_cross', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['app_id'])) { + $data['error_app_id'] = $this->error['app_id']; + } else { + $data['error_app_id'] = ''; + } + + if (isset($this->error['merchant_private_key'])) { + $data['error_merchant_private_key'] = $this->error['merchant_private_key']; + } else { + $data['error_merchant_private_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/alipay_cross', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/alipay_cross', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_alipay_cross_app_id'])) { + $data['payment_alipay_cross_app_id'] = $this->request->post['payment_alipay_cross_app_id']; + } else { + $data['payment_alipay_cross_app_id'] = $this->config->get('payment_alipay_cross_app_id'); + } + + if (isset($this->request->post['payment_alipay_cross_merchant_private_key'])) { + $data['payment_alipay_cross_merchant_private_key'] = $this->request->post['payment_alipay_cross_merchant_private_key']; + } else { + $data['payment_alipay_cross_merchant_private_key'] = $this->config->get('payment_alipay_cross_merchant_private_key'); + } + + if (isset($this->request->post['payment_alipay_cross_currency'])) { + $data['payment_alipay_cross_currency'] = $this->request->post['payment_alipay_cross_currency']; + } else { + $data['payment_alipay_cross_currency'] = $this->config->get('payment_alipay_cross_currency'); + } + + $this->load->model('localisation/currency'); + + $currencies = $this->model_localisation_currency->getCurrencies(); + $data['currencies'] = array(); + foreach ($currencies as $currency) { + if (in_array($currency['code'], $this->currencies)) { + $data['currencies'][] = array( + 'code' => $currency['code'], + 'title' => $currency['title'] + ); + } + } + + if (isset($this->request->post['payment_alipay_cross_test'])) { + $data['payment_alipay_cross_test'] = $this->request->post['payment_alipay_cross_test']; + } else { + $data['payment_alipay_cross_test'] = $this->config->get('payment_alipay_cross_test'); + } + + if (isset($this->request->post['payment_alipay_cross_total'])) { + $data['payment_alipay_cross_total'] = $this->request->post['payment_alipay_cross_total']; + } else { + $data['payment_alipay_cross_total'] = $this->config->get('payment_alipay_cross_total'); + } + + if (isset($this->request->post['payment_alipay_cross_order_status_id'])) { + $data['payment_alipay_cross_order_status_id'] = $this->request->post['payment_alipay_cross_order_status_id']; + } else { + $data['payment_alipay_cross_order_status_id'] = $this->config->get('payment_alipay_cross_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_alipay_cross_geo_zone_id'])) { + $data['payment_alipay_cross_geo_zone_id'] = $this->request->post['payment_alipay_cross_geo_zone_id']; + } else { + $data['payment_alipay_cross_geo_zone_id'] = $this->config->get('payment_alipay_cross_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_alipay_cross_test'])) { + $data['payment_alipay_cross_test'] = $this->request->post['payment_alipay_cross_test']; + } else { + $data['payment_alipay_cross_test'] = $this->config->get('payment_alipay_cross_test'); + } + + if (isset($this->request->post['payment_alipay_cross_status'])) { + $data['payment_alipay_cross_status'] = $this->request->post['payment_alipay_cross_status']; + } else { + $data['payment_alipay_cross_status'] = $this->config->get('payment_alipay_cross_status'); + } + + if (isset($this->request->post['payment_alipay_cross_sort_order'])) { + $data['payment_alipay_cross_sort_order'] = $this->request->post['payment_alipay_cross_sort_order']; + } else { + $data['payment_alipay_cross_sort_order'] = $this->config->get('payment_alipay_cross_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/alipay_cross', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/alipay_cross')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_alipay_cross_app_id']) { + $this->error['app_id'] = $this->language->get('error_app_id'); + } + + if (!$this->request->post['payment_alipay_cross_merchant_private_key']) { + $this->error['merchant_private_key'] = $this->language->get('error_merchant_private_key'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/amazon_login_pay.php b/public/admin/controller/extension/payment/amazon_login_pay.php new file mode 100644 index 0000000..88abbda --- /dev/null +++ b/public/admin/controller/extension/payment/amazon_login_pay.php @@ -0,0 +1,590 @@ +<?php +class ControllerExtensionPaymentAmazonLoginPay extends Controller { + private $version = '3.1'; + private $error = array(); + + public function index() { + + $this->load->language('extension/payment/amazon_login_pay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + $this->load->model('extension/payment/amazon_login_pay'); + + $this->model_extension_payment_amazon_login_pay->install(); + + $this->trimIntegrationDetails(); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_amazon_login_pay', $this->request->post); + + $this->model_extension_payment_amazon_login_pay->deleteEvents(); + $this->model_extension_payment_amazon_login_pay->addEvents(); + + $this->session->data['success'] = $this->language->get('text_success'); + + if (isset($this->request->post['language_reload'])) { + $this->response->redirect($this->url->link('extension/payment/amazon_login_pay', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_access_key'])) { + $data['error_access_key'] = $this->error['error_access_key']; + } else { + $data['error_access_key'] = ''; + } + + if (isset($this->error['error_access_secret'])) { + $data['error_access_secret'] = $this->error['error_access_secret']; + } else { + $data['error_access_secret'] = ''; + } + + if (isset($this->error['error_client_secret'])) { + $data['error_client_secret'] = $this->error['error_client_secret']; + } else { + $data['error_client_secret'] = ''; + } + + if (isset($this->error['error_client_id'])) { + $data['error_client_id'] = $this->error['error_client_id']; + } else { + $data['error_client_id'] = ''; + } + + if (isset($this->error['error_minimum_total'])) { + $data['error_minimum_total'] = $this->error['error_minimum_total']; + } else { + $data['error_minimum_total'] = ''; + } + + if (isset($this->error['error_curreny'])) { + $data['error_curreny'] = $this->error['error_curreny']; + } else { + $data['error_curreny'] = ''; + } + + $data['heading_title'] = $this->language->get('heading_title') . ' ' . $this->version; + + $data['https_catalog'] = HTTPS_CATALOG; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/amazon_login_pay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/amazon_login_pay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_amazon_login_pay_merchant_id'])) { + $data['payment_amazon_login_pay_merchant_id'] = $this->request->post['payment_amazon_login_pay_merchant_id']; + } elseif ($this->config->get('payment_amazon_login_pay_merchant_id')) { + $data['payment_amazon_login_pay_merchant_id'] = $this->config->get('payment_amazon_login_pay_merchant_id'); + } else { + $data['payment_amazon_login_pay_merchant_id'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_access_key'])) { + $data['payment_amazon_login_pay_access_key'] = $this->request->post['payment_amazon_login_pay_access_key']; + } elseif ($this->config->get('payment_amazon_login_pay_access_key')) { + $data['payment_amazon_login_pay_access_key'] = $this->config->get('payment_amazon_login_pay_access_key'); + } else { + $data['payment_amazon_login_pay_access_key'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_access_secret'])) { + $data['payment_amazon_login_pay_access_secret'] = $this->request->post['payment_amazon_login_pay_access_secret']; + } elseif ($this->config->get('payment_amazon_login_pay_access_secret')) { + $data['payment_amazon_login_pay_access_secret'] = $this->config->get('payment_amazon_login_pay_access_secret'); + } else { + $data['payment_amazon_login_pay_access_secret'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_client_id'])) { + $data['payment_amazon_login_pay_client_id'] = $this->request->post['payment_amazon_login_pay_client_id']; + } elseif ($this->config->get('payment_amazon_login_pay_client_id')) { + $data['payment_amazon_login_pay_client_id'] = $this->config->get('payment_amazon_login_pay_client_id'); + } else { + $data['payment_amazon_login_pay_client_id'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_client_secret'])) { + $data['payment_amazon_login_pay_client_secret'] = $this->request->post['payment_amazon_login_pay_client_secret']; + } elseif ($this->config->get('payment_amazon_login_pay_client_secret')) { + $data['payment_amazon_login_pay_client_secret'] = $this->config->get('payment_amazon_login_pay_client_secret'); + } else { + $data['payment_amazon_login_pay_client_secret'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_test'])) { + $data['payment_amazon_login_pay_test'] = $this->request->post['payment_amazon_login_pay_test']; + } elseif ($this->config->get('payment_amazon_login_pay_test')) { + $data['payment_amazon_login_pay_test'] = $this->config->get('payment_amazon_login_pay_test'); + } else { + $data['payment_amazon_login_pay_test'] = 'sandbox'; + } + + if (isset($this->request->post['payment_amazon_login_pay_mode'])) { + $data['payment_amazon_login_pay_mode'] = $this->request->post['payment_amazon_login_pay_mode']; + } elseif ($this->config->get('payment_amazon_login_pay_mode')) { + $data['payment_amazon_login_pay_mode'] = $this->config->get('payment_amazon_login_pay_mode'); + } else { + $data['payment_amazon_login_pay_mode'] = 'payment'; + } + + if (isset($this->request->post['payment_amazon_login_pay_checkout'])) { + $data['payment_amazon_login_pay_checkout'] = $this->request->post['payment_amazon_login_pay_checkout']; + } elseif ($this->config->get('payment_amazon_login_pay_checkout')) { + $data['payment_amazon_login_pay_checkout'] = $this->config->get('payment_amazon_login_pay_checkout'); + } else { + $data['payment_amazon_login_pay_checkout'] = 'payment'; + } + + if (isset($this->request->post['payment_amazon_login_pay_payment_region'])) { + $data['payment_amazon_login_pay_payment_region'] = $this->request->post['payment_amazon_login_pay_payment_region']; + } elseif ($this->config->get('payment_amazon_login_pay_payment_region')) { + $data['payment_amazon_login_pay_payment_region'] = $this->config->get('payment_amazon_login_pay_payment_region'); + } elseif (in_array($this->config->get('config_currency'), array('EUR', 'GBP', 'USD'))) { + $data['payment_amazon_login_pay_payment_region'] = $this->config->get('config_currency'); + } else { + $data['payment_amazon_login_pay_payment_region'] = 'USD'; + } + + if ($data['payment_amazon_login_pay_payment_region'] == 'EUR') { + $data['payment_amazon_login_pay_language'] = 'de-DE'; + $data['sp_id'] = 'AW93DIZMWSDWS'; + $data['locale'] = 'EUR'; + $ld = 'AW93DIZMWSDWS'; + } elseif ($data['payment_amazon_login_pay_payment_region'] == 'GBP') { + $data['payment_amazon_login_pay_language'] = 'en-GB'; + $data['sp_id'] = 'AW93DIZMWSDWS'; + $data['locale'] = 'GBP'; + $ld = 'AW93DIZMWSDWS'; + } else { + $data['payment_amazon_login_pay_language'] = 'en-US'; + $data['sp_id'] = 'A3GK1RS09H3A7D'; + $data['locale'] = 'US'; + $ld = 'A3GK1RS09H3A7D'; + } + + if (isset($this->request->post['payment_amazon_login_pay_language'])) { + $data['payment_amazon_login_pay_language'] = $this->request->post['payment_amazon_login_pay_language']; + } elseif ($this->config->get('payment_amazon_login_pay_language')) { + $data['payment_amazon_login_pay_language'] = $this->config->get('payment_amazon_login_pay_language'); + } + + if (isset($this->request->post['payment_amazon_login_pay_capture_status'])) { + $data['payment_amazon_login_pay_capture_status'] = $this->request->post['payment_amazon_login_pay_capture_status']; + } elseif ($this->config->get('payment_amazon_login_pay_capture_status')) { + $data['payment_amazon_login_pay_capture_status'] = $this->config->get('payment_amazon_login_pay_capture_status'); + } else { + $data['payment_amazon_login_pay_capture_status'] = ''; + } + + if (isset($this->request->post['payment_amazon_login_pay_pending_status'])) { + $data['payment_amazon_login_pay_pending_status'] = $this->request->post['payment_amazon_login_pay_pending_status']; + } elseif ($this->config->get('payment_amazon_login_pay_pending_status')) { + $data['payment_amazon_login_pay_pending_status'] = $this->config->get('payment_amazon_login_pay_pending_status'); + } else { + $data['payment_amazon_login_pay_pending_status'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_ipn_token'])) { + $data['payment_amazon_login_pay_ipn_token'] = $this->request->post['payment_amazon_login_pay_ipn_token']; + } elseif ($this->config->get('payment_amazon_login_pay_ipn_token')) { + $data['payment_amazon_login_pay_ipn_token'] = $this->config->get('payment_amazon_login_pay_ipn_token'); + } else { + $data['payment_amazon_login_pay_ipn_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/amazon_login_pay/ipn&token=' . $data['payment_amazon_login_pay_ipn_token']; + + if (isset($this->request->post['payment_amazon_login_pay_minimum_total'])) { + $data['payment_amazon_login_pay_minimum_total'] = $this->request->post['payment_amazon_login_pay_minimum_total']; + } elseif ($this->config->get('payment_amazon_login_pay_minimum_total')) { + $data['payment_amazon_login_pay_minimum_total'] = $this->config->get('payment_amazon_login_pay_minimum_total'); + } else { + $data['payment_amazon_login_pay_minimum_total'] = '0.01'; + } + + if (isset($this->request->post['payment_amazon_login_pay_geo_zone'])) { + $data['payment_amazon_login_pay_geo_zone'] = $this->request->post['payment_amazon_login_pay_geo_zone']; + } elseif ($this->config->get('payment_amazon_login_pay_geo_zone')) { + $data['payment_amazon_login_pay_geo_zone'] = $this->config->get('payment_amazon_login_pay_geo_zone'); + } else { + $data['payment_amazon_login_pay_geo_zone'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_debug'])) { + $data['payment_amazon_login_pay_debug'] = $this->request->post['payment_amazon_login_pay_debug']; + } elseif ($this->config->get('payment_amazon_login_pay_debug')) { + $data['payment_amazon_login_pay_debug'] = $this->config->get('payment_amazon_login_pay_debug'); + } else { + $data['payment_amazon_login_pay_debug'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_sort_order'])) { + $data['payment_amazon_login_pay_sort_order'] = $this->request->post['payment_amazon_login_pay_sort_order']; + } elseif ($this->config->get('payment_amazon_login_pay_sort_order')) { + $data['payment_amazon_login_pay_sort_order'] = $this->config->get('payment_amazon_login_pay_sort_order'); + } else { + $data['payment_amazon_login_pay_sort_order'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_status'])) { + $data['payment_amazon_login_pay_status'] = $this->request->post['payment_amazon_login_pay_status']; + } elseif ($this->config->get('payment_amazon_login_pay_status')) { + $data['payment_amazon_login_pay_status'] = $this->config->get('payment_amazon_login_pay_status'); + } else { + $data['payment_amazon_login_pay_status'] = '0'; + } + + if (isset($this->request->post['payment_amazon_login_pay_declined_code'])) { + $data['payment_amazon_login_pay_declined_code'] = $this->request->post['payment_amazon_login_pay_declined_code']; + } elseif ($this->config->get('payment_amazon_login_pay_declined_code')) { + $data['payment_amazon_login_pay_declined_code'] = $this->config->get('payment_amazon_login_pay_declined_code'); + } else { + $data['payment_amazon_login_pay_declined_code'] = ''; + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['declined_codes'] = array($this->language->get('text_amazon_invalid'), $this->language->get('text_amazon_rejected'), $this->language->get('text_amazon_timeout')); + + $data['unique_id'] = 'oc-' . str_replace(' ', '-', strtolower($this->config->get('config_name'))) . '_' . mt_rand(); + $data['allowed_login_domain'] = html_entity_decode(HTTPS_CATALOG); + $data['login_redirect_urls'][] = HTTPS_CATALOG . 'index.php?route=payment/amazon_login/login'; + $data['login_redirect_urls'][] = HTTPS_CATALOG . 'index.php?route=payment/amazon_pay/login'; + $data['store_name'] = $this->config->get('config_name'); + $data['simple_path_language'] = str_replace('-', '_', $data['payment_amazon_login_pay_language']); + + if ($data['payment_amazon_login_pay_payment_region'] == 'USD') { + $data['registration_url'] = "https://payments.amazon.com/register?registration_source=SPPL&spId=" . $ld; + + $data['languages'] = array( + 'en-US' => $this->language->get('text_us') + ); + } else { + $data['registration_url'] = "https://payments-eu.amazon.com/register?registration_source=SPPL&spId=" . $ld; + + $data['languages'] = array( + 'de-DE' => $this->language->get('text_de'), + 'es-ES' => $this->language->get('text_es'), + 'fr-FR' => $this->language->get('text_fr'), + 'it-IT' => $this->language->get('text_it'), + 'en-GB' => $this->language->get('text_uk') + ); + } + + $data['payment_regions'] = array( + 'EUR' => $this->language->get('text_eu_region'), + 'GBP' => $this->language->get('text_uk_region'), + 'USD' => $this->language->get('text_us_region') + ); + + $data['has_ssl'] = !empty($this->request->server['HTTPS']); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/amazon_login_pay', $data)); + } + + public function install() { + $this->load->model('extension/payment/amazon_login_pay'); + $this->model_extension_payment_amazon_login_pay->install(); + $this->model_extension_payment_amazon_login_pay->deleteEvents(); + $this->model_extension_payment_amazon_login_pay->addEvents(); + } + + public function uninstall() { + $this->load->model('extension/payment/amazon_login_pay'); + $this->load->model('setting/event'); + $this->model_extension_payment_amazon_login_pay->uninstall(); + $this->model_extension_payment_amazon_login_pay->deleteEvents(); + } + + public function order() { + + if ($this->config->get('payment_amazon_login_pay_status')) { + + $this->load->model('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->get['order_id']); + + if (!empty($amazon_login_pay_order)) { + + $this->load->language('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order['total_captured'] = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']); + + $amazon_login_pay_order['total_formatted'] = $this->currency->format($amazon_login_pay_order['total'], $amazon_login_pay_order['currency_code'], true, true); + $amazon_login_pay_order['total_captured_formatted'] = $this->currency->format($amazon_login_pay_order['total_captured'], $amazon_login_pay_order['currency_code'], true, true); + + $data['amazon_login_pay_order'] = $amazon_login_pay_order; + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/amazon_login_pay_order', $data); + } + } + } + + public function cancel() { + $this->load->language('extension/payment/amazon_login_pay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']); + + $cancel_response = $this->model_extension_payment_amazon_login_pay->cancel($amazon_login_pay_order); + + $this->model_extension_payment_amazon_login_pay->logger($cancel_response); + + if ($cancel_response['status'] == 'Completed') { + $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'cancel', $cancel_response['status'], 0.00); + $this->model_extension_payment_amazon_login_pay->updateCancelStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1); + $json['msg'] = $this->language->get('text_cancel_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['type'] = 'cancel'; + $json['data']['status'] = $cancel_response['status']; + $json['data']['amount'] = $this->currency->format(0.00, $amazon_login_pay_order['currency_code'], true, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($cancel_response['StatuesDetail']) && !empty($cancel_response['StatuesDetail']) ? (string)$cancel_response['StatuesDetail'] : 'Unable to cancel'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/amazon_login_pay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_amazon_login_pay->capture($amazon_login_pay_order, $this->request->post['amount']); + $this->model_extension_payment_amazon_login_pay->logger($capture_response); + + if ($capture_response['status'] == 'Completed' || $capture_response['status'] == 'Pending') { + $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'capture', $capture_response['status'], $this->request->post['amount'], $capture_response['AmazonAuthorizationId'], $capture_response['AmazonCaptureId']); + + $this->model_extension_payment_amazon_login_pay->updateAuthorizationStatus($capture_response['AmazonAuthorizationId'], 'Closed'); + + $total_captured = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']); + + if ($total_captured > 0) { + $order_reference_id = $amazon_login_pay_order['amazon_order_reference_id']; + + if ($this->model_extension_payment_amazon_login_pay->isOrderInState($order_reference_id, array('Open', 'Suspended'))) { + $this->model_extension_payment_amazon_login_pay->closeOrderRef($order_reference_id); + } + } + + if ($total_captured >= (double)$amazon_login_pay_order['total']) { + $this->model_extension_payment_amazon_login_pay->updateCaptureStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['type'] = 'capture'; + $json['data']['status'] = $capture_response['status']; + $json['data']['amazon_authorization_id'] = $capture_response['AmazonAuthorizationId']; + $json['data']['amazon_capture_id'] = $capture_response['AmazonCaptureId']; + $json['data']['amount'] = $this->currency->format($this->request->post['amount'], $amazon_login_pay_order['currency_code'], true, true); + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = $this->currency->format($total_captured, $amazon_login_pay_order['currency_code'], true, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response['status_detail']) && !empty($capture_response['status_detail']) ? (string)$capture_response['status_detail'] : 'Unable to capture'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->setOutput(json_encode($json)); + } + + public function refund() { + $this->load->language('extension/payment/amazon_login_pay'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/amazon_login_pay'); + + $amazon_login_pay_order = $this->model_extension_payment_amazon_login_pay->getOrder($this->request->post['order_id']); + + $refund_response = $this->model_extension_payment_amazon_login_pay->refund($amazon_login_pay_order, $this->request->post['amount']); + + $this->model_extension_payment_amazon_login_pay->logger($refund_response); + + $refund_status = ''; + $total_captured = ''; + $total_refunded = ''; + + foreach ($refund_response as $response) { + if ($response['status'] == 'Pending') { + $this->model_extension_payment_amazon_login_pay->addTransaction($amazon_login_pay_order['amazon_login_pay_order_id'], 'refund', $response['status'], $response['amount'] * -1, $response['amazon_authorization_id'], $response['amazon_capture_id'], $response['AmazonRefundId']); + + $total_refunded = $this->model_extension_payment_amazon_login_pay->getTotalRefunded($amazon_login_pay_order['amazon_login_pay_order_id']); + $total_captured = $this->model_extension_payment_amazon_login_pay->getTotalCaptured($amazon_login_pay_order['amazon_login_pay_order_id']); + + if ($total_captured <= 0 && $amazon_login_pay_order['capture_status'] == 1) { + $this->model_extension_payment_amazon_login_pay->updateRefundStatus($amazon_login_pay_order['amazon_login_pay_order_id'], 1); + $refund_status = 1; + $json['msg'][] = $this->language->get('text_refund_ok_order') . '<br />'; + } else { + $refund_status = 0; + $json['msg'][] = $this->language->get('text_refund_ok') . '<br />'; + } + + $data = array(); + $data['date_added'] = date("Y-m-d H:i:s"); + $data['type'] = 'refund'; + $data['status'] = $response['status']; + $data['amazon_authorization_id'] = $response['amazon_authorization_id']; + $data['amazon_capture_id'] = $response['amazon_capture_id']; + $data['amazon_refund_id'] = $response['AmazonRefundId']; + $data['amount'] = $this->currency->format(($response['amount'] * -1), $amazon_login_pay_order['currency_code'], true, true); + $json['data'][] = $data; + } else { + $json['error'] = true; + $json['error_msg'][] = isset($response['status_detail']) && !empty($response['status_detail']) ? (string)$response['status_detail'] : 'Unable to refund'; + } + } + $json['refund_status'] = $refund_status; + $json['total_captured'] = $this->currency->format($total_captured, $amazon_login_pay_order['currency_code'], true, true); + $json['total_refunded'] = $this->currency->format($total_refunded, $amazon_login_pay_order['currency_code'], true, true); + } else { + $json['error'] = true; + $json['error_msg'][] = $this->language->get('error_data_missing'); + } + $this->response->setOutput(json_encode($json)); + } + + protected function trimIntegrationDetails() { + $integration_keys = array( + 'payment_amazon_login_pay_merchant_id', + 'payment_amazon_login_pay_access_key', + 'payment_amazon_login_pay_access_secret', + 'payment_amazon_login_pay_client_id', + 'payment_amazon_login_pay_client_secret' + ); + + foreach ($this->request->post as $key => $value) { + if (in_array($key, $integration_keys)) { + $this->request->post[$key] = trim($value); + } + } + } + + protected function validate() { + $this->load->model('localisation/currency'); + + if (!$this->user->hasPermission('modify', 'extension/payment/amazon_login_pay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_amazon_login_pay_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_amazon_login_pay_access_key']) { + $this->error['error_access_key'] = $this->language->get('error_access_key'); + } + + if (empty($this->error)) { + $this->load->model('extension/payment/amazon_login_pay'); + $errors = $this->model_extension_payment_amazon_login_pay->validateDetails($this->request->post); + if (isset($errors['error_code']) && $errors['error_code'] == 'InvalidParameterValue') { + $this->error['error_merchant_id'] = $errors['status_detail']; + } elseif (isset($errors['error_code']) && $errors['error_code'] == 'InvalidAccessKeyId') { + $this->error['error_access_key'] = $errors['status_detail']; + } + } + + if (!$this->request->post['payment_amazon_login_pay_access_secret']) { + $this->error['error_access_secret'] = $this->language->get('error_access_secret'); + } + + if (!$this->request->post['payment_amazon_login_pay_client_id']) { + $this->error['error_client_id'] = $this->language->get('error_client_id'); + } + + if (!$this->request->post['payment_amazon_login_pay_client_secret']) { + $this->error['error_client_secret'] = $this->language->get('error_client_secret'); + } + + if ($this->request->post['payment_amazon_login_pay_minimum_total'] <= 0) { + $this->error['error_minimum_total'] = $this->language->get('error_minimum_total'); + } + + if (isset($this->request->post['amazon_login_pay_region'])) { + $currency_code = $this->request->post['amazon_login_pay_region']; + + $currency = $this->model_localisation_currency->getCurrency($this->currency->getId($currency_code)); + + if (empty($currency) || $currency['status'] != '1') { + $this->error['error_curreny'] = sprintf($this->language->get('error_curreny'), $currency_code); + } + } + + return !$this->error; + } + +} diff --git a/public/admin/controller/extension/payment/authorizenet_aim.php b/public/admin/controller/extension/payment/authorizenet_aim.php new file mode 100644 index 0000000..517fc4e --- /dev/null +++ b/public/admin/controller/extension/payment/authorizenet_aim.php @@ -0,0 +1,154 @@ +<?php +class ControllerExtensionPaymentAuthorizenetAim extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/authorizenet_aim'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_authorizenet_aim', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['login'])) { + $data['error_login'] = $this->error['login']; + } else { + $data['error_login'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/authorizenet_aim', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/authorizenet_aim', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_authorizenet_aim_login'])) { + $data['payment_authorizenet_aim_login'] = $this->request->post['payment_authorizenet_aim_login']; + } else { + $data['payment_authorizenet_aim_login'] = $this->config->get('payment_authorizenet_aim_login'); + } + + if (isset($this->request->post['payment_authorizenet_aim_key'])) { + $data['payment_authorizenet_aim_key'] = $this->request->post['payment_authorizenet_aim_key']; + } else { + $data['payment_authorizenet_aim_key'] = $this->config->get('payment_authorizenet_aim_key'); + } + + if (isset($this->request->post['payment_authorizenet_aim_hash'])) { + $data['payment_authorizenet_aim_hash'] = $this->request->post['payment_authorizenet_aim_hash']; + } else { + $data['payment_authorizenet_aim_hash'] = $this->config->get('payment_authorizenet_aim_hash'); + } + + if (isset($this->request->post['payment_authorizenet_aim_server'])) { + $data['payment_authorizenet_aim_server'] = $this->request->post['payment_authorizenet_aim_server']; + } else { + $data['payment_authorizenet_aim_server'] = $this->config->get('payment_authorizenet_aim_server'); + } + + if (isset($this->request->post['payment_authorizenet_aim_mode'])) { + $data['payment_authorizenet_aim_mode'] = $this->request->post['payment_authorizenet_aim_mode']; + } else { + $data['payment_authorizenet_aim_mode'] = $this->config->get('payment_authorizenet_aim_mode'); + } + + if (isset($this->request->post['payment_authorizenet_aim_method'])) { + $data['payment_authorizenet_aim_method'] = $this->request->post['payment_authorizenet_aim_method']; + } else { + $data['payment_authorizenet_aim_method'] = $this->config->get('payment_authorizenet_aim_method'); + } + + if (isset($this->request->post['payment_authorizenet_aim_total'])) { + $data['payment_authorizenet_aim_total'] = $this->request->post['payment_authorizenet_aim_total']; + } else { + $data['payment_authorizenet_aim_total'] = $this->config->get('payment_authorizenet_aim_total'); + } + + if (isset($this->request->post['payment_authorizenet_aim_order_status_id'])) { + $data['payment_authorizenet_aim_order_status_id'] = $this->request->post['payment_authorizenet_aim_order_status_id']; + } else { + $data['payment_authorizenet_aim_order_status_id'] = $this->config->get('payment_authorizenet_aim_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_authorizenet_aim_geo_zone_id'])) { + $data['payment_authorizenet_aim_geo_zone_id'] = $this->request->post['payment_authorizenet_aim_geo_zone_id']; + } else { + $data['payment_authorizenet_aim_geo_zone_id'] = $this->config->get('payment_authorizenet_aim_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_authorizenet_aim_status'])) { + $data['payment_authorizenet_aim_status'] = $this->request->post['payment_authorizenet_aim_status']; + } else { + $data['payment_authorizenet_aim_status'] = $this->config->get('payment_authorizenet_aim_status'); + } + + if (isset($this->request->post['payment_authorizenet_aim_sort_order'])) { + $data['payment_authorizenet_aim_sort_order'] = $this->request->post['payment_authorizenet_aim_sort_order']; + } else { + $data['payment_authorizenet_aim_sort_order'] = $this->config->get('payment_authorizenet_aim_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/authorizenet_aim', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/authorizenet_aim')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_authorizenet_aim_login']) { + $this->error['login'] = $this->language->get('error_login'); + } + + if (!$this->request->post['payment_authorizenet_aim_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/authorizenet_sim.php b/public/admin/controller/extension/payment/authorizenet_sim.php new file mode 100644 index 0000000..ceb4dbe --- /dev/null +++ b/public/admin/controller/extension/payment/authorizenet_sim.php @@ -0,0 +1,145 @@ +<?php +class ControllerExtensionPaymentAuthorizeNetSim extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/authorizenet_sim'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_authorizenet_sim', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/authorizenet_sim', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/authorizenet_sim', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_authorizenet_sim_merchant'])) { + $data['payment_authorizenet_sim_merchant'] = $this->request->post['payment_authorizenet_sim_merchant']; + } else { + $data['payment_authorizenet_sim_merchant'] = $this->config->get('payment_authorizenet_sim_merchant'); + } + + if (isset($this->request->post['payment_authorizenet_sim_key'])) { + $data['payment_authorizenet_sim_key'] = $this->request->post['payment_authorizenet_sim_key']; + } else { + $data['payment_authorizenet_sim_key'] = $this->config->get('payment_authorizenet_sim_key'); + } + + if (isset($this->request->post['payment_authorizenet_sim_test'])) { + $data['payment_authorizenet_sim_test'] = $this->request->post['payment_authorizenet_sim_test']; + } else { + $data['payment_authorizenet_sim_test'] = $this->config->get('payment_authorizenet_sim_test'); + } + + $data['callback'] = HTTP_CATALOG . 'index.php?route=extension/payment/authorizenet_sim/callback'; + + if (isset($this->request->post['payment_authorizenet_sim_hash'])) { + $data['payment_authorizenet_sim_hash'] = $this->request->post['payment_authorizenet_sim_hash']; + } else { + $data['payment_authorizenet_sim_hash'] = $this->config->get('payment_authorizenet_sim_hash'); + } + + if (isset($this->request->post['payment_authorizenet_sim_total'])) { + $data['payment_authorizenet_sim_total'] = $this->request->post['payment_authorizenet_sim_total']; + } else { + $data['payment_authorizenet_sim_total'] = $this->config->get('payment_authorizenet_sim_total'); + } + + if (isset($this->request->post['payment_authorizenet_sim_order_status_id'])) { + $data['payment_authorizenet_sim_order_status_id'] = $this->request->post['payment_authorizenet_sim_order_status_id']; + } else { + $data['payment_authorizenet_sim_order_status_id'] = $this->config->get('payment_authorizenet_sim_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_authorizenet_sim_geo_zone_id'])) { + $data['payment_authorizenet_sim_geo_zone_id'] = $this->request->post['payment_authorizenet_sim_geo_zone_id']; + } else { + $data['payment_authorizenet_sim_geo_zone_id'] = $this->config->get('payment_authorizenet_sim_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_authorizenet_sim_status'])) { + $data['payment_authorizenet_sim_status'] = $this->request->post['payment_authorizenet_sim_status']; + } else { + $data['payment_authorizenet_sim_status'] = $this->config->get('payment_authorizenet_sim_status'); + } + + if (isset($this->request->post['payment_authorizenet_sim_sort_order'])) { + $data['payment_authorizenet_sim_sort_order'] = $this->request->post['payment_authorizenet_sim_sort_order']; + } else { + $data['payment_authorizenet_sim_sort_order'] = $this->config->get('payment_authorizenet_sim_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/authorizenet_sim', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/authorizenet_sim')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_authorizenet_sim_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + if (!$this->request->post['payment_authorizenet_sim_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/bank_transfer.php b/public/admin/controller/extension/payment/bank_transfer.php new file mode 100644 index 0000000..9bb4882 --- /dev/null +++ b/public/admin/controller/extension/payment/bank_transfer.php @@ -0,0 +1,131 @@ +<?php +class ControllerExtensionPaymentBankTransfer extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/bank_transfer'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_bank_transfer', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['bank'])) { + $data['error_bank'] = $this->error['bank']; + } else { + $data['error_bank'] = array(); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/bank_transfer', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/bank_transfer', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $this->load->model('localisation/language'); + + $data['payment_bank_transfer'] = array(); + + $languages = $this->model_localisation_language->getLanguages(); + + foreach ($languages as $language) { + if (isset($this->request->post['payment_bank_transfer_bank' . $language['language_id']])) { + $data['payment_bank_transfer_bank'][$language['language_id']] = $this->request->post['payment_bank_transfer_bank' . $language['language_id']]; + } else { + $data['payment_bank_transfer_bank'][$language['language_id']] = $this->config->get('payment_bank_transfer_bank' . $language['language_id']); + } + } + + $data['languages'] = $languages; + + if (isset($this->request->post['payment_bank_transfer_total'])) { + $data['payment_bank_transfer_total'] = $this->request->post['payment_bank_transfer_total']; + } else { + $data['payment_bank_transfer_total'] = $this->config->get('payment_bank_transfer_total'); + } + + if (isset($this->request->post['payment_bank_transfer_order_status_id'])) { + $data['payment_bank_transfer_order_status_id'] = $this->request->post['payment_bank_transfer_order_status_id']; + } else { + $data['payment_bank_transfer_order_status_id'] = $this->config->get('payment_bank_transfer_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_bank_transfer_geo_zone_id'])) { + $data['payment_bank_transfer_geo_zone_id'] = $this->request->post['payment_bank_transfer_geo_zone_id']; + } else { + $data['payment_bank_transfer_geo_zone_id'] = $this->config->get('payment_bank_transfer_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_bank_transfer_status'])) { + $data['payment_bank_transfer_status'] = $this->request->post['payment_bank_transfer_status']; + } else { + $data['payment_bank_transfer_status'] = $this->config->get('payment_bank_transfer_status'); + } + + if (isset($this->request->post['payment_bank_transfer_sort_order'])) { + $data['payment_bank_transfer_sort_order'] = $this->request->post['payment_bank_transfer_sort_order']; + } else { + $data['payment_bank_transfer_sort_order'] = $this->config->get('payment_bank_transfer_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/bank_transfer', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/bank_transfer')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $this->load->model('localisation/language'); + + $languages = $this->model_localisation_language->getLanguages(); + + foreach ($languages as $language) { + if (empty($this->request->post['payment_bank_transfer_bank' . $language['language_id']])) { + $this->error['bank'][$language['language_id']] = $this->language->get('error_bank'); + } + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/bluepay_hosted.php b/public/admin/controller/extension/payment/bluepay_hosted.php new file mode 100644 index 0000000..2ce59d6 --- /dev/null +++ b/public/admin/controller/extension/payment/bluepay_hosted.php @@ -0,0 +1,351 @@ +<?php +class ControllerExtensionPaymentBluePayHosted extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/bluepay_hosted'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_bluepay_hosted', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['account_name'])) { + $data['error_account_name'] = $this->error['account_name']; + } else { + $data['error_account_name'] = ''; + } + + if (isset($this->error['account_id'])) { + $data['error_account_id'] = $this->error['account_id']; + } else { + $data['error_account_id'] = ''; + } + + if (isset($this->error['secret_key'])) { + $data['error_secret_key'] = $this->error['secret_key']; + } else { + $data['error_secret_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/bluepay_hosted', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/bluepay_hosted', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_bluepay_hosted_account_name'])) { + $data['payment_bluepay_hosted_account_name'] = $this->request->post['payment_bluepay_hosted_account_name']; + } else { + $data['payment_bluepay_hosted_account_name'] = $this->config->get('payment_bluepay_hosted_account_name'); + } + + if (isset($this->request->post['payment_bluepay_hosted_account_id'])) { + $data['payment_bluepay_hosted_account_id'] = $this->request->post['payment_bluepay_hosted_account_id']; + } else { + $data['payment_bluepay_hosted_account_id'] = $this->config->get('payment_bluepay_hosted_account_id'); + } + + if (isset($this->request->post['payment_bluepay_hosted_secret_key'])) { + $data['payment_bluepay_hosted_secret_key'] = $this->request->post['payment_bluepay_hosted_secret_key']; + } else { + $data['payment_bluepay_hosted_secret_key'] = $this->config->get('payment_bluepay_hosted_secret_key'); + } + + if (isset($this->request->post['payment_bluepay_hosted_test'])) { + $data['payment_bluepay_hosted_test'] = $this->request->post['payment_bluepay_hosted_test']; + } else { + $data['payment_bluepay_hosted_test'] = $this->config->get('payment_bluepay_hosted_test'); + } + + if (isset($this->request->post['payment_bluepay_hosted_transaction'])) { + $data['payment_bluepay_hosted_transaction'] = $this->request->post['payment_bluepay_hosted_transaction']; + } else { + $data['payment_bluepay_hosted_transaction'] = $this->config->get('payment_bluepay_hosted_transaction'); + } + + if (isset($this->request->post['payment_bluepay_hosted_amex'])) { + $data['payment_bluepay_hosted_amex'] = $this->request->post['payment_bluepay_hosted_amex']; + } else { + $data['payment_bluepay_hosted_amex'] = $this->config->get('payment_bluepay_hosted_amex'); + } + + if (isset($this->request->post['payment_bluepay_hosted_discover'])) { + $data['payment_bluepay_hosted_discover'] = $this->request->post['payment_bluepay_hosted_discover']; + } else { + $data['payment_bluepay_hosted_discover'] = $this->config->get('payment_bluepay_hosted_discover'); + } + + if (isset($this->request->post['payment_bluepay_hosted_total'])) { + $data['payment_bluepay_hosted_total'] = $this->request->post['payment_bluepay_hosted_total']; + } else { + $data['payment_bluepay_hosted_total'] = $this->config->get('payment_bluepay_hosted_total'); + } + + if (isset($this->request->post['payment_bluepay_hosted_order_status_id'])) { + $data['payment_bluepay_hosted_order_status_id'] = $this->request->post['payment_bluepay_hosted_order_status_id']; + } elseif ($this->config->get('payment_bluepay_hosted_order_status_id')) { + $data['payment_bluepay_hosted_order_status_id'] = $this->config->get('payment_bluepay_hosted_order_status_id'); + } else { + $data['payment_bluepay_hosted_order_status_id'] = 2; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_bluepay_hosted_geo_zone_id'])) { + $data['payment_bluepay_hosted_geo_zone_id'] = $this->request->post['payment_bluepay_hosted_geo_zone_id']; + } else { + $data['payment_bluepay_hosted_geo_zone_id'] = $this->config->get('payment_bluepay_hosted_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_bluepay_hosted_status'])) { + $data['payment_bluepay_hosted_status'] = $this->request->post['payment_bluepay_hosted_status']; + } else { + $data['payment_bluepay_hosted_status'] = $this->config->get('payment_bluepay_hosted_status'); + } + + if (isset($this->request->post['payment_bluepay_hosted_debug'])) { + $data['payment_bluepay_hosted_debug'] = $this->request->post['payment_bluepay_hosted_debug']; + } else { + $data['payment_bluepay_hosted_debug'] = $this->config->get('payment_bluepay_hosted_debug'); + } + + if (isset($this->request->post['payment_bluepay_hosted_sort_order'])) { + $data['payment_bluepay_hosted_sort_order'] = $this->request->post['payment_bluepay_hosted_sort_order']; + } else { + $data['payment_bluepay_hosted_sort_order'] = $this->config->get('payment_bluepay_hosted_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/bluepay_hosted', $data)); + } + + public function install() { + $this->load->model('extension/payment/bluepay_hosted'); + + $this->model_extension_payment_bluepay_hosted->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/bluepay_hosted'); + + $this->model_extension_payment_bluepay_hosted->uninstall(); + } + + public function order() { + if ($this->config->get('payment_bluepay_hosted_status')) { + $this->load->model('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->get['order_id']); + + if (!empty($bluepay_hosted_order)) { + $this->load->language('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order['total_released'] = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']); + + $bluepay_hosted_order['total_formatted'] = $this->currency->format($bluepay_hosted_order['total'], $bluepay_hosted_order['currency_code'], false, false); + $bluepay_hosted_order['total_released_formatted'] = $this->currency->format($bluepay_hosted_order['total_released'], $bluepay_hosted_order['currency_code'], false, false); + + $data['bluepay_hosted_order'] = $bluepay_hosted_order; + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/bluepay_hosted_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/bluepay_hosted'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_bluepay_hosted->void($this->request->post['order_id']); + + $this->model_extension_payment_bluepay_hosted->logger('Void result:\r\n' . print_r($void_response, 1)); + + if ($void_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'void', $bluepay_hosted_order['total']); + $this->model_extension_payment_bluepay_hosted->updateVoidStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['total'] = $bluepay_hosted_order['total']; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['MESSAGE']) && !empty($void_response['MESSAGE']) ? (string)$void_response['MESSAGE'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/bluepay_hosted'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_bluepay_hosted->release($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_bluepay_hosted->logger('Release result:\r\n' . print_r($release_response, 1)); + + if ($release_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'payment', $this->request->post['amount']); + + $this->model_extension_payment_bluepay_hosted->updateTransactionId($bluepay_hosted_order['bluepay_hosted_order_id'], $release_response['RRNO']); + + $total_released = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']); + + if ($total_released >= $bluepay_hosted_order['total']) { + $this->model_extension_payment_bluepay_hosted->updateReleaseStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (float)$total_released; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($release_response['MESSAGE']) && !empty($release_response['MESSAGE']) ? (string)$release_response['MESSAGE'] : 'Unable to release'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/bluepay_hosted'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/bluepay_hosted'); + + $bluepay_hosted_order = $this->model_extension_payment_bluepay_hosted->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_bluepay_hosted->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_bluepay_hosted->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if ($rebate_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_hosted->addTransaction($bluepay_hosted_order['bluepay_hosted_order_id'], 'rebate', $this->request->post['amount'] * -1); + + $total_rebated = $this->model_extension_payment_bluepay_hosted->getTotalRebated($bluepay_hosted_order['bluepay_hosted_order_id']); + $total_released = $this->model_extension_payment_bluepay_hosted->getTotalReleased($bluepay_hosted_order['bluepay_hosted_order_id']); + + if ($total_released <= 0 && $bluepay_hosted_order['release_status'] == 1) { + $this->model_extension_payment_bluepay_hosted->updateRebateStatus($bluepay_hosted_order['bluepay_hosted_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response['MESSAGE']) && !empty($rebate_response['MESSAGE']) ? (string)$rebate_response['MESSAGE'] : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/bluepay_hosted')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_bluepay_hosted_account_name']) { + $this->error['account_name'] = $this->language->get('error_account_name'); + } + + if (!$this->request->post['payment_bluepay_hosted_account_id']) { + $this->error['account_id'] = $this->language->get('error_account_id'); + } + + if (!$this->request->post['payment_bluepay_hosted_secret_key']) { + $this->error['secret_key'] = $this->language->get('error_secret_key'); + } + + return !$this->error; + } + + public function callback() { + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($this->request->get)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/bluepay_redirect.php b/public/admin/controller/extension/payment/bluepay_redirect.php new file mode 100644 index 0000000..a416a54 --- /dev/null +++ b/public/admin/controller/extension/payment/bluepay_redirect.php @@ -0,0 +1,331 @@ +<?php +class ControllerExtensionPaymentBluepayredirect extends Controller { + private $error = array(); + + public function index() { + + $this->load->language('extension/payment/bluepay_redirect'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_bluepay_redirect', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['account_id'])) { + $data['error_account_id'] = $this->error['account_id']; + } else { + $data['error_account_id'] = ''; + } + + if (isset($this->error['secret_key'])) { + $data['error_secret_key'] = $this->error['secret_key']; + } else { + $data['error_secret_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/bluepay_redirect', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/bluepay_redirect', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_bluepay_redirect_account_id'])) { + $data['payment_bluepay_redirect_account_id'] = $this->request->post['payment_bluepay_redirect_account_id']; + } else { + $data['payment_bluepay_redirect_account_id'] = $this->config->get('payment_bluepay_redirect_account_id'); + } + + if (isset($this->request->post['payment_bluepay_redirect_secret_key'])) { + $data['payment_bluepay_redirect_secret_key'] = $this->request->post['payment_bluepay_redirect_secret_key']; + } else { + $data['payment_bluepay_redirect_secret_key'] = $this->config->get('payment_bluepay_redirect_secret_key'); + } + + if (isset($this->request->post['payment_bluepay_redirect_test'])) { + $data['payment_bluepay_redirect_test'] = $this->request->post['payment_bluepay_redirect_test']; + } else { + $data['payment_bluepay_redirect_test'] = $this->config->get('payment_bluepay_redirect_test'); + } + + if (isset($this->request->post['payment_bluepay_redirect_transaction'])) { + $data['payment_bluepay_redirect_transaction'] = $this->request->post['payment_bluepay_redirect_transaction']; + } else { + $data['payment_bluepay_redirect_transaction'] = $this->config->get('payment_bluepay_redirect_transaction'); + } + + if (isset($this->request->post['payment_bluepay_redirect_total'])) { + $data['payment_bluepay_redirect_total'] = $this->request->post['payment_bluepay_redirect_total']; + } else { + $data['payment_bluepay_redirect_total'] = $this->config->get('payment_bluepay_redirect_total'); + } + + if (isset($this->request->post['payment_bluepay_redirect_card'])) { + $data['payment_bluepay_redirect_card'] = $this->request->post['payment_bluepay_redirect_card']; + } else { + $data['payment_bluepay_redirect_card'] = $this->config->get('payment_bluepay_redirect_card'); + } + + if (isset($this->request->post['payment_bluepay_redirect_order_status_id'])) { + $data['payment_bluepay_redirect_order_status_id'] = $this->request->post['payment_bluepay_redirect_order_status_id']; + } elseif ($this->config->get('payment_bluepay_redirect_order_status_id')) { + $data['payment_bluepay_redirect_order_status_id'] = $this->config->get('payment_bluepay_redirect_order_status_id'); + } else { + $data['payment_bluepay_redirect_order_status_id'] = 2; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_bluepay_redirect_geo_zone_id'])) { + $data['payment_bluepay_redirect_geo_zone_id'] = $this->request->post['payment_bluepay_redirect_geo_zone_id']; + } else { + $data['payment_bluepay_redirect_geo_zone_id'] = $this->config->get('payment_bluepay_redirect_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_bluepay_redirect_status'])) { + $data['payment_bluepay_redirect_status'] = $this->request->post['payment_bluepay_redirect_status']; + } else { + $data['payment_bluepay_redirect_status'] = $this->config->get('payment_bluepay_redirect_status'); + } + + if (isset($this->request->post['payment_bluepay_redirect_debug'])) { + $data['payment_bluepay_redirect_debug'] = $this->request->post['payment_bluepay_redirect_debug']; + } else { + $data['payment_bluepay_redirect_debug'] = $this->config->get('payment_bluepay_redirect_debug'); + } + + if (isset($this->request->post['payment_bluepay_redirect_sort_order'])) { + $data['payment_bluepay_redirect_sort_order'] = $this->request->post['payment_bluepay_redirect_sort_order']; + } else { + $data['payment_bluepay_redirect_sort_order'] = $this->config->get('payment_bluepay_redirect_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/bluepay_redirect', $data)); + } + + public function install() { + $this->load->model('extension/payment/bluepay_redirect'); + + $this->model_extension_payment_bluepay_redirect->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/bluepay_redirect'); + + $this->model_extension_payment_bluepay_redirect->uninstall(); + } + + public function order() { + if ($this->config->get('payment_bluepay_redirect_status')) { + $this->load->model('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->get['order_id']); + + if (!empty($bluepay_redirect_order)) { + $this->load->language('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order['total_released'] = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']); + + $bluepay_redirect_order['total_formatted'] = $this->currency->format($bluepay_redirect_order['total'], $bluepay_redirect_order['currency_code'], false, false); + $bluepay_redirect_order['total_released_formatted'] = $this->currency->format($bluepay_redirect_order['total_released'], $bluepay_redirect_order['currency_code'], false, false); + + $data['bluepay_redirect_order'] = $bluepay_redirect_order; + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/bluepay_redirect_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/bluepay_redirect'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_bluepay_redirect->void($this->request->post['order_id']); + + $this->model_extension_payment_bluepay_redirect->logger('Void result:\r\n' . print_r($void_response, 1)); + + if ($void_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'void', $bluepay_redirect_order['total']); + $this->model_extension_payment_bluepay_redirect->updateVoidStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['total'] = $bluepay_redirect_order['total']; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['MESSAGE']) && !empty($void_response['MESSAGE']) ? (string)$void_response['MESSAGE'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/bluepay_redirect'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_bluepay_redirect->release($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_bluepay_redirect->logger('Release result:\r\n' . print_r($release_response, 1)); + + if ($release_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'payment', $this->request->post['amount']); + + $this->model_extension_payment_bluepay_redirect->updateTransactionId($bluepay_redirect_order['bluepay_redirect_order_id'], $release_response['RRNO']); + + $total_released = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']); + + if ($total_released >= $bluepay_redirect_order['total']) { + $this->model_extension_payment_bluepay_redirect->updateReleaseStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (float)$total_released; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($release_response['MESSAGE']) && !empty($release_response['MESSAGE']) ? (string)$release_response['MESSAGE'] : 'Unable to release'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/bluepay_redirect'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/bluepay_redirect'); + + $bluepay_redirect_order = $this->model_extension_payment_bluepay_redirect->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_bluepay_redirect->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_bluepay_redirect->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if ($rebate_response['Result'] == 'APPROVED') { + $this->model_extension_payment_bluepay_redirect->addTransaction($bluepay_redirect_order['bluepay_redirect_order_id'], 'rebate', $this->request->post['amount'] * -1); + + $total_rebated = $this->model_extension_payment_bluepay_redirect->getTotalRebated($bluepay_redirect_order['bluepay_redirect_order_id']); + $total_released = $this->model_extension_payment_bluepay_redirect->getTotalReleased($bluepay_redirect_order['bluepay_redirect_order_id']); + + if ($total_released <= 0 && $bluepay_redirect_order['release_status'] == 1) { + $this->model_extension_payment_bluepay_redirect->updateRebateStatus($bluepay_redirect_order['bluepay_redirect_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response['MESSAGE']) && !empty($rebate_response['MESSAGE']) ? (string)$rebate_response['MESSAGE'] : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/bluepay_redirect')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_bluepay_redirect_account_id']) { + $this->error['account_id'] = $this->language->get('error_account_id'); + } + + if (!$this->request->post['payment_bluepay_redirect_secret_key']) { + $this->error['secret_key'] = $this->language->get('error_secret_key'); + } + + return !$this->error; + } + + public function callback() { + $this->response->addHeader('Content-Type: application/json'); + + $this->response->setOutput(json_encode($this->request->get)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/cardconnect.php b/public/admin/controller/extension/payment/cardconnect.php new file mode 100644 index 0000000..8039cf4 --- /dev/null +++ b/public/admin/controller/extension/payment/cardconnect.php @@ -0,0 +1,501 @@ +<?php +class ControllerExtensionPaymentCardConnect extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + + $this->load->model('extension/payment/cardconnect'); + + $this->load->language('extension/payment/cardconnect'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_cardconnect', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/cardconnect', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/cardconnect', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_cardconnect_merchant_id'])) { + $data['payment_cardconnect_merchant_id'] = $this->request->post['payment_cardconnect_merchant_id']; + } else { + $data['payment_cardconnect_merchant_id'] = $this->config->get('payment_cardconnect_merchant_id'); + } + + if (isset($this->request->post['cardconnect_api_username'])) { + $data['cardconnect_api_username'] = $this->request->post['cardconnect_api_username']; + } else { + $data['cardconnect_api_username'] = $this->config->get('cardconnect_api_username'); + } + + if (isset($this->request->post['cardconnect_api_password'])) { + $data['cardconnect_api_password'] = $this->request->post['cardconnect_api_password']; + } else { + $data['cardconnect_api_password'] = $this->config->get('cardconnect_api_password'); + } + + if (isset($this->request->post['cardconnect_token'])) { + $data['cardconnect_token'] = $this->request->post['cardconnect_token']; + } elseif ($this->config->has('cardconnect_token')) { + $data['cardconnect_token'] = $this->config->get('cardconnect_token'); + } else { + $data['cardconnect_token'] = md5(time()); + } + + if (isset($this->request->post['cardconnect_transaction'])) { + $data['cardconnect_transaction'] = $this->request->post['cardconnect_transaction']; + } else { + $data['cardconnect_transaction'] = $this->config->get('cardconnect_transaction'); + } + + if (isset($this->request->post['cardconnect_site'])) { + $data['cardconnect_site'] = $this->request->post['cardconnect_site']; + } elseif ($this->config->has('cardconnect_site')) { + $data['cardconnect_site'] = $this->config->get('cardconnect_site'); + } else { + $data['cardconnect_site'] = 'fts'; + } + + if (isset($this->request->post['cardconnect_environment'])) { + $data['cardconnect_environment'] = $this->request->post['cardconnect_environment']; + } else { + $data['cardconnect_environment'] = $this->config->get('cardconnect_environment'); + } + + if (isset($this->request->post['cardconnect_store_cards'])) { + $data['cardconnect_store_cards'] = $this->request->post['cardconnect_store_cards']; + } else { + $data['cardconnect_store_cards'] = $this->config->get('cardconnect_store_cards'); + } + + if (isset($this->request->post['cardconnect_echeck'])) { + $data['cardconnect_echeck'] = $this->request->post['cardconnect_echeck']; + } else { + $data['cardconnect_echeck'] = $this->config->get('cardconnect_echeck'); + } + + if (isset($this->request->post['cardconnect_total'])) { + $data['cardconnect_total'] = $this->request->post['cardconnect_total']; + } else { + $data['cardconnect_total'] = $this->config->get('cardconnect_total'); + } + + if (isset($this->request->post['cardconnect_geo_zone'])) { + $data['cardconnect_geo_zone'] = $this->request->post['cardconnect_geo_zone']; + } else { + $data['cardconnect_geo_zone'] = $this->config->get('cardconnect_geo_zone'); + } + + if (isset($this->request->post['cardconnect_status'])) { + $data['cardconnect_status'] = $this->request->post['cardconnect_status']; + } else { + $data['cardconnect_status'] = $this->config->get('cardconnect_status'); + } + + if (isset($this->request->post['cardconnect_logging'])) { + $data['cardconnect_logging'] = $this->request->post['cardconnect_logging']; + } else { + $data['cardconnect_logging'] = $this->config->get('cardconnect_logging'); + } + + if (isset($this->request->post['cardconnect_sort_order'])) { + $data['cardconnect_sort_order'] = $this->request->post['cardconnect_sort_order']; + } else { + $data['cardconnect_sort_order'] = $this->config->get('cardconnect_sort_order'); + } + + $data['cardconnect_cron_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/cardconnect/cron&token=' . $data['cardconnect_token']; + + if ($this->config->get('cardconnect_cron_time')) { + $data['cardconnect_cron_time'] = date($this->language->get('datetime_format'), strtotime($this->config->get('cardconnect_cron_time'))); + } else { + $data['cardconnect_cron_time'] = $this->language->get('text_no_cron_time'); + } + + if (isset($this->request->post['cardconnect_order_status_id_pending'])) { + $data['cardconnect_order_status_id_pending'] = $this->request->post['cardconnect_order_status_id_pending']; + } elseif ($this->config->has('cardconnect_order_status_id_pending')) { + $data['cardconnect_order_status_id_pending'] = $this->config->get('cardconnect_order_status_id_pending'); + } else { + $data['cardconnect_order_status_id_pending'] = '1'; + } + + if (isset($this->request->post['cardconnect_order_status_id_processing'])) { + $data['cardconnect_order_status_id_processing'] = $this->request->post['cardconnect_order_status_id_processing']; + } elseif ($this->config->has('cardconnect_order_status_id_processing')) { + $data['cardconnect_order_status_id_processing'] = $this->config->get('cardconnect_order_status_id_processing'); + } else { + $data['cardconnect_order_status_id_processing'] = '2'; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->error['payment_cardconnect_merchant_id'])) { + $data['error_payment_cardconnect_merchant_id'] = $this->error['payment_cardconnect_merchant_id']; + } else { + $data['error_payment_cardconnect_merchant_id'] = ''; + } + + if (isset($this->error['cardconnect_api_username'])) { + $data['error_cardconnect_api_username'] = $this->error['cardconnect_api_username']; + } else { + $data['error_cardconnect_api_username'] = ''; + } + + if (isset($this->error['cardconnect_api_password'])) { + $data['error_cardconnect_api_password'] = $this->error['cardconnect_api_password']; + } else { + $data['error_cardconnect_api_password'] = ''; + } + + if (isset($this->error['cardconnect_token'])) { + $data['error_cardconnect_token'] = $this->error['cardconnect_token']; + } else { + $data['error_cardconnect_token'] = ''; + } + + if (isset($this->error['cardconnect_site'])) { + $data['error_cardconnect_site'] = $this->error['cardconnect_site']; + } else { + $data['error_cardconnect_site'] = ''; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/cardconnect', $data)); + } + + public function install() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/cardconnect'); + + $this->model_extension_payment_cardconnect->install(); + } + } + + public function uninstall() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/cardconnect'); + + $this->model_extension_payment_cardconnect->uninstall(); + } + } + + public function order() { + if ($this->config->get('cardconnect_status')) { + $this->load->model('extension/payment/cardconnect'); + + $order_id = $this->request->get['order_id']; + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->get['order_id']); + + if ($cardconnect_order) { + $this->load->language('extension/payment/cardconnect'); + + if ($cardconnect_order['payment_method'] == 'card') { + $cardconnect_order['payment_method'] = $this->language->get('text_card'); + } else { + $cardconnect_order['payment_method'] = $this->language->get('text_echeck'); + } + + $cardconnect_order['total_formatted'] = $this->currency->format($cardconnect_order['total'], $cardconnect_order['currency_code'], false, true); + + $cardconnect_order['total_captured'] = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']); + + $cardconnect_order['total_captured_formatted'] = $this->currency->format($cardconnect_order['total_captured'], $cardconnect_order['currency_code'], false, true); + + foreach($cardconnect_order['transactions'] as &$transaction) { + switch ($transaction['type']) { + case 'payment': + $transaction['type'] = 'Payment'; + break; + case 'auth': + $transaction['type'] = 'Authorize'; + break; + case 'refund': + $transaction['type'] = 'Refund'; + break; + case 'void': + $transaction['type'] = 'Void'; + break; + default: + $transaction['type'] = 'Payment'; + } + + $transaction['amount'] = $this->currency->format($transaction['amount'], $cardconnect_order['currency_code'], false, true); + + if ($transaction['status'] == 'Y') { + $transaction['status'] = 'Accepted'; + } else if ($transaction['status'] == 'N') { + $transaction['status'] = 'Rejected'; + } + + $transaction['date_modified'] = date($this->language->get('datetime_format'), strtotime($transaction['date_modified'])); + + $transaction['date_added'] = date($this->language->get('datetime_format'), strtotime($transaction['date_added'])); + } + + $data['cardconnect_order'] = $cardconnect_order; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/cardconnect_order', $data); + } + } + } + + public function inquire() { + $this->load->language('extension/payment/cardconnect'); + + $json = array(); + + if ($this->config->get('cardconnect_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['retref'])) { + $this->load->model('extension/payment/cardconnect'); + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']); + + if ($cardconnect_order) { + $inquire_response = $this->model_extension_payment_cardconnect->inquire($cardconnect_order, $this->request->post['retref']); + + if (isset($inquire_response['respstat']) && $inquire_response['respstat'] == 'C') { + $json['error'] = $inquire_response['resptext']; + } else { + $this->model_extension_payment_cardconnect->updateTransactionStatusByRetref($this->request->post['retref'], $inquire_response['setlstat']); + + $json['status'] = $inquire_response['setlstat']; + + $json['date_modified'] = date($this->language->get('datetime_format')); + + $json['success'] = $this->language->get('text_inquire_success'); + } + } else { + $json['error'] = $this->language->get('error_no_order'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/cardconnect'); + + $json = array(); + + if ($this->config->get('cardconnect_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['amount'])) { + if ($this->request->post['amount'] > 0) { + $this->load->model('extension/payment/cardconnect'); + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']); + + if ($cardconnect_order) { + $capture_response = $this->model_extension_payment_cardconnect->capture($cardconnect_order, $this->request->post['amount']); + + if (!isset($capture_response['retref'])) { + $json['error'] = $this->language->get('error_invalid_response'); + } else if (isset($capture_response['respstat']) && $capture_response['respstat'] == 'C') { + $json['error'] = $capture_response['resptext']; + } else { + $this->model_extension_payment_cardconnect->addTransaction($cardconnect_order['cardconnect_order_id'], 'payment', $capture_response['retref'], $this->request->post['amount'], $capture_response['setlstat']); + + $total_captured = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']); + + $json['retref'] = $capture_response['retref']; + $json['amount'] = $this->currency->format($this->request->post['amount'], $cardconnect_order['currency_code'], false, true); + $json['status'] = $capture_response['setlstat']; + $json['date_modified'] = date($this->language->get('datetime_format')); + $json['date_added'] = date($this->language->get('datetime_format')); + $json['total_captured'] = $this->currency->format($total_captured, $cardconnect_order['currency_code'], false, true); + + $json['success'] = $this->language->get('text_capture_success'); + } + } else { + $json['error'] = $this->language->get('error_no_order'); + } + } else { + $json['error'] = $this->language->get('error_amount_zero'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function refund() { + $this->load->language('extension/payment/cardconnect'); + + $json = array(); + + if ($this->config->get('cardconnect_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['amount'])) { + if ($this->request->post['amount'] > 0) { + $this->load->model('extension/payment/cardconnect'); + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']); + + if ($cardconnect_order) { + $refund_response = $this->model_extension_payment_cardconnect->refund($cardconnect_order, $this->request->post['amount']); + + if (!isset($refund_response['retref'])) { + $json['error'] = $this->language->get('error_invalid_response'); + } else if (isset($refund_response['respstat']) && $refund_response['respstat'] == 'C') { + $json['error'] = $refund_response['resptext']; + } else { + $this->model_extension_payment_cardconnect->addTransaction($cardconnect_order['cardconnect_order_id'], 'refund', $refund_response['retref'], $this->request->post['amount'] * -1, $refund_response['resptext']); + + $total_captured = $this->model_extension_payment_cardconnect->getTotalCaptured($cardconnect_order['cardconnect_order_id']); + + $json['retref'] = $refund_response['retref']; + $json['amount'] = $this->currency->format($this->request->post['amount'] * -1, $cardconnect_order['currency_code'], false, true); + $json['status'] = $refund_response['resptext']; + $json['date_modified'] = date($this->language->get('datetime_format')); + $json['date_added'] = date($this->language->get('datetime_format')); + $json['total_captured'] = $this->currency->format($total_captured, $cardconnect_order['currency_code'], false, true); + + $json['success'] = $this->language->get('text_refund_success'); + } + } else { + $json['error'] = $this->language->get('error_no_order'); + } + } else { + $json['error'] = $this->language->get('error_amount_zero'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function void() { + $this->load->language('extension/payment/cardconnect'); + + $json = array(); + + if ($this->config->get('cardconnect_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['retref'])) { + $this->load->model('extension/payment/cardconnect'); + + $cardconnect_order = $this->model_extension_payment_cardconnect->getOrder($this->request->post['order_id']); + + if ($cardconnect_order) { + $void_response = $this->model_extension_payment_cardconnect->void($cardconnect_order, $this->request->post['retref']); + + if (!isset($void_response['authcode']) || $void_response['authcode'] != 'REVERS') { + $json['error'] = $void_response['resptext']; + } else { + $json['retref'] = $void_response['retref']; + $json['amount'] = $this->currency->format(0.00, $cardconnect_order['currency_code'], false, true); + $json['status'] = $void_response['resptext']; + $json['date_modified'] = date($this->language->get('datetime_format')); + $json['date_added'] = date($this->language->get('datetime_format')); + $json['success'] = $this->language->get('text_void_success'); + } + } else { + $json['error'] = $this->language->get('error_no_order'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/cardconnect')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_cardconnect_merchant_id']) { + $this->error['payment_cardconnect_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['cardconnect_api_username']) { + $this->error['cardconnect_api_username'] = $this->language->get('error_api_username'); + } + + if (!$this->request->post['cardconnect_api_password']) { + $this->error['cardconnect_api_password'] = $this->language->get('error_api_password'); + } + + if (!$this->request->post['cardconnect_token']) { + $this->error['cardconnect_token'] = $this->language->get('error_token'); + } + + if (!$this->request->post['cardconnect_site']) { + $this->error['cardconnect_site'] = $this->language->get('error_site'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/cardinity.php b/public/admin/controller/extension/payment/cardinity.php new file mode 100644 index 0000000..a6beda6 --- /dev/null +++ b/public/admin/controller/extension/payment/cardinity.php @@ -0,0 +1,304 @@ +<?php +class ControllerExtensionPaymentCardinity extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/cardinity'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_cardinity', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/cardinity', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/cardinity', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_cardinity_key'])) { + $data['payment_cardinity_key'] = $this->request->post['payment_cardinity_key']; + } else { + $data['payment_cardinity_key'] = $this->config->get('payment_cardinity_key'); + } + + if (isset($this->request->post['payment_cardinity_secret'])) { + $data['payment_cardinity_secret'] = $this->request->post['payment_cardinity_secret']; + } else { + $data['payment_cardinity_secret'] = $this->config->get('payment_cardinity_secret'); + } + + if (isset($this->request->post['payment_cardinity_debug'])) { + $data['payment_cardinity_debug'] = $this->request->post['payment_cardinity_debug']; + } else { + $data['payment_cardinity_debug'] = $this->config->get('payment_cardinity_debug'); + } + + if (isset($this->request->post['payment_cardinity_total'])) { + $data['payment_cardinity_total'] = $this->request->post['payment_cardinity_total']; + } else { + $data['payment_cardinity_total'] = $this->config->get('payment_cardinity_total'); + } + + if (isset($this->request->post['payment_cardinity_order_status_id'])) { + $data['payment_cardinity_order_status_id'] = $this->request->post['payment_cardinity_order_status_id']; + } else { + $data['payment_cardinity_order_status_id'] = $this->config->get('payment_cardinity_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_cardinity_geo_zone_id'])) { + $data['payment_cardinity_geo_zone_id'] = $this->request->post['payment_cardinity_geo_zone_id']; + } else { + $data['payment_cardinity_geo_zone_id'] = $this->config->get('payment_cardinity_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_cardinity_status'])) { + $data['payment_cardinity_status'] = $this->request->post['payment_cardinity_status']; + } else { + $data['payment_cardinity_status'] = $this->config->get('payment_cardinity_status'); + } + + if (isset($this->request->post['payment_cardinity_sort_order'])) { + $data['payment_cardinity_sort_order'] = $this->request->post['payment_cardinity_sort_order']; + } else { + $data['payment_cardinity_sort_order'] = $this->config->get('payment_cardinity_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/cardinity', $data)); + } + + public function order() { + $this->load->language('extension/payment/cardinity'); + + $data['user_token'] = $this->session->data['user_token']; + $data['order_id'] = $this->request->get['order_id']; + + return $this->load->view('extension/payment/cardinity_order', $data); + } + + public function getPayment() { + $this->load->language('extension/payment/cardinity'); + + $this->load->model('extension/payment/cardinity'); + + $data['column_refund'] = $this->language->get('column_refund'); + $data['column_date'] = $this->language->get('column_date'); + $data['column_refund_history'] = $this->language->get('column_refund_history'); + $data['column_action'] = $this->language->get('column_action'); + $data['column_status'] = $this->language->get('column_status'); + $data['column_amount'] = $this->language->get('column_amount'); + $data['column_description'] = $this->language->get('column_description'); + + $data['button_refund'] = $this->language->get('button_refund'); + + $data['user_token'] = $this->session->data['user_token']; + + $client = $this->model_extension_payment_cardinity->createClient(array( + 'key' => $this->config->get('payment_cardinity_key'), + 'secret' => $this->config->get('payment_cardinity_secret') + )); + + $order = $this->model_extension_payment_cardinity->getOrder($this->request->get['order_id']); + + $data['payment'] = false; + + $data['refunds'] = array(); + + if ($order && $order['payment_id']) { + $data['payment'] = true; + + $payment = $this->model_extension_payment_cardinity->getPayment($client, $order['payment_id']); + + $data['refund_action'] = false; + + $successful_statuses = array( + 'approved' + ); + + if (in_array($payment->getStatus(), $successful_statuses)) { + $data['refund_action'] = true; + } + + $max_refund_amount = $payment->getAmount(); + + $refunds = $this->model_extension_payment_cardinity->getRefunds($client, $order['payment_id']); + + if ($refunds) { + foreach ($refunds as $refund) { + $successful_refund_statuses = array( + 'approved' + ); + + if (in_array($refund->getStatus(), $successful_refund_statuses)) { + $max_refund_amount -= $refund->getAmount(); + } + + $data['refunds'][] = array( + 'date_added' => date($this->language->get('datetime_format'), strtotime($refund->getCreated())), + 'amount' => $this->currency->format($refund->getAmount(), $refund->getCurrency(), '1.00000000', true), + 'status' => $refund->getStatus(), + 'description' => $refund->getDescription() + ); + } + } + + if (!$max_refund_amount) { + $data['refund_action'] = false; + } + + $data['payment_id'] = $payment->getId(); + $data['symbol_left'] = $this->currency->getSymbolLeft($payment->getCurrency()); + $data['symbol_right'] = $this->currency->getSymbolRight($payment->getCurrency()); + + $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $payment->getCurrency(), '1.00000000', false); + } + + $this->response->setOutput($this->load->view('extension/payment/cardinity_order_ajax', $data)); + } + + public function refund() { + $this->load->language('extension/payment/cardinity'); + + $this->load->model('extension/payment/cardinity'); + + $json = array(); + + $success = $error = ''; + + $client = $this->model_extension_payment_cardinity->createClient(array( + 'key' => $this->config->get('payment_cardinity_key'), + 'secret' => $this->config->get('payment_cardinity_secret') + )); + + $refund = $this->model_extension_payment_cardinity->refundPayment($client, $this->request->post['payment_id'], (float)number_format($this->request->post['amount'], 2), $this->request->post['description']); + + if ($refund) { + $success = $this->language->get('text_success_action'); + } else { + $error = $this->language->get('text_error_generic'); + } + + $json['success'] = $success; + $json['error'] = $error; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + $this->load->model('extension/payment/cardinity'); + + $check_credentials = true; + + if (version_compare(phpversion(), '5.4.0', '<')) { + $this->error['warning'] = $this->language->get('error_php_version'); + } + + if (!$this->user->hasPermission('modify', 'extension/payment/cardinity')) { + $this->error['warning'] = $this->language->get('error_permission'); + + $check_credentials = false; + } + + if (!$this->request->post['payment_cardinity_key']) { + $this->error['key'] = $this->language->get('error_key'); + + $check_credentials = false; + } + + if (!$this->request->post['payment_cardinity_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + + $check_credentials = false; + } + + if (!class_exists('Cardinity\Client')) { + $this->error['warning'] = $this->language->get('error_composer'); + + $check_credentials = false; + } + + if ($check_credentials) { + $client = $this->model_extension_payment_cardinity->createClient(array( + 'key' => $this->request->post['payment_cardinity_key'], + 'secret' => $this->request->post['payment_cardinity_secret'] + )); + + $verify_credentials = $this->model_extension_payment_cardinity->verifyCredentials($client); + + if (!$verify_credentials) { + $this->error['warning'] = $this->language->get('error_connection'); + } + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + public function install() { + $this->load->model('extension/payment/cardinity'); + + $this->model_extension_payment_cardinity->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/cardinity'); + + $this->model_extension_payment_cardinity->uninstall(); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/cheque.php b/public/admin/controller/extension/payment/cheque.php new file mode 100644 index 0000000..0b77697 --- /dev/null +++ b/public/admin/controller/extension/payment/cheque.php @@ -0,0 +1,115 @@ +<?php +class ControllerExtensionPaymentCheque extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/cheque'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_cheque', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['payable'])) { + $data['error_payable'] = $this->error['payable']; + } else { + $data['error_payable'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/cheque', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/cheque', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_cheque_payable'])) { + $data['payment_cheque_payable'] = $this->request->post['payment_cheque_payable']; + } else { + $data['payment_cheque_payable'] = $this->config->get('payment_cheque_payable'); + } + + if (isset($this->request->post['payment_cheque_total'])) { + $data['payment_cheque_total'] = $this->request->post['payment_cheque_total']; + } else { + $data['payment_cheque_total'] = $this->config->get('payment_cheque_total'); + } + + if (isset($this->request->post['payment_cheque_order_status_id'])) { + $data['payment_cheque_order_status_id'] = $this->request->post['payment_cheque_order_status_id']; + } else { + $data['payment_cheque_order_status_id'] = $this->config->get('payment_cheque_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_cheque_geo_zone_id'])) { + $data['payment_cheque_geo_zone_id'] = $this->request->post['payment_cheque_geo_zone_id']; + } else { + $data['payment_cheque_geo_zone_id'] = $this->config->get('payment_cheque_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_cheque_status'])) { + $data['payment_cheque_status'] = $this->request->post['payment_cheque_status']; + } else { + $data['payment_cheque_status'] = $this->config->get('payment_cheque_status'); + } + + if (isset($this->request->post['payment_cheque_sort_order'])) { + $data['payment_cheque_sort_order'] = $this->request->post['payment_cheque_sort_order']; + } else { + $data['payment_cheque_sort_order'] = $this->config->get('payment_cheque_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/cheque', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/cheque')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_cheque_payable']) { + $this->error['payable'] = $this->language->get('error_payable'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/cod.php b/public/admin/controller/extension/payment/cod.php new file mode 100644 index 0000000..46c351d --- /dev/null +++ b/public/admin/controller/extension/payment/cod.php @@ -0,0 +1,99 @@ +<?php +class ControllerExtensionPaymentCod extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/cod'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_cod', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/cod', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/cod', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_cod_total'])) { + $data['payment_cod_total'] = $this->request->post['payment_cod_total']; + } else { + $data['payment_cod_total'] = $this->config->get('payment_cod_total'); + } + + if (isset($this->request->post['payment_cod_order_status_id'])) { + $data['payment_cod_order_status_id'] = $this->request->post['payment_cod_order_status_id']; + } else { + $data['payment_cod_order_status_id'] = $this->config->get('payment_cod_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_cod_geo_zone_id'])) { + $data['payment_cod_geo_zone_id'] = $this->request->post['payment_cod_geo_zone_id']; + } else { + $data['payment_cod_geo_zone_id'] = $this->config->get('payment_cod_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_cod_status'])) { + $data['payment_cod_status'] = $this->request->post['payment_cod_status']; + } else { + $data['payment_cod_status'] = $this->config->get('payment_cod_status'); + } + + if (isset($this->request->post['payment_cod_sort_order'])) { + $data['payment_cod_sort_order'] = $this->request->post['payment_cod_sort_order']; + } else { + $data['payment_cod_sort_order'] = $this->config->get('payment_cod_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/cod', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/cod')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/divido.php b/public/admin/controller/extension/payment/divido.php new file mode 100644 index 0000000..d358764 --- /dev/null +++ b/public/admin/controller/extension/payment/divido.php @@ -0,0 +1,215 @@ +<?php +class ControllerExtensionPaymentDivido extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/divido'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + $this->load->model('extension/payment/divido'); + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { + $this->model_setting_setting->editSetting('payment_divido', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['entry_plans_options'] = array( + 'all' => $this->language->get('entry_plans_options_all'), + 'selected' => $this->language->get('entry_plans_options_selected'), + ); + + $data['entry_products_options']= array( + 'all' => $this->language->get('entry_products_options_all'), + 'selected' => $this->language->get('entry_products_options_selected'), + 'threshold' => $this->language->get('entry_products_options_threshold'), + ); + + $data['button_save'] = $this->language->get('button_save'); + $data['button_cancel'] = $this->language->get('button_cancel'); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/divido', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/divido', 'user_token=' . $this->session->data['user_token'], 'SSL'); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', 'SSL'); + + if (isset($this->request->post['payment_divido_api_key'])) { + $data['payment_divido_api_key'] = $this->request->post['payment_divido_api_key']; + } else { + $data['payment_divido_api_key'] = $this->config->get('payment_divido_api_key'); + } + + if (isset($this->request->post['payment_divido_order_status_id'])) { + $data['payment_divido_order_status_id'] = $this->request->post['payment_divido_order_status_id']; + } elseif ($this->config->get('payment_divido_order_status_id')) { + $data['payment_divido_order_status_id'] = $this->config->get('payment_divido_order_status_id'); + } else { + $data['payment_divido_order_status_id'] = 2; + } + + if (isset($this->request->post['payment_divido_status'])) { + $data['payment_divido_status'] = $this->request->post['payment_divido_status']; + } else { + $data['payment_divido_status'] = $this->config->get('payment_divido_status'); + } + + if (isset($this->request->post['payment_divido_sort_order'])) { + $data['payment_divido_sort_order'] = $this->request->post['payment_divido_sort_order']; + } else { + $data['payment_divido_sort_order'] = $this->config->get('payment_divido_sort_order'); + } + + if (isset($this->request->post['payment_divido_title'])) { + $data['payment_divido_title'] = $this->request->post['payment_divido_title']; + } else { + $data['payment_divido_title'] = $this->config->get('payment_divido_title'); + } + + if (isset($this->request->post['payment_divido_productselection'])) { + $data['payment_divido_productselection'] = $this->request->post['payment_divido_productselection']; + } else { + $data['payment_divido_productselection'] = $this->config->get('payment_divido_productselection'); + } + + if (isset($this->request->post['payment_divido_price_threshold'])) { + $data['payment_divido_price_threshold'] = $this->request->post['payment_divido_price_threshold']; + } else { + $data['payment_divido_price_threshold'] = $this->config->get('payment_divido_price_threshold'); + } + + if (isset($this->request->post['payment_divido_cart_threshold'])) { + $data['payment_divido_cart_threshold'] = $this->request->post['payment_divido_cart_threshold']; + } else { + $data['payment_divido_cart_threshold'] = $this->config->get('payment_divido_cart_threshold'); + } + + if (isset($this->request->post['payment_divido_planselection'])) { + $data['payment_divido_planselection'] = $this->request->post['payment_divido_planselection']; + } else { + $data['payment_divido_planselection'] = $this->config->get('payment_divido_planselection'); + } + + if (isset($this->request->post['payment_divido_plans_selected'])) { + $data['payment_divido_plans_selected'] = $this->request->post['payment_divido_plans_selected']; + } elseif ($this->config->get('payment_divido_plans_selected')) { + $data['payment_divido_plans_selected'] = $this->config->get('payment_divido_plans_selected'); + } else { + $data['payment_divido_plans_selected'] = array(); + } + + if (isset($this->request->post['payment_divido_categories'])) { + $data['payment_divido_categories'] = $this->request->post['payment_divido_categories']; + } elseif ($this->config->get('payment_divido_categories')) { + $data['payment_divido_categories'] = $this->config->get('payment_divido_categories'); + } else { + $data['payment_divido_categories'] = array(); + } + + $data['categories'] = array(); + + $this->load->model('catalog/category'); + + foreach ($data['payment_divido_categories'] as $category_id) { + $category_info = $this->model_catalog_category->getCategory($category_id); + + if ($category_info) { + $data['categories'][] = array( + 'category_id' => $category_info['category_id'], + 'name' => ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name'] + ); + } + } + + try { + $data['divido_plans'] = $this->model_extension_payment_divido->getAllPlans(); + } catch (Exception $e) { + $this->log->write($e->getMessage()); + $data['divido_plans'] = array(); + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/divido', $data)); + } + + + public function order() { + if (!$this->config->get('payment_divido_status')) { + return null; + } + + $this->load->model('extension/payment/divido'); + $this->load->language('extension/payment/divido'); + + $order_id = $this->request->get['order_id']; + + $lookup = $this->model_extension_payment_divido->getLookupByOrderId($order_id); + $proposal_id = null; + $application_id = null; + $deposit_amount = null; + if ($lookup->num_rows == 1) { + $lookup_data = $lookup->row; + $proposal_id = $lookup_data['proposal_id']; + $application_id = $lookup_data['application_id']; + $deposit_amount = $lookup_data['deposit_amount']; + } + + $data['proposal_id'] = $proposal_id; + $data['application_id'] = $application_id; + $data['deposit_amount'] = $deposit_amount; + + return $this->load->view('extension/payment/divido_order', $data); + } + + public function install() { + $this->load->model('extension/payment/divido'); + $this->model_extension_payment_divido->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/divido'); + $this->model_extension_payment_divido->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/divido')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/eway.php b/public/admin/controller/extension/payment/eway.php new file mode 100644 index 0000000..26f8c43 --- /dev/null +++ b/public/admin/controller/extension/payment/eway.php @@ -0,0 +1,371 @@ +<?php +class ControllerExtensionPaymentEway extends Controller { + + private $error = array(); + + public function index() { + $this->load->language('extension/payment/eway'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) { + $this->model_setting_setting->editSetting('payment_eway', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['payment_type'])) { + $data['error_payment_type'] = $this->error['payment_type']; + } else { + $data['error_payment_type'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/eway', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/eway', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['payment_eway_payment_gateway'])) { + $data['payment_eway_payment_gateway'] = $this->request->post['payment_eway_payment_gateway']; + } else { + $data['payment_eway_payment_gateway'] = $this->config->get('payment_eway_payment_gateway'); + } + + if (isset($this->request->post['payment_eway_paymode'])) { + $data['payment_eway_paymode'] = $this->request->post['payment_eway_paymode']; + } else { + $data['payment_eway_paymode'] = $this->config->get('payment_eway_paymode'); + } + + if (isset($this->request->post['payment_eway_test'])) { + $data['payment_eway_test'] = $this->request->post['payment_eway_test']; + } else { + $data['payment_eway_test'] = $this->config->get('payment_eway_test'); + } + + if (isset($this->request->post['payment_eway_payment_type'])) { + $data['payment_eway_payment_type'] = $this->request->post['payment_eway_payment_type']; + } else { + $data['payment_eway_payment_type'] = $this->config->get('payment_eway_payment_type'); + } + + if (isset($this->request->post['payment_eway_transaction'])) { + $data['payment_eway_transaction'] = $this->request->post['payment_eway_transaction']; + } else { + $data['payment_eway_transaction'] = $this->config->get('payment_eway_transaction'); + } + + if (isset($this->request->post['payment_eway_standard_geo_zone_id'])) { + $data['payment_eway_standard_geo_zone_id'] = $this->request->post['payment_eway_standard_geo_zone_id']; + } else { + $data['payment_eway_standard_geo_zone_id'] = $this->config->get('payment_eway_standard_geo_zone_id'); + } + + if (isset($this->request->post['payment_eway_order_status_id'])) { + $data['payment_eway_order_status_id'] = $this->request->post['payment_eway_order_status_id']; + } else { + $data['payment_eway_order_status_id'] = $this->config->get('payment_eway_order_status_id'); + } + + if (isset($this->request->post['payment_eway_order_status_refunded_id'])) { + $data['payment_eway_order_status_refunded_id'] = $this->request->post['payment_eway_order_status_refunded_id']; + } else { + $data['payment_eway_order_status_refunded_id'] = $this->config->get('payment_eway_order_status_refunded_id'); + } + + if (isset($this->request->post['payment_eway_order_status_auth_id'])) { + $data['payment_eway_order_status_auth_id'] = $this->request->post['payment_eway_order_status_auth_id']; + } else { + $data['payment_eway_order_status_auth_id'] = $this->config->get('payment_eway_order_status_auth_id'); + } + + if (isset($this->request->post['payment_eway_order_status_fraud_id'])) { + $data['payment_eway_order_status_fraud_id'] = $this->request->post['payment_eway_order_status_fraud_id']; + } else { + $data['payment_eway_order_status_fraud_id'] = $this->config->get('payment_eway_order_status_fraud_id'); + } + + if (isset($this->request->post['payment_eway_transaction_method'])) { + $data['payment_eway_transaction_method'] = $this->request->post['payment_eway_transaction_method']; + } else { + $data['payment_eway_transaction_method'] = $this->config->get('payment_eway_transaction_method'); + } + + if (isset($this->request->post['payment_eway_username'])) { + $data['payment_eway_username'] = $this->request->post['payment_eway_username']; + } else { + $data['payment_eway_username'] = $this->config->get('payment_eway_username'); + } + + if (isset($this->request->post['payment_eway_password'])) { + $data['payment_eway_password'] = $this->request->post['payment_eway_password']; + } else { + $data['payment_eway_password'] = $this->config->get('payment_eway_password'); + } + + if (isset($this->request->post['payment_eway_status'])) { + $data['payment_eway_status'] = $this->request->post['payment_eway_status']; + } else { + $data['payment_eway_status'] = $this->config->get('payment_eway_status'); + } + + if (isset($this->request->post['payment_eway_sort_order'])) { + $data['payment_eway_sort_order'] = $this->request->post['payment_eway_sort_order']; + } else { + $data['payment_eway_sort_order'] = $this->config->get('payment_eway_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/eway', $data)); + } + + public function install() { + $this->load->model('extension/payment/eway'); + $this->model_extension_payment_eway->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/eway'); + $this->model_extension_payment_eway->uninstall(); + } + + // Legacy 2.0.0 + public function orderAction() { + return $this->order(); + } + + // Legacy 2.0.3 + public function action() { + return $this->order(); + } + + public function order() { + if ($this->config->get('payment_eway_status')) { + $this->load->model('extension/payment/eway'); + + $eway_order = $this->model_extension_payment_eway->getOrder($this->request->get['order_id']); + + if (!empty($eway_order)) { + $this->load->language('extension/payment/eway'); + + $eway_order['total'] = $eway_order['amount']; + $eway_order['total_formatted'] = $this->currency->format($eway_order['amount'], $eway_order['currency_code'], 1, true); + + $eway_order['total_captured'] = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']); + $eway_order['total_captured_formatted'] = $this->currency->format($eway_order['total_captured'], $eway_order['currency_code'], 1, true); + + $eway_order['uncaptured'] = $eway_order['total'] - $eway_order['total_captured']; + + $eway_order['total_refunded'] = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']); + $eway_order['total_refunded_formatted'] = $this->currency->format($eway_order['total_refunded'], $eway_order['currency_code'], 1, true); + + $eway_order['unrefunded'] = $eway_order['total_captured'] - $eway_order['total_refunded']; + + $data['text_payment_info'] = $this->language->get('text_payment_info'); + $data['text_order_total'] = $this->language->get('text_order_total'); + $data['text_void_status'] = $this->language->get('text_void_status'); + $data['text_transactions'] = $this->language->get('text_transactions'); + $data['text_column_amount'] = $this->language->get('text_column_amount'); + $data['text_column_type'] = $this->language->get('text_column_type'); + $data['text_column_created'] = $this->language->get('text_column_created'); + $data['text_column_transactionid'] = $this->language->get('text_column_transactionid'); + $data['btn_refund'] = $this->language->get('btn_refund'); + $data['btn_capture'] = $this->language->get('btn_capture'); + $data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); + $data['text_confirm_capture'] = $this->language->get('text_confirm_capture'); + + $data['text_total_captured'] = $this->language->get('text_total_captured'); + $data['text_total_refunded'] = $this->language->get('text_total_refunded'); + $data['text_capture_status'] = $this->language->get('text_capture_status'); + $data['text_refund_status'] = $this->language->get('text_refund_status'); + + $data['text_empty_refund'] = $this->language->get('text_empty_refund'); + $data['text_empty_capture'] = $this->language->get('text_empty_capture'); + + $data['eway_order'] = $eway_order; + $data['user_token'] = $this->request->get['user_token']; + $data['order_id'] = $this->request->get['order_id']; + + return $this->load->view('extension/payment/eway_order', $data); + } + } + } + + public function refund() { + $this->load->language('extension/payment/eway'); + + $order_id = $this->request->post['order_id']; + $refund_amount = (double)$this->request->post['refund_amount']; + + if ($order_id && $refund_amount > 0) { + $this->load->model('extension/payment/eway'); + $result = $this->model_extension_payment_eway->refund($order_id, $refund_amount); + + // Check if any error returns + if (isset($result->Errors) || $result === false) { + $json['error'] = true; + $reason = ''; + if ($result === false) { + $reason = $this->language->get('text_unknown_failure'); + } else { + $errors = explode(',', $result->Errors); + foreach ($errors as $error) { + $reason .= $this->language->get('text_card_message_' . $result->Errors); + } + } + $json['message'] = $this->language->get('text_refund_failed') . $reason; + } else { + $eway_order = $this->model_extension_payment_eway->getOrder($order_id); + $this->model_extension_payment_eway->addTransaction($eway_order['eway_order_id'], $result->Refund->TransactionID, 'refund', $result->Refund->TotalAmount / 100, $eway_order['currency_code']); + + $total_captured = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']); + $total_refunded = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']); + $refund_status = 0; + + if ($total_captured == $total_refunded) { + $refund_status = 1; + $this->model_extension_payment_eway->updateRefundStatus($eway_order['eway_order_id'], $refund_status); + } + + $json['data'] = array(); + $json['data']['transactionid'] = $result->TransactionID; + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = number_format($refund_amount, 2, '.', ''); + $json['data']['total_refunded_formatted'] = $this->currency->format($total_refunded, $eway_order['currency_code'], 1, true); + $json['data']['refund_status'] = $refund_status; + $json['data']['remaining'] = $total_captured - $total_refunded; + $json['message'] = $this->language->get('text_refund_success'); + $json['error'] = false; + } + } else { + $json['error'] = true; + $json['message'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/eway'); + + $order_id = $this->request->post['order_id']; + $capture_amount = (double)$this->request->post['capture_amount']; + + if ($order_id && $capture_amount > 0) { + $this->load->model('extension/payment/eway'); + $eway_order = $this->model_extension_payment_eway->getOrder($order_id); + $result = $this->model_extension_payment_eway->capture($order_id, $capture_amount, $eway_order['currency_code']); + + // Check if any error returns + if (isset($result->Errors) || $result === false) { + $json['error'] = true; + $reason = ''; + if ($result === false) { + $reason = $this->language->get('text_unknown_failure'); + } else { + $errors = explode(',', $result->Errors); + foreach ($errors as $error) { + $reason .= $this->language->get('text_card_message_' . $result->Errors); + } + } + $json['message'] = $this->language->get('text_capture_failed') . $reason; + } else { + $this->model_extension_payment_eway->addTransaction($eway_order['eway_order_id'], $result->TransactionID, 'payment', $capture_amount, $eway_order['currency_code']); + + $total_captured = $this->model_extension_payment_eway->getTotalCaptured($eway_order['eway_order_id']); + $total_refunded = $this->model_extension_payment_eway->getTotalRefunded($eway_order['eway_order_id']); + + $remaining = $eway_order['amount'] - $capture_amount; + if ($remaining <= 0) { + $remaining = 0; + } + + $this->model_extension_payment_eway->updateCaptureStatus($eway_order['eway_order_id'], 1); + $this->model_extension_payment_eway->updateTransactionId($eway_order['eway_order_id'], $result->TransactionID); + + $json['data'] = array(); + $json['data']['transactionid'] = $result->TransactionID; + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = number_format($capture_amount, 2, '.', ''); + $json['data']['total_captured_formatted'] = $this->currency->format($total_captured, $eway_order['currency_code'], 1, true); + $json['data']['capture_status'] = 1; + $json['data']['remaining'] = $remaining; + $json['message'] = $this->language->get('text_capture_success'); + $json['error'] = false; + } + } else { + $json['error'] = true; + $json['message'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/eway')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + if (!$this->request->post['payment_eway_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + if (!$this->request->post['payment_eway_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + if (!isset($this->request->post['payment_eway_payment_type'])) { + $this->error['payment_type'] = $this->language->get('error_payment_type'); + } + + return !$this->error; + } + +} diff --git a/public/admin/controller/extension/payment/firstdata.php b/public/admin/controller/extension/payment/firstdata.php new file mode 100644 index 0000000..66f33f7 --- /dev/null +++ b/public/admin/controller/extension/payment/firstdata.php @@ -0,0 +1,352 @@ +<?php +class ControllerExtensionPaymentFirstdata extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/firstdata'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_firstdata', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/firstdata/notify'; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + if (isset($this->error['error_live_url'])) { + $data['error_live_url'] = $this->error['error_live_url']; + } else { + $data['error_live_url'] = ''; + } + + if (isset($this->error['error_demo_url'])) { + $data['error_demo_url'] = $this->error['error_demo_url']; + } else { + $data['error_demo_url'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/firstdata', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/firstdata', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_firstdata_merchant_id'])) { + $data['payment_firstdata_merchant_id'] = $this->request->post['payment_firstdata_merchant_id']; + } else { + $data['payment_firstdata_merchant_id'] = $this->config->get('payment_firstdata_merchant_id'); + } + + if (isset($this->request->post['payment_firstdata_secret'])) { + $data['payment_firstdata_secret'] = $this->request->post['payment_firstdata_secret']; + } else { + $data['payment_firstdata_secret'] = $this->config->get('payment_firstdata_secret'); + } + + if (isset($this->request->post['payment_firstdata_live_demo'])) { + $data['payment_firstdata_live_demo'] = $this->request->post['payment_firstdata_live_demo']; + } else { + $data['payment_firstdata_live_demo'] = $this->config->get('payment_firstdata_live_demo'); + } + + if (isset($this->request->post['payment_firstdata_geo_zone_id'])) { + $data['payment_firstdata_geo_zone_id'] = $this->request->post['payment_firstdata_geo_zone_id']; + } else { + $data['payment_firstdata_geo_zone_id'] = $this->config->get('payment_firstdata_geo_zone_id'); + } + + if (isset($this->request->post['payment_firstdata_total'])) { + $data['payment_firstdata_total'] = $this->request->post['payment_firstdata_total']; + } else { + $data['payment_firstdata_total'] = $this->config->get('payment_firstdata_total'); + } + + if (isset($this->request->post['payment_firstdata_sort_order'])) { + $data['payment_firstdata_sort_order'] = $this->request->post['payment_firstdata_sort_order']; + } else { + $data['payment_firstdata_sort_order'] = $this->config->get('payment_firstdata_sort_order'); + } + + if (isset($this->request->post['payment_firstdata_status'])) { + $data['payment_firstdata_status'] = $this->request->post['payment_firstdata_status']; + } else { + $data['payment_firstdata_status'] = $this->config->get('payment_firstdata_status'); + } + + if (isset($this->request->post['payment_firstdata_debug'])) { + $data['payment_firstdata_debug'] = $this->request->post['payment_firstdata_debug']; + } else { + $data['payment_firstdata_debug'] = $this->config->get('payment_firstdata_debug'); + } + + if (isset($this->request->post['payment_firstdata_auto_settle'])) { + $data['payment_firstdata_auto_settle'] = $this->request->post['payment_firstdata_auto_settle']; + } elseif (!isset($this->request->post['payment_firstdata_auto_settle']) && $this->config->get('payment_firstdata_auto_settle') != '') { + $data['payment_firstdata_auto_settle'] = $this->config->get('payment_firstdata_auto_settle'); + } else { + $data['payment_firstdata_auto_settle'] = 1; + } + + if (isset($this->request->post['payment_firstdata_order_status_success_settled_id'])) { + $data['payment_firstdata_order_status_success_settled_id'] = $this->request->post['payment_firstdata_order_status_success_settled_id']; + } else { + $data['payment_firstdata_order_status_success_settled_id'] = $this->config->get('payment_firstdata_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_firstdata_order_status_success_unsettled_id'])) { + $data['payment_firstdata_order_status_success_unsettled_id'] = $this->request->post['payment_firstdata_order_status_success_unsettled_id']; + } else { + $data['payment_firstdata_order_status_success_unsettled_id'] = $this->config->get('payment_firstdata_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_firstdata_order_status_decline_id'])) { + $data['payment_firstdata_order_status_decline_id'] = $this->request->post['payment_firstdata_order_status_decline_id']; + } else { + $data['payment_firstdata_order_status_decline_id'] = $this->config->get('payment_firstdata_order_status_decline_id'); + } + + if (isset($this->request->post['payment_firstdata_order_status_void_id'])) { + $data['payment_firstdata_order_status_void_id'] = $this->request->post['payment_firstdata_order_status_void_id']; + } else { + $data['payment_firstdata_order_status_void_id'] = $this->config->get('payment_firstdata_order_status_void_id'); + } + + if (isset($this->request->post['payment_firstdata_live_url'])) { + $data['payment_firstdata_live_url'] = $this->request->post['payment_firstdata_live_url']; + } else { + $data['payment_firstdata_live_url'] = $this->config->get('payment_firstdata_live_url'); + } + + if (empty($data['payment_firstdata_live_url'])) { + $data['payment_firstdata_live_url'] = 'https://ipg-online.com/connect/gateway/processing'; + } + + if (isset($this->request->post['payment_firstdata_demo_url'])) { + $data['payment_firstdata_demo_url'] = $this->request->post['payment_firstdata_demo_url']; + } else { + $data['payment_firstdata_demo_url'] = $this->config->get('payment_firstdata_demo_url'); + } + + if (isset($this->request->post['payment_firstdata_card_storage'])) { + $data['payment_firstdata_card_storage'] = $this->request->post['payment_firstdata_card_storage']; + } else { + $data['payment_firstdata_card_storage'] = $this->config->get('payment_firstdata_card_storage'); + } + + if (empty($data['payment_firstdata_demo_url'])) { + $data['payment_firstdata_demo_url'] = 'https://test.ipg-online.com/connect/gateway/processing'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/firstdata', $data)); + } + + public function install() { + $this->load->model('extension/payment/firstdata'); + $this->model_extension_payment_firstdata->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/firstdata'); + $this->model_extension_payment_firstdata->uninstall(); + } + + public function order() { + if ($this->config->get('payment_firstdata_status')) { + $this->load->model('extension/payment/firstdata'); + + $firstdata_order = $this->model_extension_payment_firstdata->getOrder($this->request->get['order_id']); + + if (!empty($firstdata_order)) { + $this->load->language('extension/payment/firstdata'); + + $firstdata_order['total_captured'] = $this->model_extension_payment_firstdata->getTotalCaptured($firstdata_order['firstdata_order_id']); + $firstdata_order['total_formatted'] = $this->currency->format($firstdata_order['total'], $firstdata_order['currency_code'], 1, true); + $firstdata_order['total_captured_formatted'] = $this->currency->format($firstdata_order['total_captured'], $firstdata_order['currency_code'], 1, true); + + $data['firstdata_order'] = $firstdata_order; + $data['merchant_id'] = $this->config->get('payment_firstdata_merchant_id'); + $data['currency'] = $this->model_extension_payment_firstdata->mapCurrency($firstdata_order['currency_code']); + $data['amount'] = number_format($firstdata_order['total'], 2); + + $data['request_timestamp'] = date("Y:m:d-H:i:s"); + + $data['hash'] = sha1(bin2hex($data['merchant_id'] . $data['request_timestamp'] . $data['amount'] . $data['currency'] . $this->config->get('payment_firstdata_secret'))); + + $data['void_url'] = $this->url->link('extension/payment/firstdata/void', 'user_token=' . $this->session->data['user_token'], true); + $data['capture_url'] = $this->url->link('extension/payment/firstdata/capture', 'user_token=' . $this->session->data['user_token'], true); + $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/firstdata/notify'; + + if ($this->config->get('payment_firstdata_live_demo') == 1) { + $data['action_url'] = $this->config->get('payment_firstdata_live_url'); + } else { + $data['action_url'] = $this->config->get('payment_firstdata_demo_url'); + } + + if (isset($this->session->data['void_success'])) { + $data['void_success'] = $this->session->data['void_success']; + + unset($this->session->data['void_success']); + } else { + $data['void_success'] = ''; + } + + if (isset($this->session->data['void_error'])) { + $data['void_error'] = $this->session->data['void_error']; + + unset($this->session->data['void_error']); + } else { + $data['void_error'] = ''; + } + + if (isset($this->session->data['capture_success'])) { + $data['capture_success'] = $this->session->data['capture_success']; + + unset($this->session->data['capture_success']); + } else { + $data['capture_success'] = ''; + } + + if (isset($this->session->data['capture_error'])) { + $data['capture_error'] = $this->session->data['capture_error']; + + unset($this->session->data['capture_error']); + } else { + $data['capture_error'] = ''; + } + + $data['text_payment_info'] = $this->language->get('text_payment_info'); + $data['text_order_ref'] = $this->language->get('text_order_ref'); + $data['text_order_total'] = $this->language->get('text_order_total'); + $data['text_total_captured'] = $this->language->get('text_total_captured'); + $data['text_capture_status'] = $this->language->get('text_capture_status'); + $data['text_void_status'] = $this->language->get('text_void_status'); + $data['text_transactions'] = $this->language->get('text_transactions'); + $data['text_yes'] = $this->language->get('text_yes'); + $data['text_no'] = $this->language->get('text_no'); + $data['text_column_amount'] = $this->language->get('text_column_amount'); + $data['text_column_type'] = $this->language->get('text_column_type'); + $data['text_column_date_added'] = $this->language->get('text_column_date_added'); + $data['button_capture'] = $this->language->get('button_capture'); + $data['button_void'] = $this->language->get('button_void'); + $data['text_confirm_void'] = $this->language->get('text_confirm_void'); + $data['text_confirm_capture'] = $this->language->get('text_confirm_capture'); + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/firstdata_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/firstdata'); + + if ($this->request->post['status'] == 'FAILED') { + if (isset($this->request->post['fail_reason'])) { + $this->session->data['void_error'] = $this->request->post['fail_reason']; + } else { + $this->session->data['void_error'] = $this->language->get('error_void_error'); + } + } + + if ($this->request->post['status'] == 'DECLINED') { + $this->session->data['void_success'] = $this->language->get('success_void'); + } + + $this->response->redirect($this->url->link('sale/order/info', 'order_id=' . $this->request->post['order_id'] . '&user_token=' . $this->session->data['user_token'], true)); + } + + public function capture() { + $this->load->language('extension/payment/firstdata'); + + if ($this->request->post['status'] == 'FAILED') { + if (isset($this->request->post['fail_reason'])) { + $this->session->data['capture_error'] = $this->request->post['fail_reason']; + } else { + $this->session->data['capture_error'] = $this->language->get('error_capture_error'); + } + } + + if ($this->request->post['status'] == 'APPROVED') { + $this->session->data['capture_success'] = $this->language->get('success_capture'); + } + + $this->response->redirect($this->url->link('sale/order/info', 'order_id=' . $this->request->post['order_id'] . '&user_token=' . $this->session->data['user_token'], true)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/firstdata')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_firstdata_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_firstdata_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + if (!$this->request->post['payment_firstdata_live_url']) { + $this->error['error_live_url'] = $this->language->get('error_live_url'); + } + + if (!$this->request->post['payment_firstdata_demo_url']) { + $this->error['error_demo_url'] = $this->language->get('error_demo_url'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/firstdata_remote.php b/public/admin/controller/extension/payment/firstdata_remote.php new file mode 100644 index 0000000..1380a1b --- /dev/null +++ b/public/admin/controller/extension/payment/firstdata_remote.php @@ -0,0 +1,482 @@ +<?php +class ControllerExtensionPaymentFirstdataRemote extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/firstdata_remote'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_firstdata_remote', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_user_id'])) { + $data['error_user_id'] = $this->error['error_user_id']; + } else { + $data['error_user_id'] = ''; + } + + if (isset($this->error['error_password'])) { + $data['error_password'] = $this->error['error_password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['error_certificate'])) { + $data['error_certificate'] = $this->error['error_certificate']; + } else { + $data['error_certificate'] = ''; + } + + if (isset($this->error['error_key'])) { + $data['error_key'] = $this->error['error_key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['error_key_pw'])) { + $data['error_key_pw'] = $this->error['error_key_pw']; + } else { + $data['error_key_pw'] = ''; + } + + if (isset($this->error['error_ca'])) { + $data['error_ca'] = $this->error['error_ca']; + } else { + $data['error_ca'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/firstdata_remote', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['action'] = $this->url->link('extension/payment/firstdata_remote', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['firstdata_remote_merchant_id'])) { + $data['firstdata_remote_merchant_id'] = $this->request->post['firstdata_remote_merchant_id']; + } else { + $data['firstdata_remote_merchant_id'] = $this->config->get('firstdata_remote_merchant_id'); + } + + if (isset($this->request->post['firstdata_remote_user_id'])) { + $data['firstdata_remote_user_id'] = $this->request->post['firstdata_remote_user_id']; + } else { + $data['firstdata_remote_user_id'] = $this->config->get('firstdata_remote_user_id'); + } + + if (isset($this->request->post['firstdata_remote_password'])) { + $data['firstdata_remote_password'] = $this->request->post['firstdata_remote_password']; + } else { + $data['firstdata_remote_password'] = $this->config->get('firstdata_remote_password'); + } + + if (isset($this->request->post['firstdata_remote_certificate'])) { + $data['firstdata_remote_certificate'] = $this->request->post['firstdata_remote_certificate']; + } else { + $data['firstdata_remote_certificate'] = $this->config->get('firstdata_remote_certificate'); + } + + if (isset($this->request->post['firstdata_remote_key'])) { + $data['firstdata_remote_key'] = $this->request->post['firstdata_remote_key']; + } else { + $data['firstdata_remote_key'] = $this->config->get('firstdata_remote_key'); + } + + if (isset($this->request->post['firstdata_remote_key_pw'])) { + $data['firstdata_remote_key_pw'] = $this->request->post['firstdata_remote_key_pw']; + } else { + $data['firstdata_remote_key_pw'] = $this->config->get('firstdata_remote_key_pw'); + } + + if (isset($this->request->post['firstdata_remote_ca'])) { + $data['firstdata_remote_ca'] = $this->request->post['firstdata_remote_ca']; + } else { + $data['firstdata_remote_ca'] = $this->config->get('firstdata_remote_ca'); + } + + if (isset($this->request->post['firstdata_remote_geo_zone_id'])) { + $data['firstdata_remote_geo_zone_id'] = $this->request->post['firstdata_remote_geo_zone_id']; + } else { + $data['firstdata_remote_geo_zone_id'] = $this->config->get('firstdata_remote_geo_zone_id'); + } + + if (isset($this->request->post['firstdata_remote_total'])) { + $data['firstdata_remote_total'] = $this->request->post['firstdata_remote_total']; + } else { + $data['firstdata_remote_total'] = $this->config->get('firstdata_remote_total'); + } + + if (isset($this->request->post['firstdata_remote_sort_order'])) { + $data['firstdata_remote_sort_order'] = $this->request->post['firstdata_remote_sort_order']; + } else { + $data['firstdata_remote_sort_order'] = $this->config->get('firstdata_remote_sort_order'); + } + + if (isset($this->request->post['firstdata_remote_status'])) { + $data['firstdata_remote_status'] = $this->request->post['firstdata_remote_status']; + } else { + $data['firstdata_remote_status'] = $this->config->get('firstdata_remote_status'); + } + + if (isset($this->request->post['firstdata_remote_debug'])) { + $data['firstdata_remote_debug'] = $this->request->post['firstdata_remote_debug']; + } else { + $data['firstdata_remote_debug'] = $this->config->get('firstdata_remote_debug'); + } + if (isset($this->request->post['firstdata_remote_auto_settle'])) { + $data['firstdata_remote_auto_settle'] = $this->request->post['firstdata_remote_auto_settle']; + } elseif (!isset($this->request->post['payment_firstdata_auto_settle']) && $this->config->get('firstdata_remote_auto_settle') != '') { + $data['firstdata_remote_auto_settle'] = $this->config->get('firstdata_remote_auto_settle'); + } else { + $data['firstdata_remote_auto_settle'] = 1; + } + + if (isset($this->request->post['firstdata_remote_3d'])) { + $data['firstdata_remote_3d'] = $this->request->post['firstdata_remote_3d']; + } else { + $data['firstdata_remote_3d'] = $this->config->get('firstdata_remote_3d'); + } + + if (isset($this->request->post['firstdata_remote_liability'])) { + $data['firstdata_remote_liability'] = $this->request->post['firstdata_remote_liability']; + } else { + $data['firstdata_remote_liability'] = $this->config->get('firstdata_remote_liability'); + } + + if (isset($this->request->post['firstdata_remote_order_status_success_settled_id'])) { + $data['firstdata_remote_order_status_success_settled_id'] = $this->request->post['firstdata_remote_order_status_success_settled_id']; + } else { + $data['firstdata_remote_order_status_success_settled_id'] = $this->config->get('firstdata_remote_order_status_success_settled_id'); + } + + if (isset($this->request->post['firstdata_remote_order_status_success_unsettled_id'])) { + $data['firstdata_remote_order_status_success_unsettled_id'] = $this->request->post['firstdata_remote_order_status_success_unsettled_id']; + } else { + $data['firstdata_remote_order_status_success_unsettled_id'] = $this->config->get('firstdata_remote_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['firstdata_remote_order_status_decline_id'])) { + $data['firstdata_remote_order_status_decline_id'] = $this->request->post['firstdata_remote_order_status_decline_id']; + } else { + $data['firstdata_remote_order_status_decline_id'] = $this->config->get('firstdata_remote_order_status_decline_id'); + } + + if (isset($this->request->post['firstdata_remote_order_status_void_id'])) { + $data['firstdata_remote_order_status_void_id'] = $this->request->post['firstdata_remote_order_status_void_id']; + } else { + $data['firstdata_remote_order_status_void_id'] = $this->config->get('firstdata_remote_order_status_void_id'); + } + + if (isset($this->request->post['firstdata_remote_order_status_refunded_id'])) { + $data['firstdata_remote_order_status_refunded_id'] = $this->request->post['firstdata_remote_order_status_refunded_id']; + } else { + $data['firstdata_remote_order_status_refunded_id'] = $this->config->get('firstdata_remote_order_status_refunded_id'); + } + + if (isset($this->request->post['firstdata_remote_card_storage'])) { + $data['firstdata_remote_card_storage'] = $this->request->post['firstdata_remote_card_storage']; + } else { + $data['firstdata_remote_card_storage'] = $this->config->get('firstdata_remote_card_storage'); + } + + $data['cards'] = array(); + + $data['cards'][] = array( + 'text' => $this->language->get('text_mastercard'), + 'value' => 'mastercard' + ); + + $data['cards'][] = array( + 'text' => $this->language->get('text_visa'), + 'value' => 'visa' + ); + + $data['cards'][] = array( + 'text' => $this->language->get('text_diners'), + 'value' => 'diners' + ); + + $data['cards'][] = array( + 'text' => $this->language->get('text_amex'), + 'value' => 'amex' + ); + + $data['cards'][] = array( + 'text' => $this->language->get('text_maestro'), + 'value' => 'maestro' + ); + + if (isset($this->request->post['firstdata_remote_cards_accepted'])) { + $data['firstdata_remote_cards_accepted'] = $this->request->post['firstdata_remote_cards_accepted']; + } elseif ($this->config->get('firstdata_remote_cards_accepted')) { + $data['firstdata_remote_cards_accepted'] = $this->config->get('firstdata_remote_cards_accepted'); + } else { + $data['firstdata_remote_cards_accepted'] = array(); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/firstdata_remote', $data)); + } + + public function install() { + $this->load->model('extension/payment/firstdata_remote'); + $this->model_extension_payment_firstdata_remote->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/firstdata_remote'); + $this->model_extension_payment_firstdata_remote->uninstall(); + } + + public function order() { + if ($this->config->get('firstdata_remote_status')) { + $this->load->model('extension/payment/firstdata_remote'); + + $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->get['order_id']); + + if (!empty($firstdata_order)) { + $this->load->language('extension/payment/firstdata_remote'); + + $firstdata_order['total_captured'] = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); + + $firstdata_order['total_formatted'] = $this->currency->format($firstdata_order['total'], $firstdata_order['currency_code'], 1, true); + $firstdata_order['total_captured_formatted'] = $this->currency->format($firstdata_order['total_captured'], $firstdata_order['currency_code'], 1, true); + + $data['firstdata_order'] = $firstdata_order; + + $data['text_payment_info'] = $this->language->get('text_payment_info'); + $data['text_order_ref'] = $this->language->get('text_order_ref'); + $data['text_order_total'] = $this->language->get('text_order_total'); + $data['text_total_captured'] = $this->language->get('text_total_captured'); + $data['text_capture_status'] = $this->language->get('text_capture_status'); + $data['text_void_status'] = $this->language->get('text_void_status'); + $data['text_refund_status'] = $this->language->get('text_refund_status'); + $data['text_transactions'] = $this->language->get('text_transactions'); + $data['text_yes'] = $this->language->get('text_yes'); + $data['text_no'] = $this->language->get('text_no'); + $data['text_column_amount'] = $this->language->get('text_column_amount'); + $data['text_column_type'] = $this->language->get('text_column_type'); + $data['text_column_date_added'] = $this->language->get('text_column_date_added'); + $data['text_confirm_void'] = $this->language->get('text_confirm_void'); + $data['text_confirm_capture'] = $this->language->get('text_confirm_capture'); + $data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); + + $data['button_capture'] = $this->language->get('button_capture'); + $data['button_refund'] = $this->language->get('button_refund'); + $data['button_void'] = $this->language->get('button_void'); + + $data['order_id'] = $this->request->get['order_id']; + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/firstdata_remote_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/firstdata_remote'); + + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/firstdata_remote'); + + $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_firstdata_remote->void($firstdata_order['order_ref'], $firstdata_order['tdate']); + + $this->model_extension_payment_firstdata_remote->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (strtoupper($void_response['transaction_result']) == 'APPROVED') { + $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'void', 0.00); + + $this->model_extension_payment_firstdata_remote->updateVoidStatus($firstdata_order['firstdata_remote_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['column_date_added'] = date('Y-m-d H:i:s'); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['error']) && !empty($void_response['error']) ? (string)$void_response['error'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/firstdata'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/firstdata_remote'); + + $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_firstdata_remote->capture($firstdata_order['order_ref'], $firstdata_order['total'], $firstdata_order['currency_code']); + + $this->model_extension_payment_firstdata_remote->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (strtoupper($capture_response['transaction_result']) == 'APPROVED') { + $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'payment', $firstdata_order['total']); + $total_captured = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); + + $this->model_extension_payment_firstdata_remote->updateCaptureStatus($firstdata_order['firstdata_remote_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + $json['data'] = array(); + $json['data']['column_date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = (float)$firstdata_order['total']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['data']['total_formatted'] = $this->currency->format($total_captured, $firstdata_order['currency_code'], 1, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response['error']) && !empty($capture_response['error']) ? (string)$capture_response['error'] : 'Unable to capture'; + + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function refund() { + $this->load->language('extension/payment/firstdata_remote'); + + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/firstdata_remote'); + + $firstdata_order = $this->model_extension_payment_firstdata_remote->getOrder($this->request->post['order_id']); + + $refund_response = $this->model_extension_payment_firstdata_remote->refund($firstdata_order['order_ref'], $firstdata_order['total'], $firstdata_order['currency_code']); + + $this->model_extension_payment_firstdata_remote->logger('Refund result:\r\n' . print_r($refund_response, 1)); + + if (strtoupper($refund_response['transaction_result']) == 'APPROVED') { + $this->model_extension_payment_firstdata_remote->addTransaction($firstdata_order['firstdata_remote_order_id'], 'refund', $firstdata_order['total'] * -1); + + $total_refunded = $this->model_extension_payment_firstdata_remote->getTotalRefunded($firstdata_order['firstdata_remote_order_id']); + $total_captured = $this->model_extension_payment_firstdata_remote->getTotalCaptured($firstdata_order['firstdata_remote_order_id']); + + if ($total_captured <= 0 && $firstdata_order['capture_status'] == 1) { + $this->model_extension_payment_firstdata_remote->updateRefundStatus($firstdata_order['firstdata_remote_order_id'], 1); + $refund_status = 1; + $json['msg'] = $this->language->get('text_refund_ok_order'); + } else { + $refund_status = 0; + $json['msg'] = $this->language->get('text_refund_ok'); + } + + $json['data'] = array(); + $json['data']['column_date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $firstdata_order['total'] * -1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_refunded'] = (float)$total_refunded; + $json['data']['refund_status'] = $refund_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($refund_response['error']) && !empty($refund_response['error']) ? (string)$refund_response['error'] : 'Unable to refund'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/firstdata_remote')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['firstdata_remote_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['firstdata_remote_user_id']) { + $this->error['error_user_id'] = $this->language->get('error_user_id'); + } + + if (!$this->request->post['firstdata_remote_password']) { + $this->error['error_password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['firstdata_remote_certificate']) { + $this->error['error_certificate'] = $this->language->get('error_certificate'); + } + + if (!$this->request->post['firstdata_remote_key']) { + $this->error['error_key'] = $this->language->get('error_key'); + } + + if (!$this->request->post['firstdata_remote_key_pw']) { + $this->error['error_key_pw'] = $this->language->get('error_key_pw'); + } + + if (!$this->request->post['firstdata_remote_ca']) { + $this->error['error_ca'] = $this->language->get('error_ca'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/free_checkout.php b/public/admin/controller/extension/payment/free_checkout.php new file mode 100644 index 0000000..90578c5 --- /dev/null +++ b/public/admin/controller/extension/payment/free_checkout.php @@ -0,0 +1,83 @@ +<?php +class ControllerExtensionPaymentFreeCheckout extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/free_checkout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_free_checkout', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/free_checkout', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/free_checkout', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['free_checkout_order_status_id'])) { + $data['free_checkout_order_status_id'] = $this->request->post['free_checkout_order_status_id']; + } else { + $data['free_checkout_order_status_id'] = $this->config->get('free_checkout_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_free_checkout_status'])) { + $data['payment_free_checkout_status'] = $this->request->post['payment_free_checkout_status']; + } else { + $data['payment_free_checkout_status'] = $this->config->get('payment_free_checkout_status'); + } + + if (isset($this->request->post['payment_free_checkout_sort_order'])) { + $data['payment_free_checkout_sort_order'] = $this->request->post['payment_free_checkout_sort_order']; + } else { + $data['payment_free_checkout_sort_order'] = $this->config->get('payment_free_checkout_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/free_checkout', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/free_checkout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/g2apay.php b/public/admin/controller/extension/payment/g2apay.php new file mode 100644 index 0000000..19014f5 --- /dev/null +++ b/public/admin/controller/extension/payment/g2apay.php @@ -0,0 +1,302 @@ +<?php + +class ControllerExtensionPaymentG2APay extends Controller { + + private $error = array(); + + public function index() { + $this->load->language('extension/payment/g2apay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_g2apay', $this->request->post); + + $this->session->data['complete'] = $this->language->get('text_complete'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + if (isset($this->error['api_hash'])) { + $data['error_api_hash'] = $this->error['api_hash']; + } else { + $data['error_api_hash'] = ''; + } + + if (isset($this->request->post['payment_g2apay_order_status_id'])) { + $data['payment_g2apay_order_status_id'] = $this->request->post['payment_g2apay_order_status_id']; + } else { + $data['payment_g2apay_order_status_id'] = $this->config->get('payment_g2apay_order_status_id'); + } + + if (isset($this->request->post['payment_g2apay_complete_status_id'])) { + $data['payment_g2apay_complete_status_id'] = $this->request->post['payment_g2apay_complete_status_id']; + } else { + $data['payment_g2apay_complete_status_id'] = $this->config->get('payment_g2apay_complete_status_id'); + } + + if (isset($this->request->post['payment_g2apay_rejected_status_id'])) { + $data['payment_g2apay_rejected_status_id'] = $this->request->post['payment_g2apay_rejected_status_id']; + } else { + $data['payment_g2apay_rejected_status_id'] = $this->config->get('payment_g2apay_rejected_status_id'); + } + + if (isset($this->request->post['payment_g2apay_cancelled_status_id'])) { + $data['payment_g2apay_cancelled_status_id'] = $this->request->post['payment_g2apay_cancelled_status_id']; + } else { + $data['payment_g2apay_cancelled_status_id'] = $this->config->get('payment_g2apay_cancelled_status_id'); + } + + if (isset($this->request->post['payment_g2apay_pending_status_id'])) { + $data['payment_g2apay_pending_status_id'] = $this->request->post['payment_g2apay_pending_status_id']; + } else { + $data['payment_g2apay_pending_status_id'] = $this->config->get('payment_g2apay_pending_status_id'); + } + + if (isset($this->request->post['payment_g2apay_refunded_status_id'])) { + $data['payment_g2apay_refunded_status_id'] = $this->request->post['payment_g2apay_refunded_status_id']; + } else { + $data['payment_g2apay_refunded_status_id'] = $this->config->get('payment_g2apay_refunded_status_id'); + } + + if (isset($this->request->post['payment_g2apay_partially_refunded_status_id'])) { + $data['payment_g2apay_partially_refunded_status_id'] = $this->request->post['payment_g2apay_partially_refunded_status_id']; + } else { + $data['payment_g2apay_partially_refunded_status_id'] = $this->config->get('payment_g2apay_partially_refunded_status_id'); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/g2apay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $this->load->model('localisation/order_status'); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['action'] = $this->url->link('extension/payment/g2apay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_g2apay_username'])) { + $data['payment_g2apay_username'] = $this->request->post['payment_g2apay_username']; + } else { + $data['payment_g2apay_username'] = $this->config->get('payment_g2apay_username'); + } + + if (isset($this->request->post['payment_g2apay_secret'])) { + $data['payment_g2apay_secret'] = $this->request->post['payment_g2apay_secret']; + } else { + $data['payment_g2apay_secret'] = $this->config->get('payment_g2apay_secret'); + } + + if (isset($this->request->post['payment_g2apay_api_hash'])) { + $data['payment_g2apay_api_hash'] = $this->request->post['payment_g2apay_api_hash']; + } else { + $data['payment_g2apay_api_hash'] = $this->config->get('payment_g2apay_api_hash'); + } + + if (isset($this->request->post['payment_g2apay_environment'])) { + $data['payment_g2apay_environment'] = $this->request->post['payment_g2apay_environment']; + } else { + $data['payment_g2apay_environment'] = $this->config->get('payment_g2apay_environment'); + } + + if (isset($this->request->post['payment_g2apay_total'])) { + $data['payment_g2apay_total'] = $this->request->post['payment_g2apay_total']; + } else { + $data['payment_g2apay_total'] = $this->config->get('payment_g2apay_total'); + } + + if (isset($this->request->post['payment_g2apay_secret_token'])) { + $data['payment_g2apay_secret_token'] = $this->request->post['payment_g2apay_secret_token']; + } elseif ($this->config->get('payment_g2apay_secret_token')) { + $data['payment_g2apay_secret_token'] = $this->config->get('payment_g2apay_secret_token'); + } else { + $data['payment_g2apay_secret_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['g2apay_ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/g2apay/ipn&token=' . $data['payment_g2apay_secret_token']; + + if (isset($this->request->post['payment_g2apay_ipn_uri'])) { + $data['payment_g2apay_ipn_uri'] = $this->request->post['payment_g2apay_ipn_uri']; + } else { + $data['payment_g2apay_ipn_uri'] = $this->config->get('payment_g2apay_ipn_uri'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_g2apay_geo_zone_id'])) { + $data['payment_g2apay_geo_zone_id'] = $this->request->post['payment_g2apay_geo_zone_id']; + } else { + $data['payment_g2apay_geo_zone_id'] = $this->config->get('payment_g2apay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_g2apay_status'])) { + $data['payment_g2apay_status'] = $this->request->post['payment_g2apay_status']; + } else { + $data['payment_g2apay_status'] = $this->config->get('payment_g2apay_status'); + } + + if (isset($this->request->post['payment_g2apay_debug'])) { + $data['payment_g2apay_debug'] = $this->request->post['payment_g2apay_debug']; + } else { + $data['payment_g2apay_debug'] = $this->config->get('payment_g2apay_debug'); + } + + if (isset($this->request->post['payment_g2apay_sort_order'])) { + $data['payment_g2apay_sort_order'] = $this->request->post['payment_g2apay_sort_order']; + } else { + $data['payment_g2apay_sort_order'] = $this->config->get('payment_g2apay_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/g2apay', $data)); + } + + public function order() { + + if ($this->config->get('payment_g2apay_status')) { + + $this->load->model('extension/payment/g2apay'); + + $g2apay_order = $this->model_extension_payment_g2apay->getOrder($this->request->get['order_id']); + + if (!empty($g2apay_order)) { + $this->load->language('extension/payment/g2apay'); + + $g2apay_order['total_released'] = $this->model_extension_payment_g2apay->getTotalReleased($g2apay_order['g2apay_order_id']); + + $g2apay_order['total_formatted'] = $this->currency->format($g2apay_order['total'], $g2apay_order['currency_code'], false); + $g2apay_order['total_released_formatted'] = $this->currency->format($g2apay_order['total_released'], $g2apay_order['currency_code'], false); + + $data['g2apay_order'] = $g2apay_order; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/g2apay_order', $data); + } + } + } + + public function refund() { + $this->load->language('extension/payment/g2apay'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/g2apay'); + + $g2apay_order = $this->model_extension_payment_g2apay->getOrder($this->request->post['order_id']); + + $refund_response = $this->model_extension_payment_g2apay->refund($g2apay_order, $this->request->post['amount']); + + $this->model_extension_payment_g2apay->logger($refund_response); + + if ($refund_response == 'ok') { + $this->model_extension_payment_g2apay->addTransaction($g2apay_order['g2apay_order_id'], 'refund', $this->request->post['amount'] * -1); + + $total_refunded = $this->model_extension_payment_g2apay->getTotalRefunded($g2apay_order['g2apay_order_id']); + $total_released = $this->model_extension_payment_g2apay->getTotalReleased($g2apay_order['g2apay_order_id']); + + if ($total_released <= 0 && $g2apay_order['release_status'] == 1) { + $this->model_extension_payment_g2apay->updateRefundStatus($g2apay_order['g2apay_order_id'], 1); + $refund_status = 1; + $json['msg'] = $this->language->get('text_refund_ok_order'); + } else { + $refund_status = 0; + $json['msg'] = $this->language->get('text_refund_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->currency->format(($this->request->post['amount'] * -1), $g2apay_order['currency_code'], false); + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_refunded'] = (float)$total_refunded; + $json['data']['refund_status'] = $refund_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = 'Unable to refund: ' . $refund_response; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function install() { + $this->load->model('extension/payment/g2apay'); + $this->model_extension_payment_g2apay->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/g2apay'); + $this->model_extension_payment_g2apay->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/g2apay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_g2apay_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_g2apay_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + } + + if (!$this->request->post['payment_g2apay_api_hash']) { + $this->error['api_hash'] = $this->language->get('error_api_hash'); + } + + return !$this->error; + } + +} diff --git a/public/admin/controller/extension/payment/globalpay.php b/public/admin/controller/extension/payment/globalpay.php new file mode 100644 index 0000000..4e833d6 --- /dev/null +++ b/public/admin/controller/extension/payment/globalpay.php @@ -0,0 +1,408 @@ +<?php +class ControllerExtensionPaymentGlobalpay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/globalpay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_globalpay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/globalpay/notify'; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + if (isset($this->error['error_live_url'])) { + $data['error_live_url'] = $this->error['error_live_url']; + } else { + $data['error_live_url'] = ''; + } + + if (isset($this->error['error_demo_url'])) { + $data['error_demo_url'] = $this->error['error_demo_url']; + } else { + $data['error_demo_url'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/globalpay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/globalpay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_globalpay_merchant_id'])) { + $data['payment_globalpay_merchant_id'] = $this->request->post['payment_globalpay_merchant_id']; + } else { + $data['payment_globalpay_merchant_id'] = $this->config->get('payment_globalpay_merchant_id'); + } + + if (isset($this->request->post['payment_globalpay_secret'])) { + $data['payment_globalpay_secret'] = $this->request->post['payment_globalpay_secret']; + } else { + $data['payment_globalpay_secret'] = $this->config->get('payment_globalpay_secret'); + } + + if (isset($this->request->post['payment_globalpay_rebate_password'])) { + $data['payment_globalpay_rebate_password'] = $this->request->post['payment_globalpay_rebate_password']; + } else { + $data['payment_globalpay_rebate_password'] = $this->config->get('payment_globalpay_rebate_password'); + } + + if (isset($this->request->post['payment_globalpay_live_demo'])) { + $data['payment_globalpay_live_demo'] = $this->request->post['payment_globalpay_live_demo']; + } else { + $data['payment_globalpay_live_demo'] = $this->config->get('payment_globalpay_live_demo'); + } + + if (isset($this->request->post['payment_globalpay_geo_zone_id'])) { + $data['payment_globalpay_geo_zone_id'] = $this->request->post['payment_globalpay_geo_zone_id']; + } else { + $data['payment_globalpay_geo_zone_id'] = $this->config->get('payment_globalpay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_globalpay_total'])) { + $data['payment_globalpay_total'] = $this->request->post['payment_globalpay_total']; + } else { + $data['payment_globalpay_total'] = $this->config->get('payment_globalpay_total'); + } + + if (isset($this->request->post['payment_globalpay_sort_order'])) { + $data['payment_globalpay_sort_order'] = $this->request->post['payment_globalpay_sort_order']; + } else { + $data['payment_globalpay_sort_order'] = $this->config->get('payment_globalpay_sort_order'); + } + + if (isset($this->request->post['payment_globalpay_status'])) { + $data['payment_globalpay_status'] = $this->request->post['payment_globalpay_status']; + } else { + $data['payment_globalpay_status'] = $this->config->get('payment_globalpay_status'); + } + + if (isset($this->request->post['payment_globalpay_debug'])) { + $data['payment_globalpay_debug'] = $this->request->post['payment_globalpay_debug']; + } else { + $data['payment_globalpay_debug'] = $this->config->get('payment_globalpay_debug'); + } + + if (isset($this->request->post['payment_globalpay_account'])) { + $data['payment_globalpay_account'] = $this->request->post['payment_globalpay_account']; + } else { + $data['payment_globalpay_account'] = $this->config->get('payment_globalpay_account'); + } + + if (isset($this->request->post['payment_globalpay_auto_settle'])) { + $data['payment_globalpay_auto_settle'] = $this->request->post['payment_globalpay_auto_settle']; + } else { + $data['payment_globalpay_auto_settle'] = $this->config->get('payment_globalpay_auto_settle'); + } + + if (isset($this->request->post['payment_globalpay_card_select'])) { + $data['payment_globalpay_card_select'] = $this->request->post['payment_globalpay_card_select']; + } else { + $data['payment_globalpay_card_select'] = $this->config->get('payment_globalpay_card_select'); + } + + if (isset($this->request->post['payment_globalpay_tss_check'])) { + $data['payment_globalpay_tss_check'] = $this->request->post['payment_globalpay_tss_check']; + } else { + $data['payment_globalpay_tss_check'] = $this->config->get('payment_globalpay_tss_check'); + } + + if (isset($this->request->post['globalpay_order_status_success_settled_id'])) { + $data['globalpay_order_status_success_settled_id'] = $this->request->post['globalpay_order_status_success_settled_id']; + } else { + $data['globalpay_order_status_success_settled_id'] = $this->config->get('globalpay_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_success_unsettled_id'])) { + $data['payment_globalpay_order_status_success_unsettled_id'] = $this->request->post['payment_globalpay_order_status_success_unsettled_id']; + } else { + $data['payment_globalpay_order_status_success_unsettled_id'] = $this->config->get('payment_globalpay_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_decline_id'])) { + $data['payment_globalpay_order_status_decline_id'] = $this->request->post['payment_globalpay_order_status_decline_id']; + } else { + $data['payment_globalpay_order_status_decline_id'] = $this->config->get('payment_globalpay_order_status_decline_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_decline_pending_id'])) { + $data['payment_globalpay_order_status_decline_pending_id'] = $this->request->post['payment_globalpay_order_status_decline_pending_id']; + } else { + $data['payment_globalpay_order_status_decline_pending_id'] = $this->config->get('payment_globalpay_order_status_decline_pending_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_decline_stolen_id'])) { + $data['payment_globalpay_order_status_decline_stolen_id'] = $this->request->post['payment_globalpay_order_status_decline_stolen_id']; + } else { + $data['payment_globalpay_order_status_decline_stolen_id'] = $this->config->get('payment_globalpay_order_status_decline_stolen_id'); + } + + if (isset($this->request->post['payment_globalpay_order_status_decline_bank_id'])) { + $data['payment_globalpay_order_status_decline_bank_id'] = $this->request->post['payment_globalpay_order_status_decline_bank_id']; + } else { + $data['payment_globalpay_order_status_decline_bank_id'] = $this->config->get('payment_globalpay_order_status_decline_bank_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_globalpay_live_url'])) { + $data['payment_globalpay_live_url'] = $this->request->post['payment_globalpay_live_url']; + } else { + $data['payment_globalpay_live_url'] = $this->config->get('payment_globalpay_live_url'); + } + + if (empty($data['payment_globalpay_live_url'])) { + $data['payment_globalpay_live_url'] = 'https://hpp.globaliris.com/pay'; + } + + if (isset($this->request->post['payment_globalpay_demo_url'])) { + $data['payment_globalpay_demo_url'] = $this->request->post['payment_globalpay_demo_url']; + } else { + $data['payment_globalpay_demo_url'] = $this->config->get('payment_globalpay_demo_url'); + } + + if (empty($data['payment_globalpay_demo_url'])) { + $data['payment_globalpay_demo_url'] = 'https://hpp.sandbox.globaliris.com/pay'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/globalpay', $data)); + } + + public function install() { + $this->load->model('extension/payment/globalpay'); + + $this->model_extension_payment_globalpay->install(); + } + + public function order() { + if ($this->config->get('payment_globalpay_status')) { + $this->load->model('extension/payment/globalpay'); + + $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->get['order_id']); + + if (!empty($globalpay_order)) { + $this->load->language('extension/payment/globalpay'); + + $globalpay_order['total_captured'] = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']); + + $globalpay_order['total_formatted'] = $this->currency->format($globalpay_order['total'], $globalpay_order['currency_code'], 1, true); + $globalpay_order['total_captured_formatted'] = $this->currency->format($globalpay_order['total_captured'], $globalpay_order['currency_code'], 1, true); + + $data['globalpay_order'] = $globalpay_order; + + $data['auto_settle'] = $globalpay_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/globalpay_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/globalpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/globalpay'); + + $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_globalpay->void($this->request->post['order_id']); + + $this->model_extension_payment_globalpay->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (isset($void_response->result) && $void_response->result == '00') { + $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'void', 0.00); + $this->model_extension_payment_globalpay->updateVoidStatus($globalpay_order['globalpay_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/globalpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/globalpay'); + + $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_globalpay->capture($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_globalpay->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (isset($capture_response->result) && $capture_response->result == '00') { + $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'payment', $this->request->post['amount']); + + $total_captured = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']); + + if ($total_captured >= $globalpay_order['total'] || $globalpay_order['settle_type'] == 0) { + $this->model_extension_payment_globalpay->updateCaptureStatus($globalpay_order['globalpay_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $this->model_extension_payment_globalpay->updateForRebate($globalpay_order['globalpay_order_id'], $capture_response->pasref, $capture_response->orderid); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/globalpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/globalpay'); + + $globalpay_order = $this->model_extension_payment_globalpay->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_globalpay->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_globalpay->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if (isset($rebate_response->result) && $rebate_response->result == '00') { + $this->model_extension_payment_globalpay->addTransaction($globalpay_order['globalpay_order_id'], 'rebate', $this->request->post['amount']*-1); + + $total_rebated = $this->model_extension_payment_globalpay->getTotalRebated($globalpay_order['globalpay_order_id']); + $total_captured = $this->model_extension_payment_globalpay->getTotalCaptured($globalpay_order['globalpay_order_id']); + + if ($total_captured <= 0 && $globalpay_order['capture_status'] == 1) { + $this->model_extension_payment_globalpay->updateRebateStatus($globalpay_order['globalpay_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']*-1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/globalpay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_globalpay_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_globalpay_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + if (!$this->request->post['payment_globalpay_live_url']) { + $this->error['error_live_url'] = $this->language->get('error_live_url'); + } + + if (!$this->request->post['payment_globalpay_demo_url']) { + $this->error['error_demo_url'] = $this->language->get('error_demo_url'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/globalpay_remote.php b/public/admin/controller/extension/payment/globalpay_remote.php new file mode 100644 index 0000000..c4e69c3 --- /dev/null +++ b/public/admin/controller/extension/payment/globalpay_remote.php @@ -0,0 +1,372 @@ +<?php +class ControllerExtensionPaymentGlobalpayRemote extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/globalpay_remote'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_globalpay_remote', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/globalpay_remote', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/globalpay_remote', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_globalpay_remote_merchant_id'])) { + $data['payment_globalpay_remote_merchant_id'] = $this->request->post['payment_globalpay_remote_merchant_id']; + } else { + $data['payment_globalpay_remote_merchant_id'] = $this->config->get('payment_globalpay_remote_merchant_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_secret'])) { + $data['payment_globalpay_remote_secret'] = $this->request->post['payment_globalpay_remote_secret']; + } else { + $data['payment_globalpay_remote_secret'] = $this->config->get('payment_globalpay_remote_secret'); + } + + if (isset($this->request->post['payment_globalpay_remote_rebate_password'])) { + $data['payment_globalpay_remote_rebate_password'] = $this->request->post['payment_globalpay_remote_rebate_password']; + } else { + $data['payment_globalpay_remote_rebate_password'] = $this->config->get('payment_globalpay_remote_rebate_password'); + } + + if (isset($this->request->post['payment_globalpay_remote_geo_zone_id'])) { + $data['payment_globalpay_remote_geo_zone_id'] = $this->request->post['payment_globalpay_remote_geo_zone_id']; + } else { + $data['payment_globalpay_remote_geo_zone_id'] = $this->config->get('payment_globalpay_remote_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_globalpay_remote_total'])) { + $data['payment_globalpay_remote_total'] = $this->request->post['payment_globalpay_remote_total']; + } else { + $data['payment_globalpay_remote_total'] = $this->config->get('payment_globalpay_remote_total'); + } + + if (isset($this->request->post['payment_globalpay_remote_sort_order'])) { + $data['payment_globalpay_remote_sort_order'] = $this->request->post['payment_globalpay_remote_sort_order']; + } else { + $data['payment_globalpay_remote_sort_order'] = $this->config->get('payment_globalpay_remote_sort_order'); + } + + if (isset($this->request->post['payment_globalpay_remote_status'])) { + $data['payment_globalpay_remote_status'] = $this->request->post['payment_globalpay_remote_status']; + } else { + $data['payment_globalpay_remote_status'] = $this->config->get('payment_globalpay_remote_status'); + } + + if (isset($this->request->post['payment_globalpay_remote_card_data_status'])) { + $data['payment_globalpay_remote_card_data_status'] = $this->request->post['payment_globalpay_remote_card_data_status']; + } else { + $data['payment_globalpay_remote_card_data_status'] = $this->config->get('payment_globalpay_remote_card_data_status'); + } + + if (isset($this->request->post['payment_globalpay_remote_debug'])) { + $data['payment_globalpay_remote_debug'] = $this->request->post['payment_globalpay_remote_debug']; + } else { + $data['payment_globalpay_remote_debug'] = $this->config->get('payment_globalpay_remote_debug'); + } + + if (isset($this->request->post['payment_globalpay_remote_account'])) { + $data['payment_globalpay_remote_account'] = $this->request->post['payment_globalpay_remote_account']; + } else { + $data['payment_globalpay_remote_account'] = $this->config->get('payment_globalpay_remote_account'); + } + + if (isset($this->request->post['payment_globalpay_remote_auto_settle'])) { + $data['payment_globalpay_remote_auto_settle'] = $this->request->post['payment_globalpay_remote_auto_settle']; + } else { + $data['payment_globalpay_remote_auto_settle'] = $this->config->get('payment_globalpay_remote_auto_settle'); + } + + if (isset($this->request->post['payment_globalpay_remote_tss_check'])) { + $data['payment_globalpay_remote_tss_check'] = $this->request->post['payment_globalpay_remote_tss_check']; + } else { + $data['payment_globalpay_remote_tss_check'] = $this->config->get('payment_globalpay_remote_tss_check'); + } + + if (isset($this->request->post['payment_globalpay_remote_3d'])) { + $data['payment_globalpay_remote_3d'] = $this->request->post['payment_globalpay_remote_3d']; + } else { + $data['payment_globalpay_remote_3d'] = $this->config->get('payment_globalpay_remote_3d'); + } + + if (isset($this->request->post['payment_globalpay_remote_liability'])) { + $data['payment_globalpay_remote_liability'] = $this->request->post['payment_globalpay_remote_liability']; + } else { + $data['payment_globalpay_remote_liability'] = $this->config->get('payment_globalpay_remote_liability'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_success_settled_id'])) { + $data['payment_globalpay_remote_order_status_success_settled_id'] = $this->request->post['payment_globalpay_remote_order_status_success_settled_id']; + } else { + $data['payment_globalpay_remote_order_status_success_settled_id'] = $this->config->get('payment_globalpay_remote_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_success_unsettled_id'])) { + $data['payment_globalpay_remote_order_status_success_unsettled_id'] = $this->request->post['payment_globalpay_remote_order_status_success_unsettled_id']; + } else { + $data['payment_globalpay_remote_order_status_success_unsettled_id'] = $this->config->get('payment_globalpay_remote_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_decline_id'])) { + $data['payment_globalpay_remote_order_status_decline_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_id']; + } else { + $data['payment_globalpay_remote_order_status_decline_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_decline_pending_id'])) { + $data['payment_globalpay_remote_order_status_decline_pending_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_pending_id']; + } else { + $data['payment_globalpay_remote_order_status_decline_pending_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_pending_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_decline_stolen_id'])) { + $data['payment_globalpay_remote_order_status_decline_stolen_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_stolen_id']; + } else { + $data['payment_globalpay_remote_order_status_decline_stolen_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_stolen_id'); + } + + if (isset($this->request->post['payment_globalpay_remote_order_status_decline_bank_id'])) { + $data['payment_globalpay_remote_order_status_decline_bank_id'] = $this->request->post['payment_globalpay_remote_order_status_decline_bank_id']; + } else { + $data['payment_globalpay_remote_order_status_decline_bank_id'] = $this->config->get('payment_globalpay_remote_order_status_decline_bank_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/globalpay_remote', $data)); + } + + public function install() { + $this->load->model('extension/payment/globalpay_remote'); + $this->model_extension_payment_globalpay_remote->install(); + } + + public function order() { + if ($this->config->get('payment_globalpay_remote_status')) { + $this->load->model('extension/payment/globalpay_remote'); + + $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->get['order_id']); + + if (!empty($globalpay_order)) { + $this->load->language('extension/payment/globalpay_remote'); + + $globalpay_order['total_captured'] = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']); + + $globalpay_order['total_formatted'] = $this->currency->format($globalpay_order['total'], $globalpay_order['currency_code'], 1, true); + $globalpay_order['total_captured_formatted'] = $this->currency->format($globalpay_order['total_captured'], $globalpay_order['currency_code'], 1, true); + + $data['globalpay_order'] = $globalpay_order; + + $data['auto_settle'] = $globalpay_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/globalpay_remote_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/globalpay_remote'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/globalpay_remote'); + + $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_globalpay_remote->void($this->request->post['order_id']); + + $this->model_extension_payment_globalpay_remote->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (isset($void_response->result) && $void_response->result == '00') { + $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'void', 0.00); + $this->model_extension_payment_globalpay_remote->updateVoidStatus($globalpay_order['globalpay_remote_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/globalpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/globalpay_remote'); + + $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_globalpay_remote->capture($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_globalpay_remote->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (isset($capture_response->result) && $capture_response->result == '00') { + $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'payment', $this->request->post['amount']); + $total_captured = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']); + + if ($total_captured >= $globalpay_order['total'] || $globalpay_order['settle_type'] == 0) { + $this->model_extension_payment_globalpay_remote->updateCaptureStatus($globalpay_order['globalpay_remote_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $this->model_extension_payment_globalpay_remote->updateForRebate($globalpay_order['globalpay_remote_order_id'], $capture_response->pasref, $capture_response->orderid); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = (float)$this->request->post['amount']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['data']['total_formatted'] = $this->currency->format($total_captured, $globalpay_order['currency_code'], 1, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture'; + + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/globalpay_remote'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/globalpay_remote'); + + $globalpay_order = $this->model_extension_payment_globalpay_remote->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_globalpay_remote->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_globalpay_remote->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if (isset($rebate_response->result) && $rebate_response->result == '00') { + $this->model_extension_payment_globalpay_remote->addTransaction($globalpay_order['globalpay_remote_order_id'], 'rebate', $this->request->post['amount']*-1); + + $total_rebated = $this->model_extension_payment_globalpay_remote->getTotalRebated($globalpay_order['globalpay_remote_order_id']); + $total_captured = $this->model_extension_payment_globalpay_remote->getTotalCaptured($globalpay_order['globalpay_remote_order_id']); + + if ($total_captured <= 0 && $globalpay_order['capture_status'] == 1) { + $this->model_extension_payment_globalpay_remote->updateRebateStatus($globalpay_order['globalpay_remote_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/globalpay_remote')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_globalpay_remote_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_globalpay_remote_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/klarna_account.php b/public/admin/controller/extension/payment/klarna_account.php new file mode 100644 index 0000000..30dff8b --- /dev/null +++ b/public/admin/controller/extension/payment/klarna_account.php @@ -0,0 +1,329 @@ +<?php +class ControllerExtensionPaymentKlarnaAccount extends Controller { + private $error = array(); + private $pclasses = array(); + + public function index() { + $this->load->language('extension/payment/klarna_account'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $status = false; + + foreach ($this->request->post['payment_klarna_account_'] as $klarna_account) { + if ($klarna_account['status']) { + $status = true; + + break; + } + } + + $klarna_data = array( + 'klarna_account_pclasses' => $this->pclasses, + 'klarna_account_status' => $status + ); + + $this->model_setting_setting->editSetting('payment_klarna_account', array_merge($this->request->post, $klarna_data)); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/klarna_account', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/klarna_account', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['countries'] = array(); + + $data['countries'][] = array( + 'name' => $this->language->get('text_germany'), + 'code' => 'DEU' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_netherlands'), + 'code' => 'NLD' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_denmark'), + 'code' => 'DNK' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_sweden'), + 'code' => 'SWE' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_norway'), + 'code' => 'NOR' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_finland'), + 'code' => 'FIN' + ); + + if (isset($this->request->post['payment_klarna_account'])) { + $data['payment_klarna_account'] = $this->request->post['payment_klarna_account']; + } else { + $data['payment_klarna_account'] = $this->config->get('payment_klarna_account'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $file = DIR_LOGS . 'klarna_account.log'; + + if (file_exists($file)) { + $data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null); + } else { + $data['log'] = ''; + } + + $data['clear'] = $this->url->link('extension/payment/klarna_account/clear', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/klarna_account', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/klarna_account')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + $log = new Log('klarna_account.log'); + + $country = array( + 'NOR' => array( + 'currency' => 1, + 'country' => 164, + 'language' => 97, + ), + 'SWE' => array( + 'currency' => 0, + 'country' => 209, + 'language' => 138, + ), + 'FIN' => array( + 'currency' => 2, + 'country' => 73, + 'language' => 101, + ), + 'DNK' => array( + 'currency' => 3, + 'country' => 59, + 'language' => 27, + ), + 'DEU' => array( + 'currency' => 2, + 'country' => 81, + 'language' => 28, + ), + 'NLD' => array( + 'currency' => 2, + 'country' => 154, + 'language' => 101, + ), + ); + + foreach ($this->request->post['klarna_account'] as $key => $klarna_account) { + if ($klarna_account['status']) { + $digest = base64_encode(pack("H*", hash('sha256', $klarna_account['merchant'] . ':' . $country[$key]['currency'] . ':' . $klarna_account['secret']))); + + $xml = '<methodCall>'; + $xml .= ' <methodName>get_pclasses</methodName>'; + $xml .= ' <params>'; + $xml .= ' <param><value><string>4.1</string></value></param>'; + $xml .= ' <param><value><string>API:OPENCART:' . VERSION . '</string></value></param>'; + $xml .= ' <param><value><int>' . (int)$klarna_account['merchant'] . '</int></value></param>'; + $xml .= ' <param><value><int>' . $country[$key]['currency'] . '</int></value></param>'; + $xml .= ' <param><value><string>' . $digest . '</string></value></param>'; + $xml .= ' <param><value><int>' . $country[$key]['country'] . '</int></value></param>'; + $xml .= ' <param><value><int>' . $country[$key]['language'] . '</int></value></param>'; + $xml .= ' </params>'; + $xml .= '</methodCall>'; + + if ($klarna_account['server'] == 'live') { + $url = 'https://payment.klarna.com'; + } else { + $url = 'https://payment.testdrive.klarna.com'; + } + + $curl = curl_init(); + + $header = array(); + + $header[] = 'Content-Type: text/xml'; + $header[] = 'Content-Length: ' . strlen($xml); + + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_HTTPHEADER, $header); + curl_setopt($curl, CURLOPT_POSTFIELDS, $xml); + + $response = curl_exec($curl); + + if ($response !== false) { + $xml = new DOMDocument(); + $xml->loadXML($response); + + $xpath = new DOMXPath($xml); + + $nodes = $xpath->query('//methodResponse/params/param/value'); + + if ($nodes->length == 0) { + $this->error['warning'] = $this->language->get('error_log'); + + $error_code = $xpath->query('//methodResponse/fault/value/struct/member/value/int')->item(0)->nodeValue; + $error_message = $xpath->query('//methodResponse/fault/value/struct/member/value/string')->item(0)->nodeValue; + + $log->write(sprintf($this->language->get('error_pclass'), $key, $error_code, $error_message)); + + continue; + } + + $pclasses = $this->parseResponse($nodes->item(0)->firstChild, $xml); + + while ($pclasses) { + $pclass = array_slice($pclasses, 0, 10); + $pclasses = array_slice($pclasses, 10); + + $pclass[3] /= 100; + $pclass[4] /= 100; + $pclass[5] /= 100; + $pclass[6] /= 100; + $pclass[9] = ($pclass[9] != '-') ? strtotime($pclass[9]) : $pclass[9]; + + array_unshift($pclass, $klarna_account['merchant']); + + $this->pclasses[$key][] = array( + 'eid' => intval($pclass[0]), + 'id' => intval($pclass[1]), + 'description' => $pclass[2], + 'months' => intval($pclass[3]), + 'startfee' => floatval($pclass[4]), + 'invoicefee' => floatval($pclass[5]), + 'interestrate' => floatval($pclass[6]), + 'minamount' => floatval($pclass[7]), + 'country' => intval($pclass[8]), + 'type' => intval($pclass[9]), + ); + } + } else { + $this->error['warning'] = $this->language->get('error_log'); + + $log->write(sprintf($this->language->get('error_curl'), curl_errno($curl), curl_error($curl))); + } + + curl_close($curl); + } + } + + return !$this->error; + } + + private function parseResponse($node, $document) { + $child = $node; + + switch ($child->nodeName) { + case 'string': + $value = $child->nodeValue; + break; + case 'boolean': + $value = (string)$child->nodeValue; + + if ($value == '0') { + $value = false; + } elseif ($value == '1') { + $value = true; + } else { + $value = null; + } + + break; + case 'integer': + case 'int': + case 'i4': + case 'i8': + $value = (int)$child->nodeValue; + break; + case 'array': + $value = array(); + + $xpath = new DOMXPath($document); + $entries = $xpath->query('.//array/data/value', $child); + + for ($i = 0; $i < $entries->length; $i++) { + $value[] = $this->parseResponse($entries->item($i)->firstChild, $document); + } + + break; + default: + $value = null; + } + + return $value; + } + + public function clear() { + $this->load->language('extension/payment/klarna_account'); + + $file = DIR_LOGS . 'klarna_account.log'; + + $handle = fopen($file, 'w+'); + + fclose($handle); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('extension/payment/klarna_account', 'user_token=' . $this->session->data['user_token'], true)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/klarna_checkout.php b/public/admin/controller/extension/payment/klarna_checkout.php new file mode 100644 index 0000000..edeb9c4 --- /dev/null +++ b/public/admin/controller/extension/payment/klarna_checkout.php @@ -0,0 +1,859 @@ +<?php +class ControllerExtensionPaymentKlarnaCheckout extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/klarna_checkout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_klarna_checkout', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/language'); + + $data['languages'] = $this->model_localisation_language->getLanguages(); + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $data['api_locations'] = array( + array( + 'name' => 'North America', + 'code' => 'NA' + ), + array( + 'name' => 'Europe', + 'code' => 'EU' + ) + ); + + $this->load->model('catalog/information'); + + $data['informations'] = $this->model_catalog_information->getInformations(); + + $this->load->model('localisation/currency'); + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $this->load->model('extension/payment/klarna_checkout'); + + if ($this->model_extension_payment_klarna_checkout->checkForPaymentTaxes()) { + $data['error_tax_warning'] = $this->language->get('error_tax_warning'); + } else { + $data['error_tax_warning'] = ''; + } + + if (isset($this->error['account_warning'])) { + $data['error_account_warning'] = $this->error['account_warning']; + } else { + $data['error_account_warning'] = ''; + } + + if (isset($this->error['account'])) { + $data['error_account'] = $this->error['account']; + } else { + $data['error_account'] = array(); + } + + if (isset($this->error['settlement_warning'])) { + $data['error_settlement_warning'] = $this->error['settlement_warning']; + } else { + $data['error_settlement_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/klarna_checkout', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/klarna_checkout', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['klarna_checkout_debug'])) { + $data['klarna_checkout_debug'] = $this->request->post['klarna_checkout_debug']; + } else { + $data['klarna_checkout_debug'] = $this->config->get('klarna_checkout_debug'); + } + + if (isset($this->request->post['klarna_checkout_colour_button'])) { + $data['klarna_checkout_colour_button'] = $this->request->post['klarna_checkout_colour_button']; + } elseif ($this->config->get('klarna_checkout_colour_button')) { + $data['klarna_checkout_colour_button'] = $this->config->get('klarna_checkout_colour_button'); + } else { + $data['klarna_checkout_colour_button'] = '#0072cc'; + } + + if (isset($this->request->post['klarna_checkout_colour_button_text'])) { + $data['klarna_checkout_colour_button_text'] = $this->request->post['klarna_checkout_colour_button_text']; + } elseif ($this->config->get('klarna_checkout_colour_button_text')) { + $data['klarna_checkout_colour_button_text'] = $this->config->get('klarna_checkout_colour_button_text'); + } else { + $data['klarna_checkout_colour_button_text'] = '#ffffff'; + } + + if (isset($this->request->post['klarna_checkout_colour_checkbox'])) { + $data['klarna_checkout_colour_checkbox'] = $this->request->post['klarna_checkout_colour_checkbox']; + } elseif ($this->config->get('klarna_checkout_colour_checkbox')) { + $data['klarna_checkout_colour_checkbox'] = $this->config->get('klarna_checkout_colour_checkbox'); + } else { + $data['klarna_checkout_colour_checkbox'] = '#0072cc'; + } + + if (isset($this->request->post['klarna_checkout_colour_checkbox_checkmark'])) { + $data['klarna_checkout_colour_checkbox_checkmark'] = $this->request->post['klarna_checkout_colour_checkbox_checkmark']; + } elseif ($this->config->get('klarna_checkout_colour_checkbox_checkmark')) { + $data['klarna_checkout_colour_checkbox_checkmark'] = $this->config->get('klarna_checkout_colour_checkbox_checkmark'); + } else { + $data['klarna_checkout_colour_checkbox_checkmark'] = '#ffffff'; + } + + if (isset($this->request->post['klarna_checkout_colour_header'])) { + $data['klarna_checkout_colour_header'] = $this->request->post['klarna_checkout_colour_header']; + } elseif ($this->config->get('klarna_checkout_colour_header')) { + $data['klarna_checkout_colour_header'] = $this->config->get('klarna_checkout_colour_header'); + } else { + $data['klarna_checkout_colour_header'] = '#434343'; + } + + if (isset($this->request->post['klarna_checkout_colour_link'])) { + $data['klarna_checkout_colour_link'] = $this->request->post['klarna_checkout_colour_link']; + } elseif ($this->config->get('klarna_checkout_colour_link')) { + $data['klarna_checkout_colour_link'] = $this->config->get('klarna_checkout_colour_link'); + } else { + $data['klarna_checkout_colour_link'] = '#0072cc'; + } + + if (isset($this->request->post['klarna_checkout_separate_shipping_address'])) { + $data['klarna_checkout_separate_shipping_address'] = $this->request->post['klarna_checkout_separate_shipping_address']; + } else { + $data['klarna_checkout_separate_shipping_address'] = $this->config->get('klarna_checkout_separate_shipping_address'); + } + + if (isset($this->request->post['klarna_checkout_dob_mandatory'])) { + $data['klarna_checkout_dob_mandatory'] = $this->request->post['klarna_checkout_dob_mandatory']; + } else { + $data['klarna_checkout_dob_mandatory'] = $this->config->get('klarna_checkout_dob_mandatory'); + } + + if (isset($this->request->post['klarna_checkout_title_mandatory'])) { + $data['klarna_checkout_title_mandatory'] = $this->request->post['klarna_checkout_title_mandatory']; + } else { + $data['klarna_checkout_title_mandatory'] = $this->config->get('klarna_checkout_title_mandatory'); + } + + if (isset($this->request->post['klarna_checkout_additional_text_box'])) { + $data['klarna_checkout_additional_text_box'] = $this->request->post['klarna_checkout_additional_text_box']; + } else { + $data['klarna_checkout_additional_text_box'] = $this->config->get('klarna_checkout_additional_text_box'); + } + + if (isset($this->request->post['klarna_checkout_total'])) { + $data['klarna_checkout_total'] = $this->request->post['klarna_checkout_total']; + } else { + $data['klarna_checkout_total'] = $this->config->get('klarna_checkout_total'); + } + + if (isset($this->request->post['klarna_checkout_order_status_authorised_id'])) { + $data['klarna_checkout_order_status_authorised_id'] = $this->request->post['klarna_checkout_order_status_authorised_id']; + } else { + $data['klarna_checkout_order_status_authorised_id'] = $this->config->get('klarna_checkout_order_status_authorised_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_part_captured_id'])) { + $data['klarna_checkout_order_status_part_captured_id'] = $this->request->post['klarna_checkout_order_status_part_captured_id']; + } else { + $data['klarna_checkout_order_status_part_captured_id'] = $this->config->get('klarna_checkout_order_status_part_captured_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_captured_id'])) { + $data['klarna_checkout_order_status_captured_id'] = $this->request->post['klarna_checkout_order_status_captured_id']; + } else { + $data['klarna_checkout_order_status_captured_id'] = $this->config->get('klarna_checkout_order_status_captured_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_cancelled_id'])) { + $data['klarna_checkout_order_status_cancelled_id'] = $this->request->post['klarna_checkout_order_status_cancelled_id']; + } else { + $data['klarna_checkout_order_status_cancelled_id'] = $this->config->get('klarna_checkout_order_status_cancelled_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_refund_id'])) { + $data['klarna_checkout_order_status_refund_id'] = $this->request->post['klarna_checkout_order_status_refund_id']; + } else { + $data['klarna_checkout_order_status_refund_id'] = $this->config->get('klarna_checkout_order_status_refund_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_fraud_rejected_id'])) { + $data['klarna_checkout_order_status_fraud_rejected_id'] = $this->request->post['klarna_checkout_order_status_fraud_rejected_id']; + } else { + $data['klarna_checkout_order_status_fraud_rejected_id'] = $this->config->get('klarna_checkout_order_status_fraud_rejected_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_fraud_pending_id'])) { + $data['klarna_checkout_order_status_fraud_pending_id'] = $this->request->post['klarna_checkout_order_status_fraud_pending_id']; + } else { + $data['klarna_checkout_order_status_fraud_pending_id'] = $this->config->get('klarna_checkout_order_status_fraud_pending_id'); + } + + if (isset($this->request->post['klarna_checkout_order_status_fraud_accepted_id'])) { + $data['klarna_checkout_order_status_fraud_accepted_id'] = $this->request->post['klarna_checkout_order_status_fraud_accepted_id']; + } else { + $data['klarna_checkout_order_status_fraud_accepted_id'] = $this->config->get('klarna_checkout_order_status_fraud_accepted_id'); + } + + if (isset($this->request->post['klarna_checkout_terms'])) { + $data['klarna_checkout_terms'] = $this->request->post['klarna_checkout_terms']; + } else { + $data['klarna_checkout_terms'] = $this->config->get('klarna_checkout_terms'); + } + + if (isset($this->request->post['klarna_checkout_status'])) { + $data['klarna_checkout_status'] = $this->request->post['klarna_checkout_status']; + } else { + $data['klarna_checkout_status'] = $this->config->get('klarna_checkout_status'); + } + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && !isset($this->request->post['klarna_checkout_account'])) { + $data['klarna_checkout_account'] = array(); + } elseif ($this->request->server['REQUEST_METHOD'] == 'POST' && isset($this->request->post['klarna_checkout_account'])) { + $data['klarna_checkout_account'] = $this->request->post['klarna_checkout_account']; + } elseif ($this->config->get('klarna_checkout_account')) { + $data['klarna_checkout_account'] = $this->config->get('klarna_checkout_account'); + } else { + $data['klarna_checkout_account'] = array(); + } + + if (isset($this->request->post['klarna_checkout_sftp_username'])) { + $data['klarna_checkout_sftp_username'] = $this->request->post['klarna_checkout_sftp_username']; + } else { + $data['klarna_checkout_sftp_username'] = $this->config->get('klarna_checkout_sftp_username'); + } + + if (isset($this->request->post['klarna_checkout_sftp_password'])) { + $data['klarna_checkout_sftp_password'] = $this->request->post['klarna_checkout_sftp_password']; + } else { + $data['klarna_checkout_sftp_password'] = $this->config->get('klarna_checkout_sftp_password'); + } + + if (isset($this->request->post['klarna_checkout_settlement_order_status_id'])) { + $data['klarna_checkout_settlement_order_status_id'] = $this->request->post['klarna_checkout_settlement_order_status_id']; + } else { + $data['klarna_checkout_settlement_order_status_id'] = $this->config->get('klarna_checkout_settlement_order_status_id'); + } + + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info) { + $data['api_id'] = $api_info['api_id']; + $data['api_key'] = $api_info['key']; + $data['api_ip'] = $this->request->server['REMOTE_ADDR']; + } else { + $data['api_id'] = ''; + $data['api_key'] = ''; + $data['api_ip'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/klarna_checkout', $data)); + } + + public function order() { + $this->load->language('extension/payment/klarna_checkout'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + return $this->load->view('extension/payment/klarna_checkout_order', $data); + } + + public function getTransaction() { + $this->load->language('extension/payment/klarna_checkout'); + + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('sale/order'); + + if (!$this->config->get('klarna_checkout_status') || !isset($this->request->get['order_id'])) { + return; + } + + $order_reference = $this->model_extension_payment_klarna_checkout->getOrder($this->request->get['order_id']); + + $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']); + + if (!$order_reference || !$order_reference['order_ref'] || !$order_info) { + return; + } + + list($klarna_account, $connector) = $this->model_extension_payment_klarna_checkout->getConnector($this->config->get('klarna_checkout_account'), $order_info['currency_code']); + + if (!$klarna_account || !$connector) { + return; + } + + $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $order_reference['order_ref']); + + if (!$klarna_order) { + return; + } + + $data['order_ref'] = $order_reference['order_ref']; + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + $extend_authorization_action = $cancel_action = $capture_action = $refund_action = $merchant_reference_action = $address_action = $release_authorization_action = false; + + switch (strtoupper($klarna_order['status'])) { + case 'AUTHORIZED': + $merchant_reference_action = true; + $extend_authorization_action = true; + $address_action = true; + $cancel_action = true; + $capture_action = true; + break; + case 'PART_CAPTURED': + $merchant_reference_action = true; + $extend_authorization_action = true; + $release_authorization_action = true; + $address_action = true; + $capture_action = true; + $refund_action = true; + break; + case 'CAPTURED': + $address_action = true; + $merchant_reference_action = true; + $refund_action = true; + break; + case 'CANCELLED': + break; + case 'EXPIRED': + break; + case 'CLOSED': + break; + } + + $format = '{title} {given_name} {family_name}' . "\n" . '{street_address}' . "\n" . '{street_address2}' . "\n" . '{city} {postcode}' . "\n" . '{region}' . "\n" . '{country}' . "\n" . '{email} {phone}'; + + $find = array( + '{title}', + '{given_name}', + '{family_name}', + '{street_address}', + '{street_address2}', + '{city}', + '{postcode}', + '{region}', + '{country}', + '{email}', + '{phone}', + ); + + $replace = array( + 'title' => $klarna_order['billing_address']['title'], + 'given_name' => $klarna_order['billing_address']['given_name'], + 'family_name' => $klarna_order['billing_address']['family_name'], + 'street_address' => $klarna_order['billing_address']['street_address'], + 'street_address2' => $klarna_order['billing_address']['street_address2'], + 'city' => $klarna_order['billing_address']['city'], + 'postcode' => $klarna_order['billing_address']['postal_code'], + 'region' => $klarna_order['billing_address']['region'], + 'country' => $klarna_order['billing_address']['country'], + 'email' => $klarna_order['billing_address']['email'], + 'phone' => $klarna_order['billing_address']['phone'] + ); + + $billing_address_formatted = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + $replace = array( + 'title' => $klarna_order['shipping_address']['title'], + 'given_name' => $klarna_order['shipping_address']['given_name'], + 'family_name' => $klarna_order['shipping_address']['family_name'], + 'street_address' => $klarna_order['shipping_address']['street_address'], + 'street_address2' => $klarna_order['shipping_address']['street_address2'], + 'city' => $klarna_order['shipping_address']['city'], + 'postcode' => $klarna_order['shipping_address']['postal_code'], + 'region' => $klarna_order['shipping_address']['region'], + 'country' => $klarna_order['shipping_address']['country'], + 'email' => $klarna_order['shipping_address']['email'], + 'phone' => $klarna_order['shipping_address']['phone'] + ); + + $shipping_address_formatted = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format)))); + + $order_lines = array(); + + foreach ($klarna_order['order_lines'] as $order_line) { + $order_lines[] = array( + 'reference' => $order_line['reference'], + 'type' => $order_line['type'], + 'quantity' => $order_line['quantity'], + 'quantity_unit' => $order_line['quantity_unit'], + 'name' => $order_line['name'], + 'total_amount' => $this->currency->format($order_line['total_amount'] / 100, $order_info['currency_code'], '1.00000000'), + 'unit_price' => $this->currency->format($order_line['unit_price'] / 100, $order_info['currency_code'], '1.00000000'), + 'total_discount_amount' => $this->currency->format($order_line['total_discount_amount'] / 100, $order_info['currency_code'], '1.00000000'), + 'tax_rate' => ($order_line['tax_rate'] / 100) . '%', + 'total_tax_amount' => $this->currency->format($order_line['total_tax_amount'] / 100, $order_info['currency_code'], '1.00000000') + ); + } + + $merchant_id = ''; + if ($order_reference['data']) { + $klarna_checkout_order_data = json_decode($this->encryption->decrypt($this->config->get('config_encryption'), $order_reference['data']), true); + if ($klarna_checkout_order_data && $klarna_checkout_order_data['merchant_id']) { + $merchant_id = $klarna_checkout_order_data['merchant_id']; + } + } + + $data['transaction'] = array( + 'order_id' => $klarna_order['order_id'], + 'merchant_id' => $merchant_id, + 'reference' => $klarna_order['klarna_reference'], + 'status' => $klarna_order['status'], + 'fraud_status' => $klarna_order['fraud_status'], + 'merchant_reference_1' => $klarna_order['merchant_reference1'], + 'billing_address' => $klarna_order['billing_address'], + 'shipping_address' => $klarna_order['shipping_address'], + 'billing_address_formatted' => $billing_address_formatted, + 'shipping_address_formatted' => $shipping_address_formatted, + 'order_lines' => $order_lines, + 'amount' => $this->currency->format($klarna_order['order_amount'] / 100, $order_info['currency_code'], '1.00000000'), + 'authorization_expiry' => isset($klarna_order['expires_at']) ? date($this->language->get('date_format_short'), strtotime($klarna_order['expires_at'])) : '', + 'authorization_remaining' => $this->currency->format($klarna_order['remaining_authorized_amount'] / 100, $order_info['currency_code'], '1.00000000'), + ); + + $max_capture_amount = $klarna_order['remaining_authorized_amount'] / 100; + + $max_refund_amount = $klarna_order['captured_amount'] / 100; + + $data['captures'] = array(); + + foreach ($klarna_order['captures'] as $capture) { + $data['captures'][] = array( + 'capture_id' => $capture['capture_id'], + 'shipping_info_title' => sprintf($this->language->get('text_capture_shipping_info_title'), $capture['capture_id']), + 'billing_address_title' => sprintf($this->language->get('text_capture_billing_address_title'), $capture['capture_id']), + 'date_added' => date($this->language->get('datetime_format'), strtotime($capture['captured_at'])), + 'amount' => $this->currency->format($capture['captured_amount'] / 100, $order_info['currency_code'], '1.00000000', true), + 'reference' => $capture['klarna_reference'], + 'shipping_info' => $capture['shipping_info'], + 'billing_address' => $capture['billing_address'], + 'shipping_address' => $capture['shipping_address'] + ); + } + + $data['refunds'] = array(); + + foreach ($klarna_order['refunds'] as $capture) { + $max_refund_amount -= ($capture['refunded_amount'] / 100); + + $data['refunds'][] = array( + 'date_added' => date($this->language->get('datetime_format'), strtotime($capture['refunded_at'])), + 'amount' => $this->currency->format($capture['refunded_amount'] / 100, $order_info['currency_code'], '1.00000000', true) + ); + } + + if (!$max_capture_amount) { + $capture_action = false; + } + + if (!$max_refund_amount) { + $refund_action = false; + } + + $data['allowed_shipping_methods'] = array( + 'PickUpStore', + 'Home', + 'BoxReg', + 'BoxUnreg', + 'PickUpPoint', + 'Own' + ); + + $data['extend_authorization_action'] = $extend_authorization_action; + $data['cancel_action'] = $cancel_action; + $data['capture_action'] = $capture_action; + $data['refund_action'] = $refund_action; + $data['address_action'] = $address_action; + $data['merchant_reference_action'] = $merchant_reference_action; + $data['release_authorization_action'] = $release_authorization_action; + $data['max_capture_amount'] = $this->currency->format($max_capture_amount, $order_info['currency_code'], '1.00000000', false); + $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $order_info['currency_code'], '1.00000000', false); + $data['symbol_left'] = $this->currency->getSymbolLeft($order_info['currency_code']); + $data['symbol_right'] = $this->currency->getSymbolRight($order_info['currency_code']); + + // The URL we send API requests to + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $this->response->setOutput($this->load->view('extension/payment/klarna_checkout_order_ajax', $data)); + } + + public function install() { + $this->load->model('extension/payment/klarna_checkout'); + $this->model_extension_payment_klarna_checkout->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/klarna_checkout'); + $this->model_extension_payment_klarna_checkout->uninstall(); + } + + public function transactionCommand() { + $this->load->language('extension/payment/klarna_checkout'); + + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('sale/order'); + + $json = array(); + + $success = $error = ''; + + $order_info = $this->model_sale_order->getOrder($this->request->get['order_id']); + + list($klarna_account, $connector) = $this->model_extension_payment_klarna_checkout->getConnector($this->config->get('klarna_checkout_account'), $order_info['currency_code']); + + if (!$klarna_account || !$connector) { + return; + } + + $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $this->request->post['order_ref']); + + if (!$klarna_order) { + return; + } + + $old_klarna_status = $klarna_order['status']; + + if ($this->request->post['type'] == 'cancel') { + $action = $this->model_extension_payment_klarna_checkout->omCancel($connector, $this->request->post['order_ref']); + } elseif ($this->request->post['type'] == 'capture' && $this->request->post['data']) { + $action = $this->model_extension_payment_klarna_checkout->omCapture($connector, $this->request->post['order_ref'], array( + 'captured_amount' => $this->request->post['data'] * 100 + )); + } elseif ($this->request->post['type'] == 'refund' && $this->request->post['data']) { + $action = $this->model_extension_payment_klarna_checkout->omRefund($connector, $this->request->post['order_ref'], array( + 'refunded_amount' => $this->request->post['data'] * 100 + )); + } elseif ($this->request->post['type'] == 'extend_authorization') { + $action = $this->model_extension_payment_klarna_checkout->omExtendAuthorizationTime($connector, $this->request->post['order_ref']); + } elseif ($this->request->post['type'] == 'merchant_reference' && $this->request->post['data']) { + $data = array(); + parse_str(html_entity_decode($this->request->post['data']), $data); + + $action = $this->model_extension_payment_klarna_checkout->omUpdateMerchantReference($connector, $this->request->post['order_ref'], array( + 'merchant_reference1' => (string)$data['merchant_reference_1'] + )); + } elseif (($this->request->post['type'] == 'billing_address' || $this->request->post['type'] == 'shipping_address') && $this->request->post['data']) { + if ($this->request->post['type'] == 'billing_address') { + $data['billing_address'] = array(); + parse_str(html_entity_decode($this->request->post['data']), $data['billing_address']); + } else if ($this->request->post['type'] == 'shipping_address') { + $data['shipping_address'] = array(); + parse_str(html_entity_decode($this->request->post['data']), $data['shipping_address']); + } + + $action = $this->model_extension_payment_klarna_checkout->omUpdateAddress($connector, $this->request->post['order_ref'], $data); + } elseif ($this->request->post['type'] == 'release_authorization') { + $action = $this->model_extension_payment_klarna_checkout->omReleaseAuthorization($connector, $this->request->post['order_ref']); + } elseif ($this->request->post['type'] == 'capture_shipping_info' && isset($this->request->post['id'])) { + $data = array(); + parse_str(html_entity_decode($this->request->post['data']), $data); + + $action = $this->model_extension_payment_klarna_checkout->omShippingInfo($connector, $this->request->post['order_ref'], $this->request->post['id'], $data); + } elseif ($this->request->post['type'] == 'capture_billing_address' && isset($this->request->post['id'])) { + $data['billing_address'] = array(); + parse_str(html_entity_decode($this->request->post['data']), $data['billing_address']); + + $action = $this->model_extension_payment_klarna_checkout->omCustomerDetails($connector, $this->request->post['order_ref'], $this->request->post['id'], $data); + } elseif ($this->request->post['type'] == 'trigger_send_out' && isset($this->request->post['id'])) { + $action = $this->model_extension_payment_klarna_checkout->omTriggerSendOut($connector, $this->request->post['order_ref'], $this->request->post['id']); + } else { + $error = true; + } + + $klarna_order = $this->model_extension_payment_klarna_checkout->omRetrieve($connector, $this->request->post['order_ref']); + + if (!$klarna_order) { + return; + } + + $new_klarna_status = $klarna_order['status']; + + $order_status_id = ''; + if ($old_klarna_status != $new_klarna_status) { + switch ($klarna_order['status']) { + case 'AUTHORIZED': + $order_status_id = $this->config->get('klarna_checkout_order_status_authorised_id'); + + if ($klarna_order['fraud_status'] == 'PENDING') { + $order_status_id = $this->config->get('klarna_checkout_order_status_fraud_pending_id'); + } elseif ($klarna_order['fraud_status'] == 'REJECTED') { + $order_status_id = $this->config->get('klarna_checkout_order_status_fraud_rejected_id'); + } + break; + case 'PART_CAPTURED': + $order_status_id = $this->config->get('klarna_checkout_order_status_part_captured_id'); + break; + case 'CAPTURED': + $order_status_id = $this->config->get('klarna_checkout_order_status_captured_id'); + break; + case 'CANCELLED': + $order_status_id = $this->config->get('klarna_checkout_order_status_cancelled_id'); + break; + } + } elseif ($this->request->post['type'] == 'refund' && ($klarna_order['captured_amount'] - $klarna_order['refunded_amount'] == 0)) { + $order_status_id = $this->config->get('klarna_checkout_order_status_refund_id'); + } + + if (!$error && $action) { + $success = $this->language->get('text_success_action'); + } elseif (!$error && $action && isset($action->message)) { + $error = sprintf($this->language->get('text_error_settle'), $action->message); + } else { + $error = $this->language->get('text_error_generic'); + } + + $json['success'] = $success; + $json['error'] = $error; + $json['order_status_id'] = $order_status_id; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function downloadSettlementFiles() { + $this->load->language('extension/payment/klarna_checkout'); + + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('sale/order'); + + $json = array(); + + $error = array(); + + $klarna_checkout_directory = DIR_UPLOAD . 'klarna_checkout/'; + + if (isset($this->request->post['username'])) { + $username = $this->request->post['username']; + } else { + $username = ''; + } + + if (isset($this->request->post['password'])) { + $password = html_entity_decode($this->request->post['password']); + } else { + $password = ''; + } + + if (isset($this->request->post['order_status_id'])) { + $order_status_id = $this->request->post['order_status_id']; + } else { + $order_status_id = false; + } + + if (!$username || !$password || !$order_status_id) { + $error[] = 'Please supply a username, password and order status'; + } + + if (!$error) { + // Connect to the site via FTP + $connection = ftp_connect('mft.klarna.com', '4001'); + + $files = array(); + + if ($connection) { + $login = ftp_login($connection, $username, $password); + + if ($login) { + $files = ftp_nlist($connection, '.'); + + rsort($files); + + if (!is_dir($klarna_checkout_directory)) { + mkdir($klarna_checkout_directory, 0777); + } + + // Save all files to local + foreach (array_diff($files, array('.', '..')) as $file) { + if (!ftp_get($connection, $klarna_checkout_directory . $file, $file, FTP_BINARY)) { + $error[] = 'There was a problem saving one or more files'; + } + } + } + } + } + + $orders_to_process = array(); + + $files = scandir($klarna_checkout_directory); + + if (!$error) { + // Loop local files and process + foreach (array_diff($files, array('.', '..')) as $file) { + $handle = fopen($klarna_checkout_directory . $file, 'r'); + + // Skip first 2 lines, use third as headings + fgetcsv($handle); + fgetcsv($handle); + $headings = fgetcsv($handle); + + while ($data = fgetcsv($handle)) { + $row = array_combine($headings, $data); + + if ($row['type'] == 'SALE') { + $order_id = $this->encryption->decrypt($this->config->get('config_encryption'), $row['merchant_reference1']); + + $klarna_order_info = $this->model_extension_payment_klarna_checkout->getOrder($order_id); + + $order_info = $this->model_sale_order->getOrder($order_id); + + // Check if order exists in system, if it does, pass back to process + if ($klarna_order_info && $order_info && ($order_info['payment_code'] == 'klarna_checkout') && ($order_info['order_status_id'] != $order_status_id)) { + $orders_to_process[] = $order_id; + } + } + } + + fclose($handle); + } + } + + // Delete local files + foreach (array_diff($files, array('.', '..')) as $file) { + if (!unlink($klarna_checkout_directory . $file)) { + $error[] = 'Cannot delete files'; + } + } + + if ($error) { + $orders_to_process = array(); + } + + $json['error'] = $error; + $json['orders'] = $orders_to_process; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + $this->load->model('extension/payment/klarna_checkout'); + $this->load->model('localisation/geo_zone'); + + if (version_compare(phpversion(), '5.4.0', '<')) { + $this->error['warning'] = $this->language->get('error_php_version'); + } + + if (!$this->user->hasPermission('modify', 'extension/payment/klarna_checkout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->config->get('config_secure')) { + $this->error['warning'] = $this->language->get('error_ssl'); + } + + if (empty($this->request->post['klarna_checkout_account'])) { + $this->error['account_warning'] = $this->language->get('error_account_minimum'); + } else { + $currencies = array(); + + foreach ($this->request->post['klarna_checkout_account'] as $key => $account) { + if (in_array($account['currency'], $currencies)) { + $this->error['account_warning'] = $this->language->get('error_account_currency'); + + break; + } else { + $currencies[] = $account['currency']; + } + + if (!$account['merchant_id']) { + $this->error['account'][$key]['merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$account['secret']) { + $this->error['account'][$key]['secret'] = $this->language->get('error_secret'); + } + + if (!$account['locale']) { + $this->error['account'][$key]['locale'] = $this->language->get('error_locale'); + } + } + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/klarna_invoice.php b/public/admin/controller/extension/payment/klarna_invoice.php new file mode 100644 index 0000000..584d9cd --- /dev/null +++ b/public/admin/controller/extension/payment/klarna_invoice.php @@ -0,0 +1,201 @@ +<?php +class ControllerExtensionPaymentKlarnaInvoice extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/klarna_invoice'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $status = false; + + foreach ($this->request->post['payment_klarna_invoice'] as $klarna_invoice) { + if ($klarna_invoice['status']) { + $status = true; + + break; + } + } + + $klarna_data = array( + 'klarna_invoice_pclasses' => $this->pclasses, + 'klarna_invoice_status' => $status + ); + + $this->model_setting_setting->editSetting('payment_klarna_invoice', array_merge($this->request->post, $klarna_data)); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/klarna_invoice', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/klarna_invoice', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['countries'] = array(); + + $data['countries'][] = array( + 'name' => $this->language->get('text_germany'), + 'code' => 'DEU' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_netherlands'), + 'code' => 'NLD' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_denmark'), + 'code' => 'DNK' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_sweden'), + 'code' => 'SWE' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_norway'), + 'code' => 'NOR' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_finland'), + 'code' => 'FIN' + ); + + if (isset($this->request->post['payment_klarna_invoice'])) { + $data['payment_klarna_invoice'] = $this->request->post['payment_klarna_invoice']; + } else { + $data['payment_klarna_invoice'] = $this->config->get('payment_klarna_invoice'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $file = DIR_LOGS . 'klarna_invoice.log'; + + if (file_exists($file)) { + $data['log'] = file_get_contents($file, FILE_USE_INCLUDE_PATH, null); + } else { + $data['log'] = ''; + } + + $data['clear'] = $this->url->link('extension/payment/klarna_invoice/clear', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/klarna_invoice', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/klarna_invoice')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + private function parseResponse($node, $document) { + $child = $node; + + switch ($child->nodeName) { + case 'string': + $value = $child->nodeValue; + break; + + case 'boolean': + $value = (string)$child->nodeValue; + + if ($value == '0') { + $value = false; + } elseif ($value == '1') { + $value = true; + } else { + $value = null; + } + + break; + + case 'integer': + case 'int': + case 'i4': + case 'i8': + $value = (int)$child->nodeValue; + break; + + case 'array': + $value = array(); + + $xpath = new DOMXPath($document); + $entries = $xpath->query('.//array/data/value', $child); + + for ($i = 0; $i < $entries->length; $i++) { + $value[] = $this->parseResponse($entries->item($i)->firstChild, $document); + } + + break; + + default: + $value = null; + } + + return $value; + } + + public function clear() { + $this->load->language('extension/payment/klarna_invoice'); + + $file = DIR_LOGS . 'klarna_invoice.log'; + + $handle = fopen($file, 'w+'); + + fclose($handle); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('extension/payment/klarna_invoice', 'user_token=' . $this->session->data['user_token'], true)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/laybuy.php b/public/admin/controller/extension/payment/laybuy.php new file mode 100644 index 0000000..5c9cd86 --- /dev/null +++ b/public/admin/controller/extension/payment/laybuy.php @@ -0,0 +1,1121 @@ +<?php +class ControllerExtensionPaymentLaybuy extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + + $this->load->model('extension/payment/laybuy'); + + $this->load->language('extension/payment/laybuy'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + unset($this->request->post['laybuy_cron_url'], $this->request->post['laybuy_cron_time']); + + $this->model_setting_setting->editSetting('payment_laybuy', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true); + + $data['fetch'] = $this->url->link('extension/payment/laybuy/fetch', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_laybuys_membership_id'])) { + $data['payment_laybuys_membership_id'] = $this->request->post['payment_laybuys_membership_id']; + } else { + $data['payment_laybuys_membership_id'] = $this->config->get('payment_laybuys_membership_id'); + } + + if (isset($this->request->post['payment_laybuy_token'])) { + $data['payment_laybuy_token'] = $this->request->post['payment_laybuy_token']; + } elseif ($this->config->has('payment_laybuy_token')) { + $data['payment_laybuy_token'] = $this->config->get('payment_laybuy_token'); + } else { + $data['payment_laybuy_token'] = md5(time()); + } + + if (isset($this->request->post['payment_laybuy_min_deposit'])) { + $data['payment_laybuy_min_deposit'] = $this->request->post['payment_laybuy_min_deposit']; + } elseif ($this->config->get('payment_laybuy_min_deposit')) { + $data['payment_laybuy_min_deposit'] = $this->config->get('payment_laybuy_min_deposit'); + } else { + $data['payment_laybuy_min_deposit'] = '20'; + } + + if (isset($this->request->post['payment_laybuy_max_deposit'])) { + $data['payment_laybuy_max_deposit'] = $this->request->post['payment_laybuy_max_deposit']; + } elseif ($this->config->get('payment_laybuy_max_deposit')) { + $data['payment_laybuy_max_deposit'] = $this->config->get('payment_laybuy_max_deposit'); + } else { + $data['payment_laybuy_max_deposit'] = '50'; + } + + if (isset($this->request->post['payment_laybuy_max_months'])) { + $data['payment_laybuy_max_months'] = $this->request->post['payment_laybuy_max_months']; + } elseif ($this->config->get('payment_laybuy_max_months')) { + $data['payment_laybuy_max_months'] = $this->config->get('payment_laybuy_max_months'); + } else { + $data['payment_laybuy_max_months'] = '3'; + } + + if (isset($this->request->post['payment_laybuy_category'])) { + $data['payment_laybuy_category'] = $this->request->post['payment_laybuy_category']; + } elseif ($this->config->get('payment_laybuy_category')) { + $data['payment_laybuy_category'] = $this->config->get('payment_laybuy_category'); + } else { + $data['payment_laybuy_category'] = array(); + } + + $data['categories'] = array(); + + $this->load->model('catalog/category'); + + foreach ($data['payment_laybuy_category'] as $category_id) { + $category_info = $this->model_catalog_category->getCategory($category_id); + + if ($category_info) { + $data['categories'][] = array( + 'category_id' => $category_info['category_id'], + 'name' => ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name'] + ); + } + } + + if (isset($this->request->post['payment_laybuy_xproducts'])) { + $data['payment_laybuy_xproducts'] = $this->request->post['payment_laybuy_xproducts']; + } else { + $data['payment_laybuy_xproducts'] = $this->config->get('payment_laybuy_xproducts'); + } + + if (isset($this->request->post['payment_laybuy_customer_group'])) { + $data['payment_laybuy_customer_group'] = $this->request->post['payment_laybuy_customer_group']; + } elseif ($this->config->get('payment_laybuy_customer_group')) { + $data['payment_laybuy_customer_group'] = $this->config->get('payment_laybuy_customer_group'); + } else { + $data['payment_laybuy_customer_group'] = array(); + } + + $data['customer_groups'] = array(); + + $this->load->model('customer/customer_group'); + + foreach ($data['payment_laybuy_customer_group'] as $customer_group_id) { + $customer_group_info = $this->model_customer_customer_group->getCustomerGroup($customer_group_id); + + if ($customer_group_info) { + $data['customer_groups'][] = array( + 'customer_group_id' => $customer_group_info['customer_group_id'], + 'name' => $customer_group_info['name'] + ); + } + } + + if (isset($this->request->post['payment_laybuy_logging'])) { + $data['payment_laybuy_logging'] = $this->request->post['payment_laybuy_logging']; + } else { + $data['payment_laybuy_logging'] = $this->config->get('payment_laybuy_logging'); + } + + if (isset($this->request->post['payment_laybuy_total'])) { + $data['payment_laybuy_total'] = $this->request->post['payment_laybuy_total']; + } else { + $data['payment_laybuy_total'] = $this->config->get('payment_laybuy_total'); + } + + if (isset($this->request->post['payment_laybuy_order_status_id_pending'])) { + $data['payment_laybuy_order_status_id_pending'] = $this->request->post['payment_laybuy_order_status_id_pending']; + } elseif ($this->config->get('payment_laybuy_order_status_id_pending')) { + $data['payment_laybuy_order_status_id_pending'] = $this->config->get('payment_laybuy_order_status_id_pending'); + } else { + $data['payment_laybuy_order_status_id_pending'] = '1'; + } + + if (isset($this->request->post['payment_laybuy_order_status_id_canceled'])) { + $data['payment_laybuy_order_status_id_canceled'] = $this->request->post['payment_laybuy_order_status_id_canceled']; + } elseif ($this->config->get('payment_laybuy_order_status_id_canceled')) { + $data['payment_laybuy_order_status_id_canceled'] = $this->config->get('payment_laybuy_order_status_id_canceled'); + } else { + $data['payment_laybuy_order_status_id_canceled'] = '7'; + } + + if (isset($this->request->post['payment_laybuy_order_status_id_processing'])) { + $data['payment_laybuy_order_status_id_processing'] = $this->request->post['payment_laybuy_order_status_id_processing']; + } elseif ($this->config->get('payment_laybuy_order_status_id_processing')) { + $data['payment_laybuy_order_status_id_processing'] = $this->config->get('payment_laybuy_order_status_id_processing'); + } else { + $data['payment_laybuy_order_status_id_processing'] = '2'; + } + + if (isset($this->request->post['payment_laybuy_gateway_url'])) { + $data['payment_laybuy_gateway_url'] = $this->request->post['payment_laybuy_gateway_url']; + } elseif ($this->config->get('payment_laybuy_gateway_url')) { + $data['payment_laybuy_gateway_url'] = $this->config->get('payment_laybuy_gateway_url'); + } else { + $data['payment_laybuy_gateway_url'] = 'http://lay-buys.com/gateway/'; + } + + if (isset($this->request->post['payment_laybuy_api_url'])) { + $data['payment_laybuy_api_url'] = $this->request->post['payment_laybuy_api_url']; + } elseif ($this->config->get('payment_laybuy_api_url')) { + $data['payment_laybuy_api_url'] = $this->config->get('payment_laybuy_api_url'); + } else { + $data['payment_laybuy_api_url'] = 'https://lay-buys.com/report/'; + } + + if (isset($this->request->post['payment_laybuy_geo_zone_id'])) { + $data['payment_laybuy_geo_zone_id'] = $this->request->post['payment_laybuy_geo_zone_id']; + } else { + $data['payment_laybuy_geo_zone_id'] = $this->config->get('payment_laybuy_geo_zone_id'); + } + + if (isset($this->request->post['payment_laybuy_status'])) { + $data['payment_laybuy_status'] = $this->request->post['payment_laybuy_status']; + } else { + $data['payment_laybuy_status'] = $this->config->get('payment_laybuy_status'); + } + + if (isset($this->request->post['payment_laybuy_sort_order'])) { + $data['payment_laybuy_sort_order'] = $this->request->post['payment_laybuy_sort_order']; + } else { + $data['payment_laybuy_sort_order'] = $this->config->get('payment_laybuy_sort_order'); + } + + $data['laybuy_cron_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/cron&token=' . $data['payment_laybuy_token']; + + if ($this->config->get('laybuy_cron_time')) { + $data['laybuy_cron_time'] = date($this->language->get('datetime_format'), strtotime($this->config->get('laybuy_cron_time'))); + } else { + $data['laybuy_cron_time'] = $this->language->get('text_no_cron_time'); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['laybuys_membership_id'])) { + $data['error_laybuys_membership_id'] = $this->error['laybuys_membership_id']; + } else { + $data['error_laybuys_membership_id'] = ''; + } + + if (isset($this->error['laybuy_token'])) { + $data['error_laybuy_token'] = $this->error['laybuy_token']; + } else { + $data['error_laybuy_token'] = ''; + } + + if (isset($this->error['laybuy_min_deposit'])) { + $data['error_laybuy_min_deposit'] = $this->error['laybuy_min_deposit']; + } else { + $data['error_laybuy_min_deposit'] = ''; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + /* Reports tab */ + if (isset($this->request->get['filter_order_id'])) { + $filter_order_id = $this->request->get['filter_order_id']; + } else { + $filter_order_id = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_dp_percent'])) { + $filter_dp_percent = $this->request->get['filter_dp_percent']; + } else { + $filter_dp_percent = ''; + } + + if (isset($this->request->get['filter_months'])) { + $filter_months = $this->request->get['filter_months']; + } else { + $filter_months = ''; + } + + if (isset($this->request->get['filter_status'])) { + $filter_status = $this->request->get['filter_status']; + } else { + $filter_status = ''; + } + + if (isset($this->request->get['filter_date_added'])) { + $filter_date_added = $this->request->get['filter_date_added']; + } else { + $filter_date_added = ''; + } + + if (isset($this->request->get['sort'])) { + $sort = $this->request->get['sort']; + } else { + $sort = 'lt.order_id'; + } + + if (isset($this->request->get['order'])) { + $order = $this->request->get['order']; + } else { + $order = 'DESC'; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['reports'] = array(); + + $filter_data = array( + 'filter_order_id' => $filter_order_id, + 'filter_customer' => $filter_customer, + 'filter_dp_percent' => $filter_dp_percent, + 'filter_months' => $filter_months, + 'filter_status' => $filter_status, + 'filter_date_added' => $filter_date_added, + 'sort' => $sort, + 'order' => $order, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $report_total = $this->model_extension_payment_laybuy->getTotalTransactions($filter_data); + + $results = $this->model_extension_payment_laybuy->getTransactions($filter_data); + + foreach ($results as $result) { + $customer_url = false; + + $customer_id = $this->model_extension_payment_laybuy->getCustomerIdByOrderId($result['order_id']); + + if ($customer_id) { + $customer_url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . (int)$customer_id, true); + } + + $data['reports'][] = array( + 'id' => $result['laybuy_transaction_id'], + 'order_id' => $result['order_id'], + 'order_url' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$result['order_id'], true), + 'customer_name' => $result['firstname'] . ' ' . $result['lastname'], + 'customer_url' => $customer_url, + 'amount' => $this->currency->format($result['amount'], $result['currency']), + 'dp_percent' => $result['downpayment'], + 'months' => $result['months'], + 'dp_amount' => $this->currency->format($result['downpayment_amount'], $result['currency']), + 'first_payment' => date($this->language->get('date_format_short'), strtotime($result['first_payment_due'])), + 'last_payment' => date($this->language->get('date_format_short'), strtotime($result['last_payment_due'])), + 'status' => $this->model_extension_payment_laybuy->getStatusLabel($result['status']), + 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), + 'view' => $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . (int)$result['laybuy_transaction_id'], true) + ); + } + + if (isset($this->request->post['selected'])) { + $data['selected'] = (array)$this->request->post['selected']; + } else { + $data['selected'] = array(); + } + + $url = ''; + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . urlencode(html_entity_decode($this->request->get['filter_order_id'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_dp_percent'])) { + $url .= '&filter_dp_percent=' . urlencode(html_entity_decode($this->request->get['filter_dp_percent'], ENT_QUOTES, 'UTF-8')); + } + + if (isset($this->request->get['filter_months'])) { + $url .= '&filter_months=' . $this->request->get['filter_months']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if ($order == 'ASC') { + $url .= '&order=DESC'; + } else { + $url .= '&order=ASC'; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $data['sort_order_id'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.order_id' . $url . '#reportstab', true); + $data['sort_customer'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=customer' . $url . '#reportstab', true); + $data['sort_amount'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.amount' . $url . '#reportstab', true); + $data['sort_dp_percent'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.downpayment' . $url . '#reportstab', true); + $data['sort_months'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.months' . $url . '#reportstab', true); + $data['sort_dp_amount'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.downpayment_amount' . $url . '#reportstab', true); + $data['sort_first_payment'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.first_payment_due' . $url . '#reportstab', true); + $data['sort_last_payment'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.last_payment_due' . $url . '#reportstab', true); + $data['sort_status'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.status' . $url . '#reportstab', true); + $data['sort_date_added'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '&sort=lt.date_added' . $url . '#reportstab', true); + + $url = ''; + + if (isset($this->request->get['filter_order_id'])) { + $url .= '&filter_order_id=' . $this->request->get['filter_order_id']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . $this->request->get['filter_customer']; + } + + if (isset($this->request->get['filter_dp_percent'])) { + $url .= '&filter_dp_percent=' . $this->request->get['filter_dp_percent']; + } + + if (isset($this->request->get['filter_months'])) { + $url .= '&filter_months=' . $this->request->get['filter_months']; + } + + if (isset($this->request->get['filter_status'])) { + $url .= '&filter_status=' . $this->request->get['filter_status']; + } + + if (isset($this->request->get['filter_date_added'])) { + $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; + } + + if (isset($this->request->get['sort'])) { + $url .= '&sort=' . $this->request->get['sort']; + } + + if (isset($this->request->get['order'])) { + $url .= '&order=' . $this->request->get['order']; + } + + $pagination = new Pagination(); + $pagination->total = $report_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}#reportstab', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($report_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($report_total - $this->config->get('config_limit_admin'))) ? $report_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $report_total, ceil($report_total / $this->config->get('config_limit_admin'))); + + $data['filter_order_id'] = $filter_order_id; + $data['filter_customer'] = $filter_customer; + $data['filter_dp_percent'] = $filter_dp_percent; + $data['filter_months'] = $filter_months; + $data['filter_status'] = $filter_status; + $data['filter_date_added'] = $filter_date_added; + + $data['sort'] = $sort; + $data['order'] = $order; + + $data['transaction_statuses'] = $this->model_extension_payment_laybuy->getTransactionStatuses(); + /* End of Reports Tab */ + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/laybuy', $data)); + } + + public function fetch() { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->log('Fetching transactions'); + + if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) { + $this->load->language('extension/payment/laybuy'); + + $json = array(); + + $fetched = 0; + + $paypal_profile_id_array = $this->model_extension_payment_laybuy->getPayPalProfileIds(); + + if ($paypal_profile_id_array) { + $paypal_profile_ids = ''; + + foreach ($paypal_profile_id_array as $profile_id) { + $paypal_profile_ids .= $profile_id['paypal_profile_id'] . ','; + } + + $paypal_profile_ids = rtrim($paypal_profile_ids, ','); + + $data_string = 'mid=' . $this->config->get('payment_laybuys_membership_id') . '&' . 'profileIds=' . $paypal_profile_ids; + + $this->model_extension_payment_laybuy->log('Data String: ' . $data_string); + + $this->model_extension_payment_laybuy->log('API URL: ' . $this->config->get('payment_laybuy_api_url')); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $this->config->get('payment_laybuy_api_url')); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + if (curl_errno($ch)) { + $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch)); + } + curl_close($ch); + + $results = json_decode($result, true); + + $this->model_extension_payment_laybuy->log('Response: ' . print_r($results, true)); + + if ($results) { + foreach ($results as $laybuy_ref_id => $reports) { + $status = $reports['status']; + + $report = $reports['report']; + + $transaction = array(); + + $transaction = $this->model_extension_payment_laybuy->getTransactionByLayBuyRefId($laybuy_ref_id); + + $order_id = $transaction['order_id']; + + $paypal_profile_id = $transaction['paypal_profile_id']; + + $months = $transaction['months']; + + $report_content = array(); + + $pending_flag = false; + + $next_payment_status = $this->language->get('text_status_1'); + + foreach ($report as $month => $payment) { + $payment['paymentDate'] = date('Y-m-d h:i:s', strtotime(str_replace('/', '-', $payment['paymentDate']))); + $date = date($this->language->get('date_format_short'), strtotime($payment['paymentDate'])); + $next_payment_date = $payment['paymentDate']; + + if ($payment['type'] == 'd') { + $report_content[] = array( + 'instalment' => 0, + 'amount' => $this->currency->format($payment['amount'], $transaction['currency']), + 'date' => $date, + 'pp_trans_id' => $payment['txnID'], + 'status' => $payment['paymentStatus'] + ); + } elseif ($payment['type'] == 'p') { + $pending_flag = true; + + $report_content[] = array( + 'instalment' => $month, + 'amount' => $this->currency->format($payment['amount'], $transaction['currency']), + 'date' => $date, + 'pp_trans_id' => $payment['txnID'], + 'status' => $payment['paymentStatus'] + ); + + $next_payment_status = $payment['paymentStatus']; + } + } + + if ($pending_flag) { + $start_index = $month + 1; + } else { + $start_index = $month + 2; + } + + if ($month < $months) { + for ($month = 1; $month <= $months; $month++) { + $next_payment_date = date("Y-m-d h:i:s", strtotime($next_payment_date . " +1 month")); + $date = date($this->language->get('date_format_short'), strtotime($next_payment_date)); + + $report_content[] = array( + 'instalment' => $month, + 'amount' => $this->currency->format($transaction['payment_amounts'], $transaction['currency']), + 'date' => $date, + 'pp_trans_id' => '', + 'status' => $next_payment_status + ); + } + } + + $report_content = json_encode($report_content); + + switch ($status) { + case -1: // Cancel + $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' canceled'); + $this->model_extension_payment_laybuy->updateOrderStatus($order_id, $this->config->get('payment_laybuy_order_status_id_canceled'), $this->language->get('text_comment')); + $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], '7', $report_content, $start_index); + $fetched++; + break; + case 0: // Pending + $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' still pending'); + $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], $transaction['status'], $report_content, $start_index); + $fetched++; + break; + case 1: // Paid + $this->model_extension_payment_laybuy->log('Transaction #' . $transaction['laybuy_transaction_id'] . ' paid'); + $this->model_extension_payment_laybuy->updateOrderStatus($order_id, $this->config->get('payment_laybuy_order_status_id_processing'), $this->language->get('text_comment')); + $this->model_extension_payment_laybuy->updateTransaction($transaction['laybuy_transaction_id'], '5', $report_content, $start_index); + $fetched++; + break; + } + } + } + + if ($fetched) { + $this->session->data['success'] = sprintf($this->language->get('text_fetched_some'), $fetched); + } else { + $this->session->data['success'] = $this->language->get('text_fetched_none'); + } + + $this->response->redirect($this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $this->model_extension_payment_laybuy->log('No PayPal Profile IDs to update'); + + $this->session->data['success'] = $this->language->get('text_fetched_none'); + + $this->response->redirect($this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'], true)); + } + } else { + $this->model_extension_payment_laybuy->log('User does not have permission'); + } + } + + public function install() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->install(); + } + } + + public function uninstall() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->uninstall(); + } + } + + public function transaction($order_page = false) { + $this->load->model('extension/payment/laybuy'); + + $this->load->language('extension/payment/laybuy'); + + if (isset($this->request->get['id'])) { + $id = (int)$this->request->get['id']; + } else { + $id = 0; + } + + $data['id'] = $id; + + if (!$order_page) { + $this->document->setTitle($this->language->get('heading_transaction_title')); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_transaction_title'), + 'href' => $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true) + ); + + $data['heading_title'] = $this->language->get('heading_transaction_title'); + + $data['button_cancel'] = $this->language->get('button_cancel'); + + $data['cancel'] = $this->url->link('extension/payment/laybuy', 'user_token=' . $this->session->data['user_token'] . '#reportstab', true); + + $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id); + + if ($transaction_info) { + $data['initial_payments'] = $this->model_extension_payment_laybuy->getInitialPayments(); + + $data['months'] = $this->model_extension_payment_laybuy->getMonths(); + + $data['currency_symbol_left'] = $this->currency->getSymbolLeft($transaction_info['currency']); + + $data['currency_symbol_right'] = $this->currency->getSymbolRight($transaction_info['currency']); + + $data['store_url'] = HTTPS_CATALOG; + + $data['api_key'] = $this->getApiKey(); + + $this->load->model('sale/order'); + + $order = $this->model_sale_order->getOrder($transaction_info['order_id']); + + $data['order_info'] = array( + 'currency_value' => $order['currency_value'] + ); + + $data['total'] = $this->model_extension_payment_laybuy->getRemainingAmount($transaction_info['amount'], $transaction_info['downpayment_amount'], $transaction_info['payment_amounts'], $transaction_info['transaction']); + + $data['transaction'] = array( + 'paypal_profile_id' => $transaction_info['paypal_profile_id'], + 'laybuy_ref_no' => $transaction_info['laybuy_ref_no'], + 'order_id' => $transaction_info['order_id'], + 'firstname' => $transaction_info['firstname'], + 'lastname' => $transaction_info['lastname'], + 'email' => $transaction_info['email'], + 'address' => $transaction_info['address'], + 'suburb' => $transaction_info['suburb'], + 'state' => $transaction_info['state'], + 'country' => $transaction_info['country'], + 'postcode' => $transaction_info['postcode'], + 'status_id' => $transaction_info['status'], + 'status' => $this->model_extension_payment_laybuy->getStatusLabel($transaction_info['status']), + 'amount' => $this->currency->format($transaction_info['amount'], $transaction_info['currency']), + 'remaining' => $this->currency->format($this->model_extension_payment_laybuy->getRemainingAmount($transaction_info['amount'], $transaction_info['downpayment_amount'], $transaction_info['payment_amounts'], $transaction_info['transaction']), $transaction_info['currency']), + 'downpayment' => $transaction_info['downpayment'], + 'months' => $transaction_info['months'], + 'downpayment_amount' => $this->currency->format($transaction_info['downpayment_amount'], $transaction_info['currency']), + 'payment_amounts' => $this->currency->format($transaction_info['payment_amounts'], $transaction_info['currency']), + 'first_payment_due' => date($this->language->get('date_format_short'), strtotime($transaction_info['first_payment_due'])), + 'last_payment_due' => date($this->language->get('date_format_short'), strtotime($transaction_info['last_payment_due'])), + 'report' => json_decode($transaction_info['report'], true) + ); + } else { + $data['transaction'] = array(); + + $data['text_not_found'] = $this->language->get('text_not_found'); + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->session->data['error_warning'])) { + $data['error_warning'] = $this->session->data['error_warning']; + + unset($this->session->data['error_warning']); + } else { + $data['error_warning'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + if ($order_page) { + return $data; + } + + $this->response->setOutput($this->load->view('extension/payment/laybuy_transaction', $data)); + } + + public function cancel() { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->log('Canceling transaction'); + + if ($this->request->get['source'] == 'order') { + $this->model_extension_payment_laybuy->log('Called from order page'); + } else { + $this->model_extension_payment_laybuy->log('Called from extension page'); + } + + if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) { + $this->load->language('extension/payment/laybuy'); + + $json = array(); + + $id = (int)$this->request->get['id']; + + $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id); + + $cancel = false; + + if (!$transaction_info['paypal_profile_id']) { + $this->model_extension_payment_laybuy->log('Transaction has no paypal_profile_id'); + + $cancel = true; + } + + if (!$cancel) { + $data_string = 'mid=' . $this->config->get('payment_laybuys_membership_id') . '&' . 'paypal_profile_id=' . $transaction_info['paypal_profile_id']; + + $this->model_extension_payment_laybuy->log('Data String: ' . $data_string); + + $ch = curl_init(); + $url = 'https://lay-buys.com/vtmob/deal5cancel.php'; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + if (curl_errno($ch)) { + $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch)); + } + curl_close($ch); + + $this->model_extension_payment_laybuy->log('Response: ' . $result); + + if ($result == 'success') { + $this->model_extension_payment_laybuy->log('Success'); + + $cancel = true; + } else { + $this->model_extension_payment_laybuy->log('Failure'); + } + } + + if ($cancel) { + $this->model_extension_payment_laybuy->log('Transaction canceled'); + + $report_content = json_decode($transaction_info['report'], true); + + foreach ($report_content as &$array) { + $array['status'] = str_replace('Pending', 'Canceled', $array['status']); + } + + $report_content = json_encode($report_content); + + $this->model_extension_payment_laybuy->updateTransaction($transaction_info['laybuy_transaction_id'], '7', $report_content, $transaction_info['transaction']); + + $json['success'] = $this->language->get('text_cancel_success'); + + $json['order_id'] = $transaction_info['order_id']; + + $json['order_status_id'] = $this->config->get('payment_laybuy_order_status_id_canceled'); + + $json['comment'] = sprintf($this->language->get('text_comment_canceled'), $transaction_info['paypal_profile_id']); + } else { + $json['error'] = $this->language->get('text_cancel_failure'); + } + + if ($this->request->get['source'] == 'order') { + $json['reload'] = $this->url->link('sale/order/info', 'order_id=' . (int)$transaction_info['order_id'] . '&user_token=' . $this->session->data['user_token'], true); + } else { + $json['reload'] = $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true); + } + + $this->response->setOutput(json_encode($json)); + } else { + $this->model_extension_payment_laybuy->log('User does not have permission'); + } + } + + public function revise() { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->log('Revising transaction'); + + if ($this->request->get['source'] == 'order') { + $this->model_extension_payment_laybuy->log('Called from order page'); + } else { + $this->model_extension_payment_laybuy->log('Called from extension page'); + } + + if ($this->user->hasPermission('modify', 'extension/payment/laybuy')) { + if ($this->request->server['REQUEST_METHOD'] == 'POST') { + $this->load->language('extension/payment/laybuy'); + + $json = array(); + + $payment_type = $this->request->post['payment_type']; + + $amount = $this->request->post['amount']; + + $initial = $this->request->post['INIT']; + + $months = $this->request->post['MONTHS']; + + $id = $this->request->get['id']; + + $transaction_info = $this->model_extension_payment_laybuy->getTransaction($id); + + $original = $new = $transaction_info; + + $original['transaction_id'] = $new['transaction_id'] = $transaction_info['laybuy_transaction_id']; + + $original['payment_type'] = $new['payment_type'] = $payment_type; + + $original['type'] = 'Original'; + + $new['type'] = 'New'; + $new['status'] = '50'; + $new['amount'] = $amount; + $new['downpayment'] = $initial; + $new['months'] = $months; + + $collection = $this->model_extension_payment_laybuy->getRevisedTransactions($id); + + $this->model_extension_payment_laybuy->log('Collection: ' . print_r($collection, true)); + + if (count($collection) == 2) { + $this->model_extension_payment_laybuy->log('Collection == 2'); + + foreach ($collection as $request) { + $this->model_extension_payment_laybuy->log('request: ' . print_r($request, true)); + + if ($request['type'] == 'Original') { + $this->model_extension_payment_laybuy->log('Original: ' . print_r($original, true)); + + $this->model_extension_payment_laybuy->updateRevisedTransaction($id, $original); + } elseif ($request['type'] == 'New') { + $this->model_extension_payment_laybuy->log('New: ' . print_r($new, true)); + + $this->model_extension_payment_laybuy->updateRevisedTransaction($id, $new); + + $revised_transaction = $this->model_extension_payment_laybuy->getRevisedTransaction($id); + } + } + } else { + $this->model_extension_payment_laybuy->log('Collection != 2'); + + $this->model_extension_payment_laybuy->addRevisedTransaction($original); + + $laybuy_revise_request_id = $this->model_extension_payment_laybuy->addRevisedTransaction($new); + + $this->model_extension_payment_laybuy->log('$laybuy_revise_request_id: ' . $laybuy_revise_request_id); + + $revised_transaction = $this->model_extension_payment_laybuy->getRevisedTransaction($laybuy_revise_request_id); + } + + $this->model_extension_payment_laybuy->log('Revised transaction: ' . print_r($revised_transaction, true)); + + if ($revised_transaction['payment_type'] == '1') { + $pp = '1'; + $pplan = '1'; + } else { + $pp = '0'; + $pplan = '0'; + } + + $data = array(); + + $data['mid'] = $this->config->get('payment_laybuys_membership_id'); + $data['eml'] = $revised_transaction['email']; + $data['prc'] = $revised_transaction['amount']; + $data['curr'] = $revised_transaction['currency']; + $data['pp'] = $pp; + $data['pplan'] = $pplan; + $data['init'] = $initial; + $data['mnth'] = $months; + $data['convrate'] = '1'; + $data['id'] = $revised_transaction['laybuy_revise_request_id'] . '-' . $revised_transaction['order_id'] . ':' . md5($this->config->get('payment_laybuy_token')); + $data['RETURNURL'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/reviseCallback'; + $data['CANCELURL'] = HTTPS_CATALOG . 'index.php?route=extension/payment/laybuy/reviseCancel'; + + $data_string = ''; + + foreach ($data as $param => $value) { + $data_string .= $param . '=' . $value . '&'; + } + + $data_string = rtrim($data_string, '&'); + + $this->model_extension_payment_laybuy->log('Data String: ' . $data_string); + + $ch = curl_init(); + $url = 'https://lay-buys.com/vtmob/deal5.php'; + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HEADER, false); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + $result = curl_exec($ch); + if (curl_errno($ch)) { + $this->model_extension_payment_laybuy->log('cURL error: ' . curl_errno($ch)); + } + curl_close($ch); + + if ($result == 'success') { + $this->model_extension_payment_laybuy->log('Success'); + + $this->model_extension_payment_laybuy->updateTransactionStatus($id, '50'); + + $json['success'] = $this->language->get('text_revise_success'); + } else { + $this->model_extension_payment_laybuy->log('Failure'); + + $this->model_extension_payment_laybuy->log('Response: ' . print_r($result, true)); + + $json['error'] = $this->language->get('text_revise_failure'); + } + + if ($this->request->get['source'] == 'order') { + $json['reload'] = $this->url->link('sale/order/info', 'order_id=' . (int)$transaction_info['order_id'] . '&user_token=' . $this->session->data['user_token'], true); + } else { + $json['reload'] = $this->url->link('extension/payment/laybuy/transaction', 'user_token=' . $this->session->data['user_token'] . '&id=' . $id, true); + } + + $this->response->setOutput(json_encode($json)); + } else { + $this->model_extension_payment_laybuy->log('No $_POST data'); + } + } else { + $this->model_extension_payment_laybuy->log('User does not have permission'); + } + } + + public function autocomplete() { + $json = array(); + + if (isset($this->request->get['filter_customer_group'])) { + $this->load->model('customer/customer_group'); + + $results = $this->model_customer_customer_group->getCustomerGroups(); + + foreach ($results as $result) { + $json[] = array( + 'customer_group_id' => $result['customer_group_id'], + 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')) + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function order() { + if ($this->config->get('payment_laybuy_status')) { + $this->load->model('extension/payment/laybuy'); + + $this->load->language('extension/payment/laybuy'); + + $order_id = $this->request->get['order_id']; + + $transaction_info = $this->model_extension_payment_laybuy->getTransactionByOrderId($order_id); + + $laybuy_transaction_id = $transaction_info['laybuy_transaction_id']; + + $this->request->get['id'] = $laybuy_transaction_id; + + $data = $this->transaction(true); + + $data['store_url'] = HTTPS_CATALOG; + + $data['api_key'] = $this->getApiKey(); + + return $this->load->view('extension/payment/laybuy_order', $data); + } + } + + private function getApiKey() { + $this->load->model('extension/payment/laybuy'); + + $this->model_extension_payment_laybuy->log('Getting API key'); + + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info) { + $this->model_extension_payment_laybuy->log('API key: ' . $api_info['key']); + + return $api_info['key']; + } else { + $this->model_extension_payment_laybuy->log('No API info'); + + return; + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/laybuy')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_laybuys_membership_id']) { + $this->error['laybuys_membership_id'] = $this->language->get('error_membership_id'); + } + + if (!$this->request->post['payment_laybuy_token']) { + $this->error['laybuy_token'] = $this->language->get('error_token'); + } + + if ($this->request->post['payment_laybuy_min_deposit'] > $this->request->post['payment_laybuy_max_deposit']) { + $this->error['laybuy_min_deposit'] = $this->language->get('error_min_deposit'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/liqpay.php b/public/admin/controller/extension/payment/liqpay.php new file mode 100644 index 0000000..7f0841c --- /dev/null +++ b/public/admin/controller/extension/payment/liqpay.php @@ -0,0 +1,143 @@ +<?php +class ControllerExtensionPaymentLiqPay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/liqpay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_liqpay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + if (isset($this->error['signature'])) { + $data['error_signature'] = $this->error['signature']; + } else { + $data['error_signature'] = ''; + } + + if (isset($this->error['type'])) { + $data['error_type'] = $this->error['type']; + } else { + $data['error_type'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/liqpay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/liqpay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_liqpay_merchant'])) { + $data['payment_liqpay_merchant'] = $this->request->post['payment_liqpay_merchant']; + } else { + $data['payment_liqpay_merchant'] = $this->config->get('payment_liqpay_merchant'); + } + + if (isset($this->request->post['payment_liqpay_signature'])) { + $data['payment_liqpay_signature'] = $this->request->post['payment_liqpay_signature']; + } else { + $data['payment_liqpay_signature'] = $this->config->get('payment_liqpay_signature'); + } + + if (isset($this->request->post['payment_liqpay_type'])) { + $data['payment_liqpay_type'] = $this->request->post['payment_liqpay_type']; + } else { + $data['payment_liqpay_type'] = $this->config->get('payment_liqpay_type'); + } + + if (isset($this->request->post['payment_liqpay_total'])) { + $data['payment_liqpay_total'] = $this->request->post['payment_liqpay_total']; + } else { + $data['payment_liqpay_total'] = $this->config->get('payment_liqpay_total'); + } + + if (isset($this->request->post['payment_liqpay_order_status_id'])) { + $data['payment_liqpay_order_status_id'] = $this->request->post['payment_liqpay_order_status_id']; + } else { + $data['payment_liqpay_order_status_id'] = $this->config->get('payment_liqpay_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_liqpay_geo_zone_id'])) { + $data['payment_liqpay_geo_zone_id'] = $this->request->post['payment_liqpay_geo_zone_id']; + } else { + $data['payment_liqpay_geo_zone_id'] = $this->config->get('payment_liqpay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_liqpay_status'])) { + $data['payment_liqpay_status'] = $this->request->post['payment_liqpay_status']; + } else { + $data['payment_liqpay_status'] = $this->config->get('payment_liqpay_status'); + } + + if (isset($this->request->post['payment_liqpay_sort_order'])) { + $data['payment_liqpay_sort_order'] = $this->request->post['payment_liqpay_sort_order']; + } else { + $data['payment_liqpay_sort_order'] = $this->config->get('payment_liqpay_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/liqpay', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/liqpay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_liqpay_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + if (!$this->request->post['payment_liqpay_signature']) { + $this->error['signature'] = $this->language->get('error_signature'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/nochex.php b/public/admin/controller/extension/payment/nochex.php new file mode 100644 index 0000000..08e0413 --- /dev/null +++ b/public/admin/controller/extension/payment/nochex.php @@ -0,0 +1,149 @@ +<?php +class ControllerExtensionPaymentNOCHEX extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/nochex'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_nochex', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['email'])) { + $data['error_email'] = $this->error['email']; + } else { + $data['error_email'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/nochex', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/nochex', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_nochex_email'])) { + $data['payment_nochex_email'] = $this->request->post['payment_nochex_email']; + } else { + $data['payment_nochex_email'] = $this->config->get('payment_nochex_email'); + } + + if (isset($this->request->post['payment_nochex_account'])) { + $data['payment_nochex_account'] = $this->request->post['payment_nochex_account']; + } else { + $data['payment_nochex_account'] = $this->config->get('payment_nochex_account'); + } + + if (isset($this->request->post['payment_nochex_merchant'])) { + $data['payment_nochex_merchant'] = $this->request->post['payment_nochex_merchant']; + } else { + $data['payment_nochex_merchant'] = $this->config->get('payment_nochex_merchant'); + } + + if (isset($this->request->post['payment_nochex_template'])) { + $data['payment_nochex_template'] = $this->request->post['payment_nochex_template']; + } else { + $data['payment_nochex_template'] = $this->config->get('payment_nochex_template'); + } + + if (isset($this->request->post['payment_nochex_test'])) { + $data['payment_nochex_test'] = $this->request->post['payment_nochex_test']; + } else { + $data['payment_nochex_test'] = $this->config->get('payment_nochex_test'); + } + + if (isset($this->request->post['payment_nochex_total'])) { + $data['payment_nochex_total'] = $this->request->post['payment_nochex_total']; + } else { + $data['payment_nochex_total'] = $this->config->get('payment_nochex_total'); + } + + if (isset($this->request->post['payment_nochex_order_status_id'])) { + $data['payment_nochex_order_status_id'] = $this->request->post['payment_nochex_order_status_id']; + } else { + $data['payment_nochex_order_status_id'] = $this->config->get('payment_nochex_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_nochex_geo_zone_id'])) { + $data['payment_nochex_geo_zone_id'] = $this->request->post['payment_nochex_geo_zone_id']; + } else { + $data['payment_nochex_geo_zone_id'] = $this->config->get('payment_nochex_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_nochex_status'])) { + $data['payment_nochex_status'] = $this->request->post['payment_nochex_status']; + } else { + $data['payment_nochex_status'] = $this->config->get('payment_nochex_status'); + } + + if (isset($this->request->post['payment_nochex_sort_order'])) { + $data['payment_nochex_sort_order'] = $this->request->post['payment_nochex_sort_order']; + } else { + $data['payment_nochex_sort_order'] = $this->config->get('payment_nochex_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/nochex', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/nochex')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_nochex_email']) { + $this->error['email'] = $this->language->get('error_email'); + } + + if (!$this->request->post['payment_nochex_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/paymate.php b/public/admin/controller/extension/payment/paymate.php new file mode 100644 index 0000000..4552e76 --- /dev/null +++ b/public/admin/controller/extension/payment/paymate.php @@ -0,0 +1,139 @@ +<?php +class ControllerExtensionPaymentPayMate extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/paymate'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_paymate', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/paymate', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/paymate', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_paymate_username'])) { + $data['payment_paymate_username'] = $this->request->post['payment_paymate_username']; + } else { + $data['payment_paymate_username'] = $this->config->get('payment_paymate_username'); + } + + if (isset($this->request->post['payment_paymate_password'])) { + $data['payment_paymate_username'] = $this->request->post['payment_paymate_password']; + } elseif ($this->config->get('payment_paymate_password')) { + $data['payment_paymate_password'] = $this->config->get('payment_paymate_password'); + } else { + $data['payment_paymate_password'] = token(32); + } + + if (isset($this->request->post['payment_paymate_test'])) { + $data['payment_paymate_test'] = $this->request->post['payment_paymate_test']; + } else { + $data['payment_paymate_test'] = $this->config->get('payment_paymate_test'); + } + + if (isset($this->request->post['payment_paymate_total'])) { + $data['payment_paymate_total'] = $this->request->post['payment_paymate_total']; + } else { + $data['payment_paymate_total'] = $this->config->get('payment_paymate_total'); + } + + if (isset($this->request->post['payment_paymate_order_status_id'])) { + $data['payment_paymate_order_status_id'] = $this->request->post['payment_paymate_order_status_id']; + } else { + $data['payment_paymate_order_status_id'] = $this->config->get('payment_paymate_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_paymate_geo_zone_id'])) { + $data['payment_paymate_geo_zone_id'] = $this->request->post['payment_paymate_geo_zone_id']; + } else { + $data['payment_paymate_geo_zone_id'] = $this->config->get('payment_paymate_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_paymate_status'])) { + $data['payment_paymate_status'] = $this->request->post['payment_paymate_status']; + } else { + $data['payment_paymate_status'] = $this->config->get('payment_paymate_status'); + } + + if (isset($this->request->post['payment_paymate_sort_order'])) { + $data['payment_paymate_sort_order'] = $this->request->post['payment_paymate_sort_order']; + } else { + $data['payment_paymate_sort_order'] = $this->config->get('payment_paymate_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/paymate', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/paymate')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_paymate_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_paymate_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/paypoint.php b/public/admin/controller/extension/payment/paypoint.php new file mode 100644 index 0000000..c4948a2 --- /dev/null +++ b/public/admin/controller/extension/payment/paypoint.php @@ -0,0 +1,127 @@ +<?php +class ControllerExtensionPaymentPayPoint extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/paypoint'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_paypoint', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/paypoint', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/paypoint', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_paypoint_merchant'])) { + $data['payment_paypoint_merchant'] = $this->request->post['payment_paypoint_merchant']; + } else { + $data['payment_paypoint_merchant'] = $this->config->get('payment_paypoint_merchant'); + } + + if (isset($this->request->post['payment_paypoint_password'])) { + $data['payment_paypoint_password'] = $this->request->post['payment_paypoint_password']; + } else { + $data['payment_paypoint_password'] = $this->config->get('payment_paypoint_password'); + } + + if (isset($this->request->post['payment_paypoint_test'])) { + $data['payment_paypoint_test'] = $this->request->post['payment_paypoint_test']; + } else { + $data['payment_paypoint_test'] = $this->config->get('payment_paypoint_test'); + } + + if (isset($this->request->post['payment_paypoint_total'])) { + $data['payment_paypoint_total'] = $this->request->post['payment_paypoint_total']; + } else { + $data['payment_paypoint_total'] = $this->config->get('payment_paypoint_total'); + } + + if (isset($this->request->post['payment_paypoint_order_status_id'])) { + $data['payment_paypoint_order_status_id'] = $this->request->post['payment_paypoint_order_status_id']; + } else { + $data['payment_paypoint_order_status_id'] = $this->config->get('payment_paypoint_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['paypoint_geo_zone_id'])) { + $data['paypoint_geo_zone_id'] = $this->request->post['paypoint_geo_zone_id']; + } else { + $data['paypoint_geo_zone_id'] = $this->config->get('paypoint_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['paypoint_status'])) { + $data['paypoint_status'] = $this->request->post['paypoint_status']; + } else { + $data['paypoint_status'] = $this->config->get('paypoint_status'); + } + + if (isset($this->request->post['paypoint_sort_order'])) { + $data['paypoint_sort_order'] = $this->request->post['paypoint_sort_order']; + } else { + $data['paypoint_sort_order'] = $this->config->get('paypoint_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/paypoint', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/paypoint')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_paypoint_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/payza.php b/public/admin/controller/extension/payment/payza.php new file mode 100644 index 0000000..bb250dc --- /dev/null +++ b/public/admin/controller/extension/payment/payza.php @@ -0,0 +1,133 @@ +<?php +class ControllerExtensionPaymentPayza extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/payza'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_payza', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant'])) { + $data['error_merchant'] = $this->error['merchant']; + } else { + $data['error_merchant'] = ''; + } + + if (isset($this->error['security'])) { + $data['error_security'] = $this->error['security']; + } else { + $data['error_security'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/payza', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/payza', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_payza_merchant'])) { + $data['payment_payza_merchant'] = $this->request->post['payment_payza_merchant']; + } else { + $data['payment_payza_merchant'] = $this->config->get('payment_payza_merchant'); + } + + if (isset($this->request->post['payment_payza_security'])) { + $data['payment_payza_security'] = $this->request->post['payment_payza_security']; + } else { + $data['payment_payza_security'] = $this->config->get('payment_payza_security'); + } + + $data['callback'] = HTTP_CATALOG . 'index.php?route=extension/payment/payza/callback'; + + if (isset($this->request->post['payment_payza_total'])) { + $data['payment_payza_total'] = $this->request->post['payment_payza_total']; + } else { + $data['payment_payza_total'] = $this->config->get('payment_payza_total'); + } + + if (isset($this->request->post['payment_payza_order_status_id'])) { + $data['payment_payza_order_status_id'] = $this->request->post['payment_payza_order_status_id']; + } else { + $data['payment_payza_order_status_id'] = $this->config->get('payment_payza_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_payza_geo_zone_id'])) { + $data['payment_payza_geo_zone_id'] = $this->request->post['payment_payza_geo_zone_id']; + } else { + $data['payment_payza_geo_zone_id'] = $this->config->get('payment_payza_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_payza_status'])) { + $data['payment_payza_status'] = $this->request->post['payment_payza_status']; + } else { + $data['payment_payza_status'] = $this->config->get('payment_payza_status'); + } + + if (isset($this->request->post['payment_payza_sort_order'])) { + $data['payment_payza_sort_order'] = $this->request->post['payment_payza_sort_order']; + } else { + $data['payment_payza_sort_order'] = $this->config->get('payment_payza_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/payza', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/payza')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_payza_merchant']) { + $this->error['merchant'] = $this->language->get('error_merchant'); + } + + if (!$this->request->post['payment_payza_security']) { + $this->error['security'] = $this->language->get('error_security'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/perpetual_payments.php b/public/admin/controller/extension/payment/perpetual_payments.php new file mode 100644 index 0000000..f363b5f --- /dev/null +++ b/public/admin/controller/extension/payment/perpetual_payments.php @@ -0,0 +1,137 @@ +<?php +class ControllerExtensionPaymentPerpetualPayments extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/perpetual_payments'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_perpetual_payments', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['auth_id'])) { + $data['error_auth_id'] = $this->error['auth_id']; + } else { + $data['error_auth_id'] = ''; + } + + if (isset($this->error['auth_pass'])) { + $data['error_auth_pass'] = $this->error['auth_pass']; + } else { + $data['error_auth_pass'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/perpetual_payments', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/perpetual_payments', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_perpetual_payments_auth_id'])) { + $data['payment_perpetual_payments_auth_id'] = $this->request->post['payment_perpetual_payments_auth_id']; + } else { + $data['payment_perpetual_payments_auth_id'] = $this->config->get('payment_perpetual_payments_auth_id'); + } + + if (isset($this->request->post['payment_perpetual_payments_auth_pass'])) { + $data['payment_perpetual_payments_auth_pass'] = $this->request->post['payment_perpetual_payments_auth_pass']; + } else { + $data['payment_perpetual_payments_auth_pass'] = $this->config->get('payment_perpetual_payments_auth_pass'); + } + + if (isset($this->request->post['payment_perpetual_payments_test'])) { + $data['payment_perpetual_payments_test'] = $this->request->post['payment_perpetual_payments_test']; + } else { + $data['payment_perpetual_payments_test'] = $this->config->get('payment_perpetual_payments_test'); + } + + if (isset($this->request->post['payment_perpetual_payments_total'])) { + $data['payment_perpetual_payments_total'] = $this->request->post['payment_perpetual_payments_total']; + } else { + $data['payment_perpetual_payments_total'] = $this->config->get('payment_perpetual_payments_total'); + } + + if (isset($this->request->post['payment_perpetual_payments_order_status_id'])) { + $data['payment_perpetual_payments_order_status_id'] = $this->request->post['payment_perpetual_payments_order_status_id']; + } else { + $data['payment_perpetual_payments_order_status_id'] = $this->config->get('payment_perpetual_payments_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_perpetual_payments_geo_zone_id'])) { + $data['payment_perpetual_payments_geo_zone_id'] = $this->request->post['payment_perpetual_payments_geo_zone_id']; + } else { + $data['payment_perpetual_payments_geo_zone_id'] = $this->config->get('payment_perpetual_payments_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_perpetual_payments_status'])) { + $data['payment_perpetual_payments_status'] = $this->request->post['payment_perpetual_payments_status']; + } else { + $data['payment_perpetual_payments_status'] = $this->config->get('payment_perpetual_payments_status'); + } + + if (isset($this->request->post['payment_perpetual_payments_sort_order'])) { + $data['payment_perpetual_payments_sort_order'] = $this->request->post['payment_perpetual_payments_sort_order']; + } else { + $data['payment_perpetual_payments_sort_order'] = $this->config->get('payment_perpetual_payments_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/perpetual_payments', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/perpetual_payments')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_perpetual_payments_auth_id']) { + $this->error['auth_id'] = $this->language->get('error_auth_id'); + } + + if (!$this->request->post['payment_perpetual_payments_auth_pass']) { + $this->error['auth_pass'] = $this->language->get('error_auth_pass'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pilibaba.php b/public/admin/controller/extension/payment/pilibaba.php new file mode 100644 index 0000000..5f78593 --- /dev/null +++ b/public/admin/controller/extension/payment/pilibaba.php @@ -0,0 +1,343 @@ +<?php +class ControllerExtensionPaymentPilibaba extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + + $this->load->model('extension/payment/pilibaba'); + + $this->load->language('extension/payment/pilibaba'); + + $this->document->setTitle($this->language->get('heading_title')); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pilibaba', $this->request->post); + + if ($this->request->post['payment_pilibaba_status']) { + $this->model_extension_payment_pilibaba->enablePiliExpress(); + } else { + $this->model_extension_payment_pilibaba->disablePiliExpress(); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pilibaba', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pilibaba', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pilibaba_merchant_number'])) { + $data['payment_pilibaba_merchant_number'] = $this->request->post['payment_pilibaba_merchant_number']; + } else { + $data['payment_pilibaba_merchant_number'] = $this->config->get('payment_pilibaba_merchant_number'); + } + + if (isset($this->request->post['payment_pilibaba_secret_key'])) { + $data['payment_pilibaba_secret_key'] = $this->request->post['payment_pilibaba_secret_key']; + } else { + $data['payment_pilibaba_secret_key'] = $this->config->get('payment_pilibaba_secret_key'); + } + + if (isset($this->request->post['payment_pilibaba_environment'])) { + $data['payment_pilibaba_environment'] = $this->request->post['payment_pilibaba_environment']; + } else { + $data['payment_pilibaba_environment'] = $this->config->get('payment_pilibaba_environment'); + } + + if (isset($this->request->post['payment_pilibaba_shipping_fee'])) { + $data['payment_pilibaba_shipping_fee'] = $this->request->post['payment_pilibaba_shipping_fee']; + } else { + $data['payment_pilibaba_shipping_fee'] = $this->config->get('payment_pilibaba_shipping_fee'); + } + + if (isset($this->request->post['payment_pilibaba_order_status_id'])) { + $data['payment_pilibaba_order_status_id'] = $this->request->post['payment_pilibaba_order_status_id']; + } elseif ($this->config->has('payment_pilibaba_order_status_id')) { + $data['payment_pilibaba_order_status_id'] = $this->config->get('payment_pilibaba_order_status_id'); + } else { + $data['payment_pilibaba_order_status_id'] = '2'; + } + + if (isset($this->request->post['payment_pilibaba_status'])) { + $data['payment_pilibaba_status'] = $this->request->post['payment_pilibaba_status']; + } else { + $data['payment_pilibaba_status'] = $this->config->get('payment_pilibaba_status'); + } + + if (isset($this->request->post['payment_pilibaba_logging'])) { + $data['payment_pilibaba_logging'] = $this->request->post['payment_pilibaba_logging']; + } else { + $data['payment_pilibaba_logging'] = $this->config->get('payment_pilibaba_logging'); + } + + if (isset($this->request->post['payment_pilibaba_sort_order'])) { + $data['payment_pilibaba_sort_order'] = $this->request->post['payment_pilibaba_sort_order']; + } else { + $data['payment_pilibaba_sort_order'] = $this->config->get('payment_pilibaba_sort_order'); + } + + if (isset($this->request->post['payment_pilibaba_email_address'])) { + $data['payment_pilibaba_email_address'] = $this->request->post['payment_pilibaba_email_address']; + } elseif ($this->config->has('payment_pilibaba_email_address')) { + $data['payment_pilibaba_email_address'] = $this->config->get('payment_pilibaba_email_address'); + } else { + $data['payment_pilibaba_email_address'] = ''; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->session->data['success'])) { + $data['success'] = $this->session->data['success']; + + unset($this->session->data['success']); + } else { + $data['success'] = ''; + } + + if (isset($this->error['pilibaba_merchant_number'])) { + $data['error_pilibaba_merchant_number'] = $this->error['pilibaba_merchant_number']; + } else { + $data['error_pilibaba_merchant_number'] = ''; + } + + if (isset($this->error['pilibaba_secret_key'])) { + $data['error_pilibaba_secret_key'] = $this->error['pilibaba_secret_key']; + } else { + $data['error_pilibaba_secret_key'] = ''; + } + + if (isset($this->error['pilibaba_shipping_fee'])) { + $data['error_pilibaba_shipping_fee'] = $this->error['pilibaba_shipping_fee']; + } else { + $data['error_pilibaba_shipping_fee'] = ''; + } + + if ($data['pilibaba_merchant_number'] && $data['payment_pilibaba_secret_key']) { + $data['show_register'] = false; + + $data['currencies'] = $data['warehouses'] = $data['countries'] = array(); + } else { + $data['show_register'] = true; + + $data['currencies'] = $this->model_extension_payment_pilibaba->getCurrencies(); + + $data['warehouses'] = $this->model_extension_payment_pilibaba->getWarehouses(); + + $this->load->model('localisation/country'); + + $data['countries'] = $this->model_localisation_country->getCountries(); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if ($this->config->get('config_weight_class_id') != '2') { + $data['error_weight'] = sprintf($this->language->get('error_weight'), $this->url->link('setting/setting', 'user_token=' . $this->session->data['user_token'], true)); + } else { + $data['error_weight'] = ''; + } + + if ($this->config->has('payment_pilibaba_email_address') && $this->config->get('payment_pilibaba_email_address')) { + $data['notice_email'] = sprintf($this->language->get('text_email'), $this->config->get('payment_pilibaba_email_address')); + } else { + $data['notice_email'] = ''; + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pilibaba', $data)); + } + + public function install() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/pilibaba'); + + $this->model_extension_payment_pilibaba->install(); + } + } + + public function uninstall() { + if ($this->user->hasPermission('modify', 'marketplace/extension')) { + $this->load->model('extension/payment/pilibaba'); + + $this->model_extension_payment_pilibaba->uninstall(); + } + } + + public function register() { + $this->load->language('extension/payment/pilibaba'); + + $json = array(); + + if (isset($this->request->post['email_address']) && isset($this->request->post['password']) && isset($this->request->post['currency']) && isset($this->request->post['warehouse']) && isset($this->request->post['country']) && isset($this->request->post['environment'])) { + if (utf8_strlen($this->request->post['email_address']) < 1) { + $json['error'] = $this->language->get('error_email_address'); + } else if (!filter_var($this->request->post['email_address'], FILTER_VALIDATE_EMAIL)) { + $json['error'] = $this->language->get('error_email_invalid'); + } else if (utf8_strlen($this->request->post['password']) < 8) { + $json['error'] = $this->language->get('error_password'); + } else if (utf8_strlen($this->request->post['currency']) < 1) { + $json['error'] = $this->language->get('error_currency'); + } else if (utf8_strlen($this->request->post['warehouse']) < 1) { + $json['error'] = $this->language->get('error_warehouse'); + } else if ($this->request->post['warehouse'] == 'other' && utf8_strlen($this->request->post['country']) < 1) { + $json['error'] = $this->language->get('error_country'); + } else { + $this->load->model('extension/payment/pilibaba'); + + $response = $this->model_extension_payment_pilibaba->register($this->request->post['email_address'], $this->request->post['password'], $this->request->post['currency'], $this->request->post['warehouse'], $this->request->post['country'], $this->request->post['environment']); + + if (isset($response['code']) && isset($response['message'])) { + if ($response['code'] == '0') { + $this->load->model('setting/setting'); + + $this->model_setting_setting->editSetting('payment_pilibaba', array('pilibaba_merchant_number' => $response['data']['merchantNo'], 'pilibaba_secret_key' => $response['data']['privateKey'], 'pilibaba_email_address' => $this->request->post['email_address'], 'payment_pilibaba_environment' => $this->request->post['environment']), 0); + + $this->session->data['success'] = $this->language->get('text_register_success'); + + $json['redirect'] = $this->url->link('extension/payment/pilibaba', 'user_token=' . $this->session->data['user_token'], true); + } else { + $json['error'] = $response['message']; + } + } else { + $json['error'] = $this->language->get('error_bad_response'); + } + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function order() { + if ($this->config->get('payment_pilibaba_status')) { + $this->load->model('extension/payment/pilibaba'); + + $order_id = $this->request->get['order_id']; + + $pilibaba_order = $this->model_extension_payment_pilibaba->getOrder($this->request->get['order_id']); + + if ($pilibaba_order) { + $this->load->language('extension/payment/pilibaba'); + + $order_info['order_id'] = $pilibaba_order['order_id']; + + $order_info['amount'] = '¥' . $pilibaba_order['amount']; + + $order_info['fee'] = '¥' . $pilibaba_order['fee']; + + $order_info['status'] = 'Success'; + + $order_info['date_added'] = date($this->language->get('datetime_format'), strtotime($pilibaba_order['date_added'])); + + $order_info['tracking'] = $pilibaba_order['tracking']; + + $data['pilibaba_order'] = $order_info; + + $data['barcode'] = $this->url->link('extension/payment/pilibaba/barcode', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true); + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/pilibaba_order', $data); + } + } + } + + public function tracking() { + $this->load->language('extension/payment/pilibaba'); + + $json = array(); + + if ($this->config->get('payment_pilibaba_status')) { + if (isset($this->request->post['order_id']) && isset($this->request->post['tracking'])) { + if (utf8_strlen($this->request->post['tracking']) > 0 && utf8_strlen($this->request->post['tracking']) <= 50) { + $this->load->model('extension/payment/pilibaba'); + + $this->model_extension_payment_pilibaba->updateTrackingNumber($this->request->post['order_id'], $this->request->post['tracking'], $this->config->get('payment_pilibaba_merchant_number')); + + $json['success'] = $this->language->get('text_tracking_success'); + } else { + $json['error'] = $this->language->get('error_tracking_length'); + } + } else { + $json['error'] = $this->language->get('error_data_missing'); + } + } else { + $json['error'] = $this->language->get('error_not_enabled'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function barcode() { + if ($this->config->get('payment_pilibaba_status')) { + if (isset($this->request->get['order_id'])) { + if ($this->config->get('payment_pilibaba_environment') == 'live') { + $url = 'https://www.pilibaba.com/pilipay/barCode'; + } else { + $url = 'http://pre.pilibaba.com/pilipay/barCode'; + } + + echo '<img src="' . $url . '?orderNo=' . $this->request->get['order_id'] . '&merchantNo=' . $this->config->get('payment_pilibaba_merchant_number') . '">'; + } + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pilibaba')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pilibaba_merchant_number']) { + $this->error['pilibaba_merchant_number'] = $this->language->get('error_merchant_number'); + } + + if (!$this->request->post['payment_pilibaba_secret_key']) { + $this->error['pilibaba_secret_key'] = $this->language->get('error_secret_key'); + } + + if ($this->request->post['payment_pilibaba_shipping_fee'] != '' && strpos($this->request->post['payment_pilibaba_shipping_fee'], '.') === false) { + $this->error['pilibaba_shipping_fee'] = $this->language->get('error_shipping_fee'); + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pp_braintree.php b/public/admin/controller/extension/payment/pp_braintree.php new file mode 100644 index 0000000..0bf83e8 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_braintree.php @@ -0,0 +1,1132 @@ +<?php +class ControllerExtensionPaymentPPBraintree extends Controller { + private $error = array(); + private $gateway = null; + private $opencart_connect_url = 'https://www.opencart.com/index.php?route=external/braintree_auth/connect'; + private $opencart_retrieve_url = 'https://www.opencart.com/index.php?route=external/braintree_auth/retrieve'; + + public function index() { + $this->load->language('extension/payment/pp_braintree'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + foreach ($this->request->post['payment_pp_braintree_account'] as $currency => $account) { + if (!isset($account['status'])) { + $this->request->post['payment_pp_braintree_account'][$currency]['status'] = 0; + } + } + + $this->model_setting_setting->editSetting('payment_pp_braintree', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['button_configure'] = $this->url->link('extension/module/pp_braintree_button/configure', 'user_token=' . $this->session->data['user_token'], true); + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/currency'); + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['account'])) { + $data['error_account'] = $this->error['account']; + } else { + $data['error_account'] = array(); + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_braintree_merchant_id'])) { + $data['payment_pp_braintree_merchant_id'] = $this->request->post['payment_pp_braintree_merchant_id']; + } else { + $data['payment_pp_braintree_merchant_id'] = $this->config->get('payment_pp_braintree_merchant_id'); + } + + if (isset($this->request->post['payment_pp_braintree_public_key'])) { + $data['payment_pp_braintree_public_key'] = $this->request->post['payment_pp_braintree_public_key']; + } else { + $data['payment_pp_braintree_public_key'] = $this->config->get('payment_pp_braintree_public_key'); + } + + if (isset($this->request->post['payment_pp_braintree_private_key'])) { + $data['payment_pp_braintree_private_key'] = $this->request->post['payment_pp_braintree_private_key']; + } else { + $data['payment_pp_braintree_private_key'] = $this->config->get('payment_pp_braintree_private_key'); + } + + if (isset($this->request->post['payment_pp_braintree_access_token'])) { + $data['payment_pp_braintree_access_token'] = $this->request->post['payment_pp_braintree_access_token']; + } else { + $data['payment_pp_braintree_access_token'] = $this->config->get('payment_pp_braintree_access_token'); + } + + if (isset($this->request->post['payment_pp_braintree_refresh_token'])) { + $data['payment_pp_braintree_refresh_token'] = $this->request->post['payment_pp_braintree_refresh_token']; + } else { + $data['payment_pp_braintree_refresh_token'] = $this->config->get('payment_pp_braintree_refresh_token'); + } + + if (isset($this->request->post['payment_pp_braintree_environment'])) { + $data['payment_pp_braintree_environment'] = $this->request->post['payment_pp_braintree_environment']; + } else { + $data['payment_pp_braintree_environment'] = $this->config->get('payment_pp_braintree_environment'); + } + + if (isset($this->request->post['payment_pp_braintree_settlement_immediate'])) { + $data['payment_pp_braintree_settlement_immediate'] = $this->request->post['payment_pp_braintree_settlement_immediate']; + } else { + $data['payment_pp_braintree_settlement_immediate'] = $this->config->get('payment_pp_braintree_settlement_immediate'); + } + + if (isset($this->request->post['payment_pp_braintree_card_vault'])) { + $data['payment_pp_braintree_card_vault'] = $this->request->post['payment_pp_braintree_card_vault']; + } else { + $data['payment_pp_braintree_card_vault'] = $this->config->get('payment_pp_braintree_card_vault'); + } + + if (isset($this->request->post['payment_pp_braintree_card_check_vault'])) { + $data['payment_pp_braintree_card_check_vault'] = $this->request->post['payment_pp_braintree_card_check_vault']; + } else { + $data['payment_pp_braintree_card_check_vault'] = $this->config->get('payment_pp_braintree_card_check_vault'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_vault'])) { + $data['payment_pp_braintree_paypal_vault'] = $this->request->post['payment_pp_braintree_paypal_vault']; + } else { + $data['payment_pp_braintree_paypal_vault'] = $this->config->get('payment_pp_braintree_paypal_vault'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_check_vault'])) { + $data['payment_pp_braintree_paypal_check_vault'] = $this->request->post['payment_pp_braintree_paypal_check_vault']; + } else { + $data['payment_pp_braintree_paypal_check_vault'] = $this->config->get('payment_pp_braintree_paypal_check_vault'); + } + + if (isset($this->request->post['payment_pp_braintree_vault_cvv_3ds'])) { + $data['payment_pp_braintree_vault_cvv_3ds'] = $this->request->post['payment_pp_braintree_vault_cvv_3ds']; + } else { + $data['payment_pp_braintree_vault_cvv_3ds'] = $this->config->get('payment_pp_braintree_vault_cvv_3ds'); + } + + if (isset($this->request->post['payment_pp_braintree_debug'])) { + $data['payment_pp_braintree_debug'] = $this->request->post['payment_pp_braintree_debug']; + } else { + $data['payment_pp_braintree_debug'] = $this->config->get('payment_pp_braintree_debug'); + } + + if (isset($this->request->post['payment_pp_braintree_total'])) { + $data['payment_pp_braintree_total'] = $this->request->post['payment_pp_braintree_total']; + } else { + $data['payment_pp_braintree_total'] = $this->config->get('payment_pp_braintree_total'); + } + + if (isset($this->request->post['payment_pp_braintree_geo_zone_id'])) { + $data['payment_pp_braintree_geo_zone_id'] = $this->request->post['payment_pp_braintree_geo_zone_id']; + } else { + $data['payment_pp_braintree_geo_zone_id'] = $this->config->get('payment_pp_braintree_geo_zone_id'); + } + + if (isset($this->request->post['payment_pp_braintree_status'])) { + $data['payment_pp_braintree_status'] = $this->request->post['payment_pp_braintree_status']; + } else { + $data['payment_pp_braintree_status'] = $this->config->get('payment_pp_braintree_status'); + } + + if (isset($this->request->post['payment_pp_braintree_sort_order'])) { + $data['payment_pp_braintree_sort_order'] = $this->request->post['payment_pp_braintree_sort_order']; + } else { + $data['payment_pp_braintree_sort_order'] = $this->config->get('payment_pp_braintree_sort_order'); + } + + if (isset($this->request->post['payment_pp_braintree_account'])) { + $data['payment_pp_braintree_account'] = $this->request->post['payment_pp_braintree_account']; + } else { + $data['payment_pp_braintree_account'] = $this->config->get('payment_pp_braintree_account'); + } + + if (isset($this->request->post['payment_pp_braintree_authorization_expired_id'])) { + $data['payment_pp_braintree_authorization_expired_id'] = $this->request->post['payment_pp_braintree_authorization_expired_id']; + } else { + $data['payment_pp_braintree_authorization_expired_id'] = $this->config->get('payment_pp_braintree_authorization_expired_id'); + } + + if (isset($this->request->post['payment_pp_braintree_authorized_id'])) { + $data['payment_pp_braintree_authorized_id'] = $this->request->post['payment_pp_braintree_authorized_id']; + } else { + $data['payment_pp_braintree_authorized_id'] = $this->config->get('payment_pp_braintree_authorized_id'); + } + + if (isset($this->request->post['payment_pp_braintree_authorizing_id'])) { + $data['payment_pp_braintree_authorizing_id'] = $this->request->post['payment_pp_braintree_authorizing_id']; + } else { + $data['payment_pp_braintree_authorizing_id'] = $this->config->get('payment_pp_braintree_authorizing_id'); + } + + if (isset($this->request->post['payment_pp_braintree_settlement_pending_id'])) { + $data['payment_pp_braintree_settlement_pending_id'] = $this->request->post['payment_pp_braintree_settlement_pending_id']; + } else { + $data['payment_pp_braintree_settlement_pending_id'] = $this->config->get('payment_pp_braintree_settlement_pending_id'); + } + + if (isset($this->request->post['payment_pp_braintree_failed_id'])) { + $data['payment_pp_braintree_failed_id'] = $this->request->post['payment_pp_braintree_failed_id']; + } else { + $data['payment_pp_braintree_failed_id'] = $this->config->get('payment_pp_braintree_failed_id'); + } + + if (isset($this->request->post['payment_pp_braintree_gateway_rejected_id'])) { + $data['payment_pp_braintree_gateway_rejected_id'] = $this->request->post['payment_pp_braintree_gateway_rejected_id']; + } else { + $data['payment_pp_braintree_gateway_rejected_id'] = $this->config->get('payment_pp_braintree_gateway_rejected_id'); + } + + if (isset($this->request->post['payment_pp_braintree_processor_declined_id'])) { + $data['payment_pp_braintree_processor_declined_id'] = $this->request->post['payment_pp_braintree_processor_declined_id']; + } else { + $data['payment_pp_braintree_processor_declined_id'] = $this->config->get('payment_pp_braintree_processor_declined_id'); + } + + if (isset($this->request->post['payment_pp_braintree_settled_id'])) { + $data['payment_pp_braintree_settled_id'] = $this->request->post['payment_pp_braintree_settled_id']; + } else { + $data['payment_pp_braintree_settled_id'] = $this->config->get('payment_pp_braintree_settled_id'); + } + + if (isset($this->request->post['payment_pp_braintree_settling_id'])) { + $data['payment_pp_braintree_settling_id'] = $this->request->post['payment_pp_braintree_settling_id']; + } else { + $data['payment_pp_braintree_settling_id'] = $this->config->get('payment_pp_braintree_settling_id'); + } + + if (isset($this->request->post['payment_pp_braintree_submitted_for_settlement_id'])) { + $data['payment_pp_braintree_submitted_for_settlement_id'] = $this->request->post['payment_pp_braintree_submitted_for_settlement_id']; + } else { + $data['payment_pp_braintree_submitted_for_settlement_id'] = $this->config->get('payment_pp_braintree_submitted_for_settlement_id'); + } + + if (isset($this->request->post['payment_pp_braintree_voided_id'])) { + $data['payment_pp_braintree_voided_id'] = $this->request->post['payment_pp_braintree_voided_id']; + } else { + $data['payment_pp_braintree_voided_id'] = $this->config->get('payment_pp_braintree_voided_id'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_status'])) { + $data['payment_pp_braintree_3ds_status'] = $this->request->post['payment_pp_braintree_3ds_status']; + } else { + $data['payment_pp_braintree_3ds_status'] = $this->config->get('payment_pp_braintree_3ds_status'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_unsupported_card'])) { + $data['payment_pp_braintree_3ds_unsupported_card'] = $this->request->post['payment_pp_braintree_3ds_unsupported_card']; + } else { + $data['payment_pp_braintree_3ds_unsupported_card'] = $this->config->get('payment_pp_braintree_3ds_unsupported_card'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_lookup_error'])) { + $data['payment_pp_braintree_3ds_lookup_error'] = $this->request->post['payment_pp_braintree_3ds_lookup_error']; + } else { + $data['payment_pp_braintree_3ds_lookup_error'] = $this->config->get('payment_pp_braintree_3ds_lookup_error'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_lookup_enrolled'])) { + $data['payment_pp_braintree_3ds_lookup_enrolled'] = $this->request->post['payment_pp_braintree_3ds_lookup_enrolled']; + } else { + $data['payment_pp_braintree_3ds_lookup_enrolled'] = $this->config->get('payment_pp_braintree_3ds_lookup_enrolled'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_lookup_not_enrolled'])) { + $data['payment_pp_braintree_3ds_lookup_not_enrolled'] = $this->request->post['payment_pp_braintree_3ds_lookup_not_enrolled']; + } else { + $data['payment_pp_braintree_3ds_lookup_not_enrolled'] = $this->config->get('payment_pp_braintree_3ds_lookup_not_enrolled'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_not_participating'])) { + $data['payment_pp_braintree_3ds_not_participating'] = $this->request->post['payment_pp_braintree_3ds_not_participating']; + } else { + $data['payment_pp_braintree_3ds_not_participating'] = $this->config->get('payment_pp_braintree_3ds_not_participating'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_unavailable'])) { + $data['payment_pp_braintree_3ds_unavailable'] = $this->request->post['payment_pp_braintree_3ds_unavailable']; + } else { + $data['payment_pp_braintree_3ds_unavailable'] = $this->config->get('payment_pp_braintree_3ds_unavailable'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_signature_failed'])) { + $data['payment_pp_braintree_3ds_signature_failed'] = $this->request->post['payment_pp_braintree_3ds_signature_failed']; + } else { + $data['payment_pp_braintree_3ds_signature_failed'] = $this->config->get('payment_pp_braintree_3ds_signature_failed'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_successful'])) { + $data['payment_pp_braintree_3ds_successful'] = $this->request->post['payment_pp_braintree_3ds_successful']; + } else { + $data['payment_pp_braintree_3ds_successful'] = $this->config->get('payment_pp_braintree_3ds_successful'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_attempt_successful'])) { + $data['payment_pp_braintree_3ds_attempt_successful'] = $this->request->post['payment_pp_braintree_3ds_attempt_successful']; + } else { + $data['payment_pp_braintree_3ds_attempt_successful'] = $this->config->get('payment_pp_braintree_3ds_attempt_successful'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_failed'])) { + $data['payment_pp_braintree_3ds_failed'] = $this->request->post['payment_pp_braintree_3ds_failed']; + } else { + $data['payment_pp_braintree_3ds_failed'] = $this->config->get('payment_pp_braintree_3ds_failed'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_unable_to_auth'])) { + $data['payment_pp_braintree_3ds_unable_to_auth'] = $this->request->post['payment_pp_braintree_3ds_unable_to_auth']; + } else { + $data['payment_pp_braintree_3ds_unable_to_auth'] = $this->config->get('payment_pp_braintree_3ds_unable_to_auth'); + } + + if (isset($this->request->post['payment_pp_braintree_3ds_error'])) { + $data['payment_pp_braintree_3ds_error'] = $this->request->post['payment_pp_braintree_3ds_error']; + } else { + $data['payment_pp_braintree_3ds_error'] = $this->config->get('payment_pp_braintree_3ds_error'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_option'])) { + $data['payment_pp_braintree_paypal_option'] = $this->request->post['payment_pp_braintree_paypal_option']; + } else { + $data['payment_pp_braintree_paypal_option'] = $this->config->get('payment_pp_braintree_paypal_option'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_button_colour'])) { + $data['payment_pp_braintree_paypal_button_colour'] = $this->request->post['payment_pp_braintree_paypal_button_colour']; + } else { + $data['payment_pp_braintree_paypal_button_colour'] = $this->config->get('payment_pp_braintree_paypal_button_colour'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_button_size'])) { + $data['payment_pp_braintree_paypal_button_size'] = $this->request->post['payment_pp_braintree_paypal_button_size']; + } else { + $data['payment_pp_braintree_paypal_button_size'] = $this->config->get('payment_pp_braintree_paypal_button_size'); + } + + if (isset($this->request->post['payment_pp_braintree_paypal_button_shape'])) { + $data['payment_pp_braintree_paypal_button_shape'] = $this->request->post['payment_pp_braintree_paypal_button_shape']; + } else { + $data['payment_pp_braintree_paypal_button_shape'] = $this->config->get('payment_pp_braintree_paypal_button_shape'); + } + + if (isset($this->request->post['payment_pp_braintree_billing_agreement'])) { + $data['payment_pp_braintree_billing_agreement'] = $this->request->post['payment_pp_braintree_billing_agreement']; + } else { + $data['payment_pp_braintree_billing_agreement'] = $this->config->get('payment_pp_braintree_billing_agreement'); + } + + $data['transaction_statuses'] = array( + 'authorization_expired', + 'authorized', + 'authorizing', + 'settlement_pending', + 'failed', + 'gateway_rejected', + 'processor_declined', + 'settled', + 'settling', + 'submitted_for_settlement', + 'voided' + ); + + $data['card_types'] = array( + 'Visa', + 'MasterCard', + 'American Express', + 'Discover', + 'JCB', + 'Maestro' + ); + + if (isset($this->request->get['retrieve_code'])) { + $data['retrieve_code'] = $this->request->get['retrieve_code']; + + $curl = curl_init($this->opencart_retrieve_url); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true), + 'retrieve_code' => $this->request->get['retrieve_code'], + 'store_version' => VERSION, + ); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + + $curl_response = curl_exec($curl); + $config_response = json_decode($curl_response, true); + curl_close($curl); + + if (isset($config_response['merchant_id']) && isset($config_response['access_token']) && isset($config_response['refresh_token'])) { + $braintree_settings = $this->model_setting_setting->getSetting('payment_pp_braintree'); + $braintree_settings['payment_pp_braintree_merchant_id'] = $config_response['merchant_id']; + $braintree_settings['payment_pp_braintree_access_token'] = $config_response['access_token']; + $braintree_settings['payment_pp_braintree_refresh_token'] = $config_response['refresh_token']; + $braintree_settings['payment_pp_braintree_environment'] = $config_response['environment']; + $braintree_settings['payment_pp_braintree_public_key'] = ''; + $braintree_settings['payment_pp_braintree_private_key'] = ''; + + $this->model_setting_setting->editSetting('payment_pp_braintree', $braintree_settings); + + $data['payment_pp_braintree_merchant_id'] = $config_response['merchant_id']; + $data['payment_pp_braintree_access_token'] = $config_response['access_token']; + $data['payment_pp_braintree_refresh_token'] = $config_response['refresh_token']; + $data['payment_pp_braintree_environment'] = $config_response['environment']; + $data['payment_pp_braintree_public_key'] = ''; + $data['payment_pp_braintree_private_key'] = ''; + + $data['success'] = $this->language->get('text_success_connect'); + } + } + + $data['auth_connect_url'] = ''; + + // If Braintree is not setup yet, request auth token for merchant on-boarding flow + if ($data['payment_pp_braintree_merchant_id'] == '') { + $curl = curl_init($this->opencart_connect_url); + + $this->load->model('localisation/country'); + $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true), + 'store_url' => HTTPS_CATALOG, + 'store_version' => VERSION, + 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''), + ); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + + $curl_response = curl_exec($curl); + + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + if ($curl_response['url']) { + $data['auth_connect_url'] = $curl_response['url']; + } + } + + $data['braintree_config'] = array(); + $data['braintree_config']['three_d_secure_enabled'] = 0; + $data['braintree_config']['paypal_enabled'] = 0; + + $data['error_braintree_account_3ds'] = $this->language->get('error_braintree_account_3ds'); + $data['error_braintree_account_paypal'] = $this->language->get('error_braintree_account_paypal'); + + // load the account info from braintree if the config has been added yet. + if (!empty($data['payment_pp_braintree_access_token']) || (!empty($data['payment_pp_braintree_environment']) && !empty($data['payment_pp_braintree_merchant_id']) && !empty($data['payment_pp_braintree_public_key']) && !empty($data['payment_pp_braintree_private_key']))) { + $this->initialise($data['payment_pp_braintree_access_token'], array( + 'payment_pp_braintree_environment' => $data['payment_pp_braintree_environment'], + 'payment_pp_braintree_merchant_id' => $data['payment_pp_braintree_merchant_id'], + 'payment_pp_braintree_public_key' => $data['payment_pp_braintree_public_key'], + 'payment_pp_braintree_private_key' => $data['payment_pp_braintree_private_key'], + )); + + $verify_credentials = $this->model_extension_payment_pp_braintree->verifyCredentials($this->gateway); + + if (!$verify_credentials) { + $this->error['warning'] = $this->language->get('error_connection'); + } else { + $merchant_config = json_decode(base64_decode($verify_credentials), true); + + if (isset($merchant_config['threeDSecureEnabled']) && $merchant_config['threeDSecureEnabled'] == 1) { + $data['braintree_config']['three_d_secure_enabled'] = 1; + } + + if (isset($merchant_config['paypalEnabled']) && $merchant_config['paypalEnabled'] == 1) { + $data['braintree_config']['paypal_enabled'] = 1; + } + } + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_braintree', $data)); + } + + public function install() { + $this->load->model('setting/setting'); + + $defaults = array(); + + // 3D secure defaults + $defaults['payment_pp_braintree_3ds_unsupported_card'] = 1; + $defaults['payment_pp_braintree_3ds_lookup_error'] = 1; + $defaults['payment_pp_braintree_3ds_lookup_enrolled'] = 1; + $defaults['payment_pp_braintree_3ds_lookup_not_enrolled'] = 1; + $defaults['payment_pp_braintree_3ds_not_participating'] = 1; + $defaults['payment_pp_braintree_3ds_unavailable'] = 1; + $defaults['payment_pp_braintree_3ds_signature_failed'] = 0; + $defaults['payment_pp_braintree_3ds_successful'] = 1; + $defaults['payment_pp_braintree_3ds_attempt_successful'] = 1; + $defaults['payment_pp_braintree_3ds_failed'] = 0; + $defaults['payment_pp_braintree_3ds_unable_to_auth'] = 1; + $defaults['payment_pp_braintree_3ds_error'] = 1; + + // Order Status defaults + $defaults['payment_pp_braintree_authorization_expired_id'] = 14; + $defaults['payment_pp_braintree_authorized_id'] = 2; + $defaults['payment_pp_braintree_authorizing_id'] = 1; + $defaults['payment_pp_braintree_failed_id'] = 10; + $defaults['payment_pp_braintree_gateway_rejected_id'] = 8; + $defaults['payment_pp_braintree_processor_declined_id'] = 8; + $defaults['payment_pp_braintree_settled_id'] = 2; + $defaults['payment_pp_braintree_settling_id'] = 2; + $defaults['payment_pp_braintree_settlement_pending_id'] = 2; + $defaults['payment_pp_braintree_submitted_for_settlement_id'] = 2; + $defaults['payment_pp_braintree_voided_id'] = 16; + + $defaults['payment_pp_braintree_settlement_immediate'] = 1; + + // PayPal options + $defaults['payment_pp_braintree_paypal_option'] = 1; + $defaults['payment_pp_braintree_paypal_button_size'] = 'small'; + $defaults['payment_pp_braintree_paypal_button_shape'] = 'rect'; + + // Vault options + $defaults['payment_pp_braintree_card_vault'] = 1; + $defaults['payment_pp_braintree_paypal_vault'] = 0; + $defaults['payment_pp_braintree_card_check_vault'] = 1; + $defaults['payment_pp_braintree_paypal_check_vault'] = 0; + + $this->model_setting_setting->editSetting('payment_pp_braintree', $defaults); + } + + public function order() { + $this->load->language('extension/payment/pp_braintree'); + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + return $this->load->view('extension/payment/pp_braintree_order', $data); + } + + public function getTransaction() { + $this->load->language('extension/payment/pp_braintree'); + + $this->load->model('extension/payment/pp_braintree'); + $this->load->model('sale/order'); + + if (!$this->config->get('payment_pp_braintree_status') || (!isset($this->request->get['order_id']) && !isset($this->request->get['transaction_id']))) { + return; + } + + $this->initialise($this->config->get('payment_pp_braintree_access_token'), array( + 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'), + 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'), + 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'), + 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key') + )); + + if (isset($this->request->get['order_id'])) { + $search = array( + Braintree_TransactionSearch::orderId()->is($this->request->get['order_id']) + ); + } elseif (isset($this->request->get['transaction_id'])) { + $search = array( + Braintree_TransactionSearch::id()->is($this->request->get['transaction_id']) + ); + } + + $search_transactions = $this->model_extension_payment_pp_braintree->getTransactions($this->gateway, $search); + + $transaction = array(); + + foreach ($search_transactions as $search_transaction) { + $transaction = $search_transaction; + } + + $data['transaction'] = array(); + + if ($transaction) { + $data['transaction_id'] = $transaction->id; + + $data['user_token'] = $this->session->data['user_token']; + + $data['void_action'] = $data['settle_action'] = $data['refund_action'] = false; + + switch ($transaction->status) { + case 'authorized': + $data['void_action'] = true; + $data['settle_action'] = true; + break; + case 'submitted_for_settlement': + $data['void_action'] = true; + break; + case 'settling': + $data['refund_action'] = true; + break; + case 'settled': + $data['refund_action'] = true; + break; + } + + $statuses = array(); + + foreach ($transaction->statusHistory as $status_history) { + $created_at = $status_history->timestamp; + + $statuses[] = array( + 'status' => $status_history->status, + 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))) + ); + } + + $data['statuses'] = $statuses; + + $max_settle_amount = $transaction->amount; + + $max_refund_amount = $transaction->amount; + + $data['refunds'] = array(); + + foreach (array_reverse($transaction->refundIds) as $refund_id) { + $refund = $this->model_extension_payment_pp_braintree->getTransaction($this->gateway, $refund_id); + + $successful_statuses = array( + 'authorized', + 'authorizing', + 'settlement_pending', + 'settlement_confirmed', + 'settled', + 'settling', + 'submitted_for_settlement' + ); + + if (in_array($refund->status, $successful_statuses)) { + $max_refund_amount -= $refund->amount; + } + + $created_at = $refund->createdAt; + + $data['refunds'][] = array( + 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))), + 'amount' => $this->currency->format($refund->amount, $refund->currencyIsoCode, '1.00000000', true), + 'status' => $refund->status + ); + } + + //If nothing left to refund, disable refund action + if (!$max_refund_amount) { + $data['refund_action'] = false; + } + + $data['max_settle_amount'] = $this->currency->format($max_settle_amount, $transaction->currencyIsoCode, '1.00000000', false); + + $data['max_refund_amount'] = $this->currency->format($max_refund_amount, $transaction->currencyIsoCode, '1.00000000', false); + + $amount = $this->currency->format($transaction->amount, $transaction->currencyIsoCode, '1.00000000', true); + + $data['symbol_left'] = $this->currency->getSymbolLeft($transaction->currencyIsoCode); + $data['symbol_right'] = $this->currency->getSymbolRight($transaction->currencyIsoCode); + + $created_at = $transaction->createdAt; + + if ($transaction->threeDSecureInfo) { + if ($transaction->threeDSecureInfo->liabilityShifted) { + $liability_shifted = $this->language->get('text_yes'); + } else { + $liability_shifted = $this->language->get('text_no'); + } + } + + if ($transaction->threeDSecureInfo) { + if ($transaction->threeDSecureInfo->liabilityShiftPossible) { + $liability_shift_possible = $this->language->get('text_yes'); + } else { + $liability_shift_possible = $this->language->get('text_no'); + } + } + + $data['transaction'] = array( + 'status' => $transaction->status, + 'transaction_id' => $transaction->id, + 'type' => $transaction->type, + 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))), + 'merchant_account_id' => $transaction->merchantAccountId, + 'payment_type' => $transaction->paymentInstrumentType, + 'currency' => $transaction->currencyIsoCode, + 'amount' => $amount, + 'order_id' => $transaction->orderId, + 'processor_code' => $transaction->processorAuthorizationCode, + 'cvv_response' => $transaction->cvvResponseCode, + 'avs_response' => sprintf($this->language->get('text_avs_response'), $transaction->avsStreetAddressResponseCode, $transaction->avsPostalCodeResponseCode), + 'threeds_enrolled' => ($transaction->threeDSecureInfo ? $transaction->threeDSecureInfo->enrolled : ''), + 'threeds_status' => ($transaction->threeDSecureInfo ? $transaction->threeDSecureInfo->status : ''), + 'threeds_shifted' => ($transaction->threeDSecureInfo ? $liability_shifted : ''), + 'threeds_shift_possible' => ($transaction->threeDSecureInfo ? $liability_shift_possible : '') + ); + + $data['text_confirm_void'] = $this->language->get('text_confirm_void'); + $data['text_confirm_settle'] = $this->language->get('text_confirm_settle'); + $data['text_confirm_refund'] = $this->language->get('text_confirm_refund'); + + $this->response->setOutput($this->load->view('extension/payment/pp_braintree_order_ajax', $data)); + } + } + + public function transactionCommand() { + $this->load->language('extension/payment/pp_braintree'); + + $this->load->model('extension/payment/pp_braintree'); + + $this->initialise($this->config->get('payment_pp_braintree_access_token'), array( + 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'), + 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'), + 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'), + 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key') + )); + + $json = array(); + + $success = $error = ''; + + if ($this->request->post['type'] == 'void') { + $action = $this->model_extension_payment_pp_braintree->voidTransaction($this->gateway, $this->request->post['transaction_id']); + } elseif ($this->request->post['type'] == 'settle' && $this->request->post['amount']) { + $action = $this->model_extension_payment_pp_braintree->settleTransaction($this->gateway, $this->request->post['transaction_id'], $this->request->post['amount']); + } elseif ($this->request->post['type'] == 'refund' && $this->request->post['amount']) { + $action = $this->model_extension_payment_pp_braintree->refundTransaction($this->gateway, $this->request->post['transaction_id'], $this->request->post['amount']); + } else { + $error = true; + } + + if (!$error && $action && $action->success) { + $success = $this->language->get('text_success_action'); + } elseif (!$error && $action && isset($action->message)) { + $error = sprintf($this->language->get('text_error_settle'), $action->message); + } else { + $error = $this->language->get('text_error_generic'); + } + + $json['success'] = $success; + $json['error'] = $error; + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function search() { + $this->load->language('extension/payment/pp_braintree'); + + $this->load->model('extension/payment/pp_braintree'); + $this->load->model('customer/customer'); + $this->load->model('sale/order'); + + $this->initialise($this->config->get('payment_pp_braintree_access_token'), array( + 'payment_pp_braintree_environment' => $this->config->get('payment_pp_braintree_environment'), + 'payment_pp_braintree_merchant_id' => $this->config->get('payment_pp_braintree_merchant_id'), + 'payment_pp_braintree_public_key' => $this->config->get('payment_pp_braintree_public_key'), + 'payment_pp_braintree_private_key' => $this->config->get('payment_pp_braintree_private_key') + )); + + $json = array(); + + $success = $error = ''; + + if (isset($this->request->get['filter_transaction_id'])) { + $filter_transaction_id = $this->request->get['filter_transaction_id']; + } else { + $filter_transaction_id = null; + } + + if (isset($this->request->get['filter_transaction_type'])) { + $filter_transaction_type = $this->request->get['filter_transaction_type']; + } else { + $filter_transaction_type = null; + } + + if (isset($this->request->get['filter_payment_type'])) { + $filter_payment_type = $this->request->get['filter_payment_type']; + } else { + $filter_payment_type = null; + } + + if (isset($this->request->get['filter_card_type'])) { + $filter_card_type = $this->request->get['filter_card_type']; + } else { + $filter_card_type = null; + } + + if (isset($this->request->get['filter_merchant_account_id'])) { + $filter_merchant_account_id = $this->request->get['filter_merchant_account_id']; + } else { + $filter_merchant_account_id = null; + } + + if (isset($this->request->get['filter_transaction_status'])) { + $filter_transaction_status = $this->request->get['filter_transaction_status']; + } else { + $filter_transaction_status = null; + } + + if (isset($this->request->get['filter_date_from'])) { + $filter_date_from = $this->request->get['filter_date_from']; + } else { + $filter_date_from = null; + } + + if (isset($this->request->get['filter_date_to'])) { + $filter_date_to = $this->request->get['filter_date_to']; + } else { + $filter_date_to = null; + } + + if (isset($this->request->get['filter_amount_from'])) { + $filter_amount_from = $this->request->get['filter_amount_from']; + } else { + $filter_amount_from = null; + } + + if (isset($this->request->get['filter_amount_to'])) { + $filter_amount_to = $this->request->get['filter_amount_to']; + } else { + $filter_amount_to = null; + } + + $json['transactions'] = array(); + + $search = array(); + + if ($filter_transaction_id) { + $search[] = Braintree_TransactionSearch::id()->is($filter_transaction_id); + } + + if ($filter_transaction_type) { + if ($filter_transaction_type == 'sale') { + $transaction_type = Braintree_Transaction::SALE; + } elseif ($filter_transaction_type == 'credit') { + $transaction_type = Braintree_Transaction::CREDIT; + } + + $search[] = Braintree_TransactionSearch::type()->is($transaction_type); + } + + if ($filter_payment_type) { + if ($filter_payment_type == 'Credit Card') { + $payment_type = 'CreditCardDetail'; + } elseif ($filter_payment_type == 'PayPal') { + $payment_type = 'PayPalDetail'; + } + + $search[] = Braintree_TransactionSearch::paymentInstrumentType()->is($payment_type); + } + + if ($filter_card_type) { + switch ($filter_card_type) { + case 'Visa': + $card_type = Braintree_CreditCard::VISA; + break; + case 'MasterCard': + $card_type = Braintree_CreditCard::MASTER_CARD; + break; + case 'American Express': + $card_type = Braintree_CreditCard::AMEX; + break; + case 'Discover': + $card_type = Braintree_CreditCard::DISCOVER; + break; + case 'JCB': + $card_type = Braintree_CreditCard::JCB; + break; + case 'Maestro': + $card_type = Braintree_CreditCard::MAESTRO; + break; + } + + $search[] = Braintree_TransactionSearch::creditCardCardType()->is($card_type); + } + + if ($filter_merchant_account_id) { + $search[] = Braintree_TransactionSearch::merchantAccountId()->is($filter_merchant_account_id); + } + + if ($filter_transaction_status) { + $search[] = Braintree_TransactionSearch::status()->in($filter_transaction_status); + } + + if ($filter_date_from || $filter_date_to) { + if ($filter_date_from) { + $date_from = new DateTime($filter_date_from); + } else { + $date_from = new DateTime('2012-01-01 00:00'); + } + + if ($filter_date_to) { + $date_to = new DateTime($filter_date_to . ' +1 day -1 minute'); + } else { + $date_to = new DateTime('tomorrow -1 minute'); + } + + $search[] = Braintree_TransactionSearch::createdAt()->between($date_from, $date_to); + } + + if ($filter_amount_from) { + $amount_from = $filter_amount_from; + } else { + $amount_from = 0; + } + + if ($filter_amount_to) { + $amount_to = $filter_amount_to; + } else { + $amount_to = 9999999; + } + + $search[] = Braintree_TransactionSearch::amount()->between((float)$amount_from, (float)$amount_to); + + $transactions = $this->model_extension_payment_pp_braintree->getTransactions($this->gateway, $search); + + if ($transactions) { + foreach ($transactions as $transaction) { + $customer_url = false; + + if ($transaction->customer['id']) { + $braintree_customer_id = explode('_', $transaction->customer['id']); + + if (isset($braintree_customer_id[2]) && is_numeric($braintree_customer_id[2])) { + $customer_info = $this->model_customer_customer->getCustomer($braintree_customer_id[2]); + + if ($customer_info && $customer_info['email'] == $transaction->customer['email']) { + $customer_url = $this->url->link('sale/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . (int)$braintree_customer_id[2], true); + } + } + } + + $order = false; + + if ($transaction->orderId) { + $order_info = $this->model_sale_order->getOrder($transaction->orderId); + + if ($order_info && $order_info['email'] == $transaction->customer['email']) { + $order = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . (int)$transaction->orderId, true); + } + } + + $created_at = $transaction->createdAt; + + $json['transactions'][] = array( + 'transaction_id' => $transaction->id, + 'amount' => $transaction->amount, + 'currency_iso' => $transaction->currencyIsoCode, + 'status' => $transaction->status, + 'type' => $transaction->type, + 'merchant_account_id' => $transaction->merchantAccountId, + 'customer' => $transaction->customer['firstName'] . ' ' . $transaction->customer['lastName'], + 'customer_url' => $customer_url, + 'order' => $order, + 'date_added' => date($this->language->get('datetime_format'), strtotime($created_at->format('Y-m-d H:i:s e'))) + ); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function connectRedirect() { + if ($this->user->hasPermission('modify', 'extension/extension/payment')) { + // Install the module before doing the redirect + $this->load->model('setting/extension'); + + $this->model_setting_extension->install('payment', 'pp_braintree'); + + $this->install(); + + $curl = curl_init($this->opencart_connect_url); + + $this->load->model('localisation/country'); + $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true), + 'store_url' => HTTPS_CATALOG, + 'store_version' => VERSION, + 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''), + ); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + + $curl_response = curl_exec($curl); + + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + if ($curl_response['url']) { + $this->response->redirect($curl_response['url']); + } else { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } + } else { + $this->response->redirect($this->url->link('error/permission', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function promotion() { + $this->load->language('extension/payment/pp_braintree'); + + $data['connect_link'] = ''; + $data['module_link'] = ''; + + if ($this->config->get('payment_pp_braintree_status') || $this->config->get('payment_pp_braintree_merchant_id') || $this->config->get('payment_pp_braintree_access_token')) { + $data['module_link'] = $this->url->link('extension/payment/pp_braintree', 'user_token=' . $this->session->data['user_token'], true); + } else { + if ($this->user->hasPermission('modify', 'extension/extension/payment')) { + $data['connect_link'] = $this->url->link('extension/payment/pp_braintree/connectRedirect', 'user_token=' . $this->session->data['user_token'], true); + } + } + + if ($this->config->get("payment_pp_braintree_status") == 1) { + $data['payment_pp_braintree_status'] = "enabled"; + } elseif ($this->config->get("payment_pp_braintree_status") == null) { + $data['payment_pp_braintree_status'] = ""; + } else { + $data['payment_pp_braintree_status'] = "disabled"; + } + + return $this->load->view('extension/payment/pp_braintree_promotion', $data); + } + + protected function validate() { + $this->load->model('extension/payment/pp_braintree'); + + $check_credentials = true; + + if (version_compare(phpversion(), '5.4.0', '<')) { + $this->error['warning'] = $this->language->get('error_php_version'); + } + + if (!$this->user->hasPermission('modify', 'extension/payment/pp_braintree')) { + $this->error['warning'] = $this->language->get('error_permission'); + + $check_credentials = false; + } + + if ($check_credentials && $this->request->post['payment_pp_braintree_status'] == 1) { + $this->initialise($this->request->post['payment_pp_braintree_access_token'], array( + 'payment_pp_braintree_environment' => $this->request->post['payment_pp_braintree_environment'], + 'payment_pp_braintree_merchant_id' => $this->request->post['payment_pp_braintree_merchant_id'], + 'payment_pp_braintree_public_key' => $this->request->post['payment_pp_braintree_public_key'], + 'payment_pp_braintree_private_key' => $this->request->post['payment_pp_braintree_private_key'], + )); + + $verify_credentials = $this->model_extension_payment_pp_braintree->verifyCredentials($this->gateway); + + if (!$verify_credentials) { + $this->error['warning'] = $this->language->get('error_connection'); + } else { + foreach ($this->request->post['payment_pp_braintree_account'] as $currency => $pp_braintree_account) { + if (!empty($pp_braintree_account['merchant_account_id'])) { + $verify_merchant_account_id = $this->model_extension_payment_pp_braintree->verifyMerchantAccount($this->gateway, $pp_braintree_account['merchant_account_id']); + + if (!$verify_merchant_account_id) { + $this->error['account'][$currency] = $this->language->get('error_account'); + } + } + } + + $merchant_config = json_decode(base64_decode($verify_credentials), true); + + // verify the Braintree account is ready to accept 3DS transactions + if (isset($merchant_config['threeDSecureEnabled']) && ($this->request->post['payment_pp_braintree_3ds_status'] == 1 && $merchant_config['threeDSecureEnabled'] != 1)) { + $this->error['warning'] = $this->language->get('error_3ds_not_ready'); + } + + // verify the Braintree account is ready to use PayPal Billing Agreements + if (isset($merchant_config['paypal']['billingAgreementEnabled']) && ($this->request->post['payment_pp_braintree_billing_agreement'] == 1 && $merchant_config['paypal']['billingAgreementEnabled'] != 1)) { + $this->error['warning'] = $this->language->get('error_paypal_billing_not_ready'); + } + + // verify the Braintree account is ready to accept PayPal transactions + if (isset($merchant_config['paypalEnabled']) && ($this->request->post['payment_pp_braintree_paypal_option'] == 1 && $merchant_config['paypalEnabled'] != 1)) { + $this->error['warning'] = $this->language->get('error_paypal_not_ready'); + } + + // verify the environment matches with the token the system is using + if (isset($merchant_config['environment']) && ($this->request->post['payment_pp_braintree_environment'] != $merchant_config['environment'])) { + $this->error['warning'] = sprintf($this->language->get('error_environment'), $this->request->post['payment_pp_braintree_environment'], $merchant_config['environment']); + } + } + } + + if ($this->error && !isset($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_warning'); + } + + return !$this->error; + } + + private function initialise($access_token = '', $credentials = array()) { + $this->load->model('extension/payment/pp_braintree'); + + if ($access_token != '') { + $this->gateway = $this->model_extension_payment_pp_braintree->setGateway($access_token); + } else { + Braintree_Configuration::environment(isset($credentials['payment_pp_braintree_environment']) ? $credentials['payment_pp_braintree_environment'] : ''); + Braintree_Configuration::merchantId(isset($credentials['payment_pp_braintree_merchant_id']) ? $credentials['payment_pp_braintree_merchant_id'] : ''); + Braintree_Configuration::publicKey(isset($credentials['payment_pp_braintree_public_key']) ? $credentials['payment_pp_braintree_public_key'] : ''); + Braintree_Configuration::privateKey(isset($credentials['payment_pp_braintree_private_key']) ? $credentials['payment_pp_braintree_private_key'] : ''); + } + } +} diff --git a/public/admin/controller/extension/payment/pp_express.php b/public/admin/controller/extension/payment/pp_express.php new file mode 100644 index 0000000..aed25c0 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_express.php @@ -0,0 +1,1347 @@ +<?php +class ControllerExtensionPaymentPPExpress extends Controller { + private $error = array(); + private $opencart_connect_url = 'https://www.opencart.com/index.php?route=external/paypal_auth/connect'; + private $opencart_retrieve_url = 'https://www.opencart.com/index.php?route=external/paypal_auth/retrieve'; + + public function index() { + $this->load->language('extension/payment/pp_express'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_express', $this->request->post); + + // If OC has been upgraded, verify that the module has the new event registered. + $this->load->model('setting/event'); + + $pp_express_js_event = $this->model_setting_event->getEventByCode("extension_pp_express_checkout_js"); + + if (empty($pp_express_js_event)) { + // Event is missing, add it + $this->model_setting_event->addEvent('extension_pp_express_checkout_js', 'catalog/controller/checkout/checkout/before', 'extension/payment/pp_express/eventLoadCheckoutJs'); + } + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['user_token'] = $this->session->data['user_token']; + + $data['button_configure'] = $this->url->link('extension/module/pp_button/configure', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['signature'])) { + $data['error_signature'] = $this->error['signature']; + } else { + $data['error_signature'] = ''; + } + + if (isset($this->error['sandbox_username'])) { + $data['error_sandbox_username'] = $this->error['sandbox_username']; + } else { + $data['error_sandbox_username'] = ''; + } + + if (isset($this->error['sandbox_password'])) { + $data['error_sandbox_password'] = $this->error['sandbox_password']; + } else { + $data['error_sandbox_password'] = ''; + } + + if (isset($this->error['sandbox_signature'])) { + $data['error_sandbox_signature'] = $this->error['sandbox_signature']; + } else { + $data['error_sandbox_signature'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['action'] = $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['search'] = $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->post['payment_pp_express_username'])) { + $data['payment_pp_express_username'] = $this->request->post['payment_pp_express_username']; + } else { + $data['payment_pp_express_username'] = $this->config->get('payment_pp_express_username'); + } + + if (isset($this->request->post['payment_pp_express_password'])) { + $data['payment_pp_express_password'] = $this->request->post['payment_pp_express_password']; + } else { + $data['payment_pp_express_password'] = $this->config->get('payment_pp_express_password'); + } + + if (isset($this->request->post['payment_pp_express_signature'])) { + $data['payment_pp_express_signature'] = $this->request->post['payment_pp_express_signature']; + } else { + $data['payment_pp_express_signature'] = $this->config->get('payment_pp_express_signature'); + } + + if (isset($this->request->post['payment_pp_express_sandbox_username'])) { + $data['payment_pp_express_sandbox_username'] = $this->request->post['payment_pp_express_sandbox_username']; + } else { + $data['payment_pp_express_sandbox_username'] = $this->config->get('payment_pp_express_sandbox_username'); + } + + if (isset($this->request->post['payment_pp_express_sandbox_password'])) { + $data['payment_pp_express_sandbox_password'] = $this->request->post['payment_pp_express_sandbox_password']; + } else { + $data['payment_pp_express_sandbox_password'] = $this->config->get('payment_pp_express_sandbox_password'); + } + + if (isset($this->request->post['payment_pp_express_sandbox_signature'])) { + $data['payment_pp_express_sandbox_signature'] = $this->request->post['payment_pp_express_sandbox_signature']; + } else { + $data['payment_pp_express_sandbox_signature'] = $this->config->get('payment_pp_express_sandbox_signature'); + } + + if (isset($this->request->post['payment_pp_express_test'])) { + $data['payment_pp_express_test'] = $this->request->post['payment_pp_express_test']; + } else { + $data['payment_pp_express_test'] = $this->config->get('payment_pp_express_test'); + } + + if (isset($this->request->post['payment_pp_express_debug'])) { + $data['payment_pp_express_debug'] = $this->request->post['payment_pp_express_debug']; + } else { + $data['payment_pp_express_debug'] = $this->config->get('payment_pp_express_debug'); + } + + if (isset($this->request->post['payment_pp_express_currency'])) { + $data['payment_pp_express_currency'] = $this->request->post['payment_pp_express_currency']; + } else { + $data['payment_pp_express_currency'] = $this->config->get('payment_pp_express_currency'); + } + + if (isset($this->request->post['payment_pp_express_recurring_cancel'])) { + $data['payment_pp_express_recurring_cancel'] = $this->request->post['payment_pp_express_recurring_cancel']; + } else { + $data['payment_pp_express_recurring_cancel'] = $this->config->get('payment_pp_express_recurring_cancel'); + } + + if (isset($this->request->post['payment_pp_express_transaction'])) { + $data['payment_pp_express_transaction'] = $this->request->post['payment_pp_express_transaction']; + } else { + $data['payment_pp_express_transaction'] = $this->config->get('payment_pp_express_transaction'); + } + + if (isset($this->request->post['payment_pp_express_total'])) { + $data['payment_pp_express_total'] = $this->request->post['payment_pp_express_total']; + } else { + $data['payment_pp_express_total'] = $this->config->get('payment_pp_express_total'); + } + + if (isset($this->request->post['payment_pp_express_geo_zone_id'])) { + $data['payment_pp_express_geo_zone_id'] = $this->request->post['payment_pp_express_geo_zone_id']; + } else { + $data['payment_pp_express_geo_zone_id'] = $this->config->get('payment_pp_express_geo_zone_id'); + } + + if (isset($this->request->post['payment_pp_express_status'])) { + $data['payment_pp_express_status'] = $this->request->post['payment_pp_express_status']; + } else { + $data['payment_pp_express_status'] = $this->config->get('payment_pp_express_status'); + } + + if (isset($this->request->post['payment_pp_express_sort_order'])) { + $data['payment_pp_express_sort_order'] = $this->request->post['payment_pp_express_sort_order']; + } else { + $data['payment_pp_express_sort_order'] = $this->config->get('payment_pp_express_sort_order'); + } + + if (isset($this->request->post['payment_pp_express_canceled_reversal_status_id'])) { + $data['payment_pp_express_canceled_reversal_status_id'] = $this->request->post['payment_pp_express_canceled_reversal_status_id']; + } else { + $data['payment_pp_express_canceled_reversal_status_id'] = $this->config->get('payment_pp_express_canceled_reversal_status_id'); + } + + if (isset($this->request->post['payment_pp_express_completed_status_id'])) { + $data['payment_pp_express_completed_status_id'] = $this->request->post['payment_pp_express_completed_status_id']; + } else { + $data['payment_pp_express_completed_status_id'] = $this->config->get('payment_pp_express_completed_status_id'); + } + + if (isset($this->request->post['payment_pp_express_denied_status_id'])) { + $data['payment_pp_express_denied_status_id'] = $this->request->post['payment_pp_express_denied_status_id']; + } else { + $data['payment_pp_express_denied_status_id'] = $this->config->get('payment_pp_express_denied_status_id'); + } + + if (isset($this->request->post['payment_pp_express_expired_status_id'])) { + $data['payment_pp_express_expired_status_id'] = $this->request->post['payment_pp_express_expired_status_id']; + } else { + $data['payment_pp_express_expired_status_id'] = $this->config->get('payment_pp_express_expired_status_id'); + } + + if (isset($this->request->post['payment_pp_express_failed_status_id'])) { + $data['payment_pp_express_failed_status_id'] = $this->request->post['payment_pp_express_failed_status_id']; + } else { + $data['payment_pp_express_failed_status_id'] = $this->config->get('payment_pp_express_failed_status_id'); + } + + if (isset($this->request->post['payment_pp_express_pending_status_id'])) { + $data['payment_pp_express_pending_status_id'] = $this->request->post['payment_pp_express_pending_status_id']; + } else { + $data['payment_pp_express_pending_status_id'] = $this->config->get('payment_pp_express_pending_status_id'); + } + + if (isset($this->request->post['payment_pp_express_processed_status_id'])) { + $data['payment_pp_express_processed_status_id'] = $this->request->post['payment_pp_express_processed_status_id']; + } else { + $data['payment_pp_express_processed_status_id'] = $this->config->get('payment_pp_express_processed_status_id'); + } + + if (isset($this->request->post['payment_pp_express_refunded_status_id'])) { + $data['payment_pp_express_refunded_status_id'] = $this->request->post['payment_pp_express_refunded_status_id']; + } else { + $data['payment_pp_express_refunded_status_id'] = $this->config->get('payment_pp_express_refunded_status_id'); + } + + if (isset($this->request->post['payment_pp_express_reversed_status_id'])) { + $data['payment_pp_express_reversed_status_id'] = $this->request->post['payment_pp_express_reversed_status_id']; + } else { + $data['payment_pp_express_reversed_status_id'] = $this->config->get('payment_pp_express_reversed_status_id'); + } + + if (isset($this->request->post['payment_pp_express_voided_status_id'])) { + $data['payment_pp_express_voided_status_id'] = $this->request->post['payment_pp_express_voided_status_id']; + } else { + $data['payment_pp_express_voided_status_id'] = $this->config->get('payment_pp_express_voided_status_id'); + } + + + + + + + + if (isset($this->request->post['payment_pp_express_style_layout'])) { + $data['payment_pp_express_style_layout'] = $this->request->post['payment_pp_express_style_layout']; + } else { + $data['payment_pp_express_style_layout'] = $this->config->get('payment_pp_express_style_layout'); + } + + if (isset($this->request->post['payment_pp_express_style_size'])) { + $data['payment_pp_express_style_size'] = $this->request->post['payment_pp_express_style_size']; + } else { + $data['payment_pp_express_style_size'] = $this->config->get('payment_pp_express_style_size'); + } + + if (isset($this->request->post['payment_pp_express_style_shape'])) { + $data['payment_pp_express_style_shape'] = $this->request->post['payment_pp_express_style_shape']; + } else { + $data['payment_pp_express_style_shape'] = $this->config->get('payment_pp_express_style_shape'); + } + + if (isset($this->request->post['payment_pp_express_style_color'])) { + $data['payment_pp_express_style_color'] = $this->request->post['payment_pp_express_style_color']; + } else { + $data['payment_pp_express_style_color'] = $this->config->get('payment_pp_express_style_color'); + } + + if (isset($this->request->post['payment_pp_express_pp_credit'])) { + $data['payment_pp_express_pp_credit'] = $this->request->post['payment_pp_express_pp_credit']; + } else { + // get the store country id from settings - if it is US then pp_credit is defaulted to on. + if ($this->config->get('payment_pp_express_pp_credit') == null) { + $this->load->model('localisation/country'); + + $store_country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + if (!empty($store_country) && $store_country['iso_code_2'] == "US") { + $data['payment_pp_express_pp_credit'] = 1; + } else { + $data['payment_pp_express_pp_credit'] = 0; + } + } else { + $data['payment_pp_express_pp_credit'] = $this->config->get('payment_pp_express_pp_credit'); + } + } + + if (isset($this->request->post['payment_pp_express_pp_cards'])) { + $data['payment_pp_express_pp_cards'] = $this->request->post['payment_pp_express_pp_cards']; + } else { + $data['payment_pp_express_pp_cards'] = $this->config->get('payment_pp_express_pp_cards'); + } + + if (isset($this->request->post['payment_pp_express_pp_elv'])) { + $data['payment_pp_express_pp_elv'] = $this->request->post['payment_pp_express_pp_elv']; + } else { + $data['payment_pp_express_pp_elv'] = $this->config->get('payment_pp_express_pp_elv'); + } + + if (isset($this->request->post['payment_pp_express_logo'])) { + $data['payment_pp_express_logo'] = $this->request->post['payment_pp_express_logo']; + } else { + $data['payment_pp_express_logo'] = $this->config->get('payment_pp_express_logo'); + } + + $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_express/ipn'; + + $this->load->model('extension/payment/pp_express'); + $this->load->model('tool/image'); + $this->load->model('localisation/geo_zone'); + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['currencies'] = $this->model_extension_payment_pp_express->getCurrencies(); + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_express_logo']) && is_file(DIR_IMAGE . $this->request->post['payment_pp_express_logo'])) { + $data['thumb'] = $this->model_tool_image->resize($this->request->post['payment_pp_express_logo'], 750, 90); + } elseif (is_file(DIR_IMAGE . $this->config->get('payment_pp_express_logo'))) { + $data['thumb'] = $this->model_tool_image->resize($this->config->get('payment_pp_express_logo'), 750, 90); + } else { + $data['thumb'] = $this->model_tool_image->resize('no_image.png', 750, 90); + } + + $data['placeholder'] = $this->model_tool_image->resize('no_image.png', 750, 90); + + if (isset($this->request->get['retrieve_code']) && isset($this->request->get['merchant_id'])) { + $curl = curl_init($this->opencart_retrieve_url); + + $post_data = array( + 'merchant_id' => $this->request->get['merchant_id'], + 'retrieve_code' => $this->request->get['retrieve_code'], + ); + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + + $curl_response = curl_exec($curl); + $config_response = json_decode($curl_response, true); + curl_close($curl); + + if (isset($config_response['api_user_name']) && isset($config_response['api_password']) && isset($config_response['signature'])) { + $pp_express_settings = $this->model_setting_setting->getSetting('payment_pp_express'); + + if ($config_response['environment'] == 'sandbox') { + $pp_express_settings['payment_pp_express_sandbox_username'] = $config_response['api_user_name']; + $pp_express_settings['payment_pp_express_sandbox_password'] = $config_response['api_password']; + $pp_express_settings['payment_pp_express_sandbox_signature'] = $config_response['signature']; + $pp_express_settings['payment_pp_express_test'] = 1; + + $data['payment_pp_express_sandbox_username'] = $config_response['api_user_name']; + $data['payment_pp_express_sandbox_password'] = $config_response['api_password']; + $data['payment_pp_express_sandbox_signature'] = $config_response['signature']; + $data['payment_pp_express_test'] = 1; + } else { + $pp_express_settings['payment_pp_express_username'] = $config_response['api_user_name']; + $pp_express_settings['payment_pp_express_password'] = $config_response['api_password']; + $pp_express_settings['payment_pp_express_signature'] = $config_response['signature']; + $pp_express_settings['payment_pp_express_test'] = 0; + + $data['payment_pp_express_username'] = $config_response['api_user_name']; + $data['payment_pp_express_password'] = $config_response['api_password']; + $data['payment_pp_express_signature'] = $config_response['signature']; + $data['payment_pp_express_test'] = 0; + } + + $data['retrieve_success'] = 1; + $data['text_retrieve'] = $this->language->get('text_retrieve'); + + $this->model_setting_setting->editSetting('payment_pp_express', $pp_express_settings); + } + } + + $this->load->model('localisation/country'); + + $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + 'store_url' => HTTPS_CATALOG, + 'store_version' => VERSION, + 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''), + ); + + // Create sandbox link + $curl = curl_init($this->opencart_connect_url); + + $post_data['environment'] = 'sandbox'; + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); + + $curl_response = curl_exec($curl); + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + $data['auth_connect_url_sandbox'] = ''; + if (isset($curl_response['url']) && !empty($curl_response['url'])) { + $data['auth_connect_url_sandbox'] = $curl_response['url']; + } + + // Create Live link + $curl = curl_init($this->opencart_connect_url); + + $post_data['environment'] = 'live'; + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); + + $curl_response = curl_exec($curl); + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + $data['auth_connect_url_live'] = ''; + if (isset($curl_response['url']) && !empty($curl_response['url'])) { + $data['auth_connect_url_live'] = $curl_response['url']; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_express', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_express')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if ($this->request->post['payment_pp_express_test']) { + if (!$this->request->post['payment_pp_express_sandbox_username']) { + $this->error['sandbox_username'] = $this->language->get('error_sandbox_username'); + } + + if (!$this->request->post['payment_pp_express_sandbox_password']) { + $this->error['sandbox_password'] = $this->language->get('error_sandbox_password'); + } + + if (!$this->request->post['payment_pp_express_sandbox_signature']) { + $this->error['sandbox_signature'] = $this->language->get('error_sandbox_signature'); + } + } else { + if (!$this->request->post['payment_pp_express_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_pp_express_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['payment_pp_express_signature']) { + $this->error['signature'] = $this->language->get('error_signature'); + } + } + + return !$this->error; + } + + public function install() { + $this->load->model('extension/payment/pp_express'); + + $this->model_extension_payment_pp_express->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/pp_express'); + + $this->model_extension_payment_pp_express->uninstall(); + } + + public function order() { + if ($this->config->get('payment_pp_express_status')) { + $this->load->language('extension/payment/pp_express_order'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('extension/payment/pp_express'); + + $paypal_info = $this->model_extension_payment_pp_express->getPayPalOrder($order_id); + + if ($paypal_info) { + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['capture_status'] = $paypal_info['capture_status']; + + $data['total'] = $paypal_info['total']; + + $captured = number_format($this->model_extension_payment_pp_express->getCapturedTotal($paypal_info['paypal_order_id']), 2); + + $data['captured'] = $captured; + + $data['capture_remaining'] = number_format($paypal_info['total'] - $captured, 2); + + $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotal($paypal_info['paypal_order_id']), 2); + + $data['refunded'] = $refunded; + + return $this->load->view('extension/payment/pp_express_order', $data); + } + } + } + + public function transaction() { + $this->load->language('extension/payment/pp_express_order'); + + $data['transactions'] = array(); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('extension/payment/pp_express'); + + $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id); + + if ($paypal_info) { + $results = $this->model_extension_payment_pp_express->getTransactions($paypal_info['paypal_order_id']); + + foreach ($results as $result) { + $data['transactions'][] = array( + 'transaction_id' => $result['transaction_id'], + 'amount' => $result['amount'], + 'payment_type' => $result['payment_type'], + 'payment_status' => $result['payment_status'], + 'pending_reason' => $result['pending_reason'], + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])), + 'view' => $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $result['transaction_id'], true), + 'refund' => $this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $result['transaction_id'], true), + 'resend' => $this->url->link('extension/payment/pp_express/resend', 'user_token=' . $this->session->data['user_token'] . '&paypal_order_transaction_id=' . $result['paypal_order_transaction_id'], true) + ); + } + } + + $this->response->setOutput($this->load->view('extension/payment/pp_express_transaction', $data)); + } + + public function capture() { + $json = array(); + + $this->load->language('extension/payment/pp_express_order'); + + if (!isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $json['error'] = $this->language->get('error_capture'); + } + + if (!$json) { + $this->load->model('extension/payment/pp_express'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id); + + if ($paypal_info) { + // If this is the final amount to capture or not + if ($this->request->post['complete'] == 1) { + $complete = 'Complete'; + } else { + $complete = 'NotComplete'; + } + + $request = array( + 'METHOD' => 'DoCapture', + 'AUTHORIZATIONID' => $paypal_info['authorization_id'], + 'AMT' => number_format($this->request->post['amount'], 2), + 'CURRENCYCODE' => $paypal_info['currency_code'], + 'COMPLETETYPE' => $complete, + 'MSGSUBID' => uniqid(mt_rand(), true) + ); + + $response = $this->model_extension_payment_pp_express->call($request); + + if (isset($response['ACK']) && ($response['ACK'] != 'Failure') && ($response['ACK'] != 'FailureWithWarning')) { + $transaction_data = array( + 'paypal_order_id' => $paypal_info['paypal_order_id'], + 'transaction_id' => $response['TRANSACTIONID'], + 'parent_id' => $paypal_info['authorization_id'], + 'note' => '', + 'msgsubid' => $response['MSGSUBID'], + 'receipt_id' => '', + 'payment_type' => $response['PAYMENTTYPE'], + 'payment_status' => $response['PAYMENTSTATUS'], + 'pending_reason' => (isset($response['PENDINGREASON']) ? $response['PENDINGREASON'] : ''), + 'transaction_entity' => 'payment', + 'amount' => $response['AMT'], + 'debug_data' => json_encode($response) + ); + + $this->model_extension_payment_pp_express->addTransaction($transaction_data); + + $captured = number_format($this->model_extension_payment_pp_express->getCapturedTotal($paypal_info['paypal_order_id']), 2); + $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotal($paypal_info['paypal_order_id']), 2); + + $json['captured'] = $captured; + $json['refunded'] = $refunded; + $json['remaining'] = number_format($paypal_info['total'] - $captured, 2); + + if ($this->request->post['complete'] == 1 || $json['remaining'] == 0.00) { + $json['capture_status'] = $this->language->get('text_complete'); + + $this->model_extension_payment_pp_express->editPayPalOrderStatus($order_id, 'Complete'); + } + + $json['success'] = $this->language->get('text_success'); + } else { + $json['error'] = (isset($response['L_SHORTMESSAGE0']) ? $response['L_SHORTMESSAGE0'] : $this->language->get('error_transaction')); + } + } else { + $json['error'] = $this->language->get('error_not_found'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function refund() { + $this->load->language('extension/payment/pp_express_refund'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'], true), + ); + + //button actions + $data['action'] = $this->url->link('extension/payment/pp_express/doRefund', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true); + + $data['transaction_id'] = $this->request->get['transaction_id']; + + $this->load->model('extension/payment/pp_express'); + $pp_transaction = $this->model_extension_payment_pp_express->getTransaction($this->request->get['transaction_id']); + + $data['amount_original'] = $pp_transaction['AMT']; + $data['currency_code'] = $pp_transaction['CURRENCYCODE']; + + $refunded = number_format($this->model_extension_payment_pp_express->getRefundedTotalByParentId($this->request->get['transaction_id']), 2); + + if ($refunded != 0.00) { + $data['refund_available'] = number_format($data['amount_original'] + $refunded, 2); + $data['attention'] = $this->language->get('text_current_refunds') . ': ' . $data['refund_available']; + } else { + $data['refund_available'] = ''; + $data['attention'] = ''; + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_express_refund', $data)); + } + + public function doRefund() { + /** + * used to issue a refund for a captured payment + * + * refund can be full or partial + */ + if (isset($this->request->post['transaction_id']) && isset($this->request->post['refund_full'])) { + + $this->load->model('extension/payment/pp_express'); + $this->load->language('extension/payment/pp_express_refund'); + + if ($this->request->post['refund_full'] == 0 && $this->request->post['amount'] == 0) { + $this->session->data['error'] = $this->language->get('error_partial_amt'); + } else { + $order_id = $this->model_extension_payment_pp_express->getOrderId($this->request->post['transaction_id']); + $paypal_order = $this->model_extension_payment_pp_express->getOrder($order_id); + + if ($paypal_order) { + $call_data = array(); + $call_data['METHOD'] = 'RefundTransaction'; + $call_data['TRANSACTIONID'] = $this->request->post['transaction_id']; + $call_data['NOTE'] = urlencode($this->request->post['refund_message']); + $call_data['MSGSUBID'] = uniqid(mt_rand(), true); + + $current_transaction = $this->model_extension_payment_pp_express->getLocalTransaction($this->request->post['transaction_id']); + + if ($this->request->post['refund_full'] == 1) { + $call_data['REFUNDTYPE'] = 'Full'; + } else { + $call_data['REFUNDTYPE'] = 'Partial'; + $call_data['AMT'] = number_format($this->request->post['amount'], 2); + $call_data['CURRENCYCODE'] = $this->request->post['currency_code']; + } + + $result = $this->model_extension_payment_pp_express->call($call_data); + + $transaction = array( + 'paypal_order_id' => $paypal_order['paypal_order_id'], + 'transaction_id' => '', + 'parent_transaction_id' => $this->request->post['transaction_id'], + 'note' => $this->request->post['refund_message'], + 'msgsubid' => $call_data['MSGSUBID'], + 'receipt_id' => '', + 'payment_type' => 'refund', + 'payment_status' => 'Refunded', + 'transaction_entity' => 'payment', + 'pending_reason' => '', + 'amount' => '-' . (isset($call_data['AMT']) ? $call_data['AMT'] : $current_transaction['amount']), + 'debug_data' => json_encode($result) + ); + + if ($result == false) { + $transaction['payment_status'] = 'Failed'; + $this->model_extension_payment_pp_express->addTransaction($transaction, $call_data); + $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true)); + } else if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + + $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID']; + $transaction['pending_reason'] = $result['PENDINGREASON']; + $transaction['amount'] = '-' . $result['GROSSREFUNDAMT']; + + $this->model_extension_payment_pp_express->addTransaction($transaction); + + //edit transaction to refunded status + if ($result['TOTALREFUNDEDAMOUNT'] == $this->request->post['amount_original']) { + $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Refunded' WHERE `transaction_id` = '" . $this->db->escape($this->request->post['transaction_id']) . "' LIMIT 1"); + } else { + $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Partially-Refunded' WHERE `transaction_id` = '" . $this->db->escape($this->request->post['transaction_id']) . "' LIMIT 1"); + } + + //redirect back to the order + $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true)); + } else { + $this->model_extension_payment_pp_express->log(json_encode($result)); + $this->session->data['error'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error') . (isset($result['L_LONGMESSAGE0']) ? '<br />' . $result['L_LONGMESSAGE0'] : ''); + $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } else { + $this->session->data['error'] = $this->language->get('error_data_missing'); + $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } + } else { + $this->session->data['error'] = $this->language->get('error_data'); + $this->response->redirect($this->url->link('extension/payment/pp_express/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } + + /** + * used to void an authorised payment + */ + public function void() { + $json = array(); + + $this->load->language('extension/payment/pp_express_order'); + + if (isset($this->request->get['order_id'])) { + $order_id = $this->request->get['order_id']; + } else { + $order_id = 0; + } + + $this->load->model('extension/payment/pp_express'); + + $paypal_info = $this->model_extension_payment_pp_express->getOrder($order_id); + + if ($paypal_info) { + $request = array( + 'METHOD' => 'DoVoid', + 'AUTHORIZATIONID' => $paypal_info['authorization_id'], + 'MSGSUBID' => uniqid(mt_rand(), true) + ); + + $response_info = $this->model_extension_payment_pp_express->call($request); + + if (isset($response_info['ACK']) && ($response_info['ACK'] != 'Failure') && ($response_info['ACK'] != 'FailureWithWarning')) { + $transaction = array( + 'paypal_order_id' => $paypal_info['paypal_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_info['authorization_id'], + 'note' => '', + 'msgsubid' => '', + 'receipt_id' => '', + 'payment_type' => 'void', + 'payment_status' => 'Void', + 'pending_reason' => '', + 'transaction_entity' => 'auth', + 'amount' => '', + 'debug_data' => json_encode($response_info) + ); + + $this->model_extension_payment_pp_express->addTransaction($transaction); + + $this->model_extension_payment_pp_express->editPayPalOrderStatus($order_id, 'Complete'); + + $json['capture_status'] = 'Complete'; + + $json['success'] = $this->language->get('text_success'); + } else { + $json['error'] = (isset($response_info['L_SHORTMESSAGE0']) ? $response_info['L_SHORTMESSAGE0'] : $this->language->get('error_transaction')); + } + } else { + $json['error'] = $this->language->get('error_not_found'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + // Cancel an active recurring + public function recurringCancel() { + $json = array(); + + $this->load->language('extension/recurring/pp_express'); + + //cancel an active recurring + $this->load->model('account/recurring'); + + if (isset($this->request->get['order_recurring_id'])) { + $order_recurring_id = $this->request->get['order_recurring_id']; + } else { + $order_recurring_id = 0; + } + + $recurring_info = $this->model_account_recurring->getOrderRecurring($order_recurring_id); + + if ($recurring_info && $recurring_info['reference']) { + if ($this->config->get('payment_pp_express_test')) { + $api_url = 'https://api-3t.sandbox.paypal.com/nvp'; + $api_username = $this->config->get('payment_pp_express_sandbox_username'); + $api_password = $this->config->get('payment_pp_express_sandbox_password'); + $api_signature = $this->config->get('payment_pp_express_sandbox_signature'); + } else { + $api_url = 'https://api-3t.paypal.com/nvp'; + $api_username = $this->config->get('payment_pp_express_username'); + $api_password = $this->config->get('payment_pp_express_password'); + $api_signature = $this->config->get('payment_pp_express_signature'); + } + + $request = array( + 'USER' => $api_username, + 'PWD' => $api_password, + 'SIGNATURE' => $api_signature, + 'VERSION' => '109.0', + 'BUTTONSOURCE' => 'OpenCart_2.0_EC', + 'METHOD' => 'SetExpressCheckout', + 'METHOD' => 'ManageRecurringPaymentsProfileStatus', + 'PROFILEID' => $recurring_info['reference'], + 'ACTION' => 'Cancel' + ); + + $curl = curl_init($api_url); + + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $request); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_TIMEOUT, 30); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + + $response = curl_exec($curl); + + if (!$response) { + $this->log(sprintf($this->language->get('error_curl'), curl_errno($curl), curl_error($curl))); + } + + curl_close($curl); + + $response_info = array(); + + parse_str($response, $response_info); + + if (isset($response_info['PROFILEID'])) { + $this->model_account_recurring->editOrderRecurringStatus($order_recurring_id, 4); + $this->model_account_recurring->addOrderRecurringTransaction($order_recurring_id, 5); + + $json['success'] = $this->language->get('text_cancelled'); + } else { + $json['error'] = sprintf($this->language->get('error_not_cancelled'), $response_info['L_LONGMESSAGE0']); + } + } else { + $json['error'] = $this->language->get('error_not_found'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function resend() { + $json = array(); + + $this->load->language('extension/payment/pp_express'); + + if (isset($this->request->get['paypal_order_transaction_id'])) { + $paypal_order_transaction_id = $this->request->get['paypal_order_transaction_id']; + } else { + $paypal_order_transaction_id = 0; + } + + $this->load->model('extension/payment/pp_express'); + + $transaction = $this->model_extension_payment_pp_express->getFailedTransaction($paypal_order_transaction_id); + + if ($transaction) { + + $call_data = json_decode($transaction['call_data'], true); + + $result = $this->model_extension_payment_pp_express->call($call_data); + + if ($result) { + + $parent_transaction = $this->model_extension_payment_pp_express->getLocalTransaction($transaction['parent_id']); + + if ($parent_transaction['amount'] == abs($transaction['amount'])) { + $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Refunded' WHERE `transaction_id` = '" . $this->db->escape($transaction['parent_id']) . "' LIMIT 1"); + } else { + $this->db->query("UPDATE `" . DB_PREFIX . "paypal_order_transaction` SET `payment_status` = 'Partially-Refunded' WHERE `transaction_id` = '" . $this->db->escape($transaction['parent_id']) . "' LIMIT 1"); + } + + if (isset($result['REFUNDTRANSACTIONID'])) { + $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID']; + } else { + $transaction['transaction_id'] = $result['TRANSACTIONID']; + } + + if (isset($result['PAYMENTTYPE'])) { + $transaction['payment_type'] = $result['PAYMENTTYPE']; + } else { + $transaction['payment_type'] = $result['REFUNDSTATUS']; + } + + if (isset($result['PAYMENTSTATUS'])) { + $transaction['payment_status'] = $result['PAYMENTSTATUS']; + } else { + $transaction['payment_status'] = 'Refunded'; + } + + if (isset($result['AMT'])) { + $transaction['amount'] = $result['AMT']; + } else { + $transaction['amount'] = $transaction['amount']; + } + + $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : ''); + + $this->model_extension_payment_pp_express->updateTransaction($transaction); + + $json['success'] = $this->language->get('success_transaction_resent'); + } else { + $json['error'] = $this->language->get('error_timeout'); + } + } else { + $json['error'] = $this->language->get('error_transaction_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function search() { + $this->load->language('extension/payment/pp_express_search'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['user_token'] = $this->session->data['user_token']; + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true), + ); + + $this->load->model('extension/payment/pp_express'); + + $data['currency_codes'] = $this->model_extension_payment_pp_express->getCurrencies(); + + $data['default_currency'] = $this->config->get('payment_pp_express_currency'); + + $data['date_start'] = date("Y-m-d", strtotime('-30 days')); + $data['date_end'] = date("Y-m-d"); + $data['view_link'] = $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'], true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_express_search', $data)); + } + + public function info() { + $this->load->language('extension/payment/pp_express_view'); + + $this->document->setTitle($this->language->get('heading_title')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->get['transaction_id'], true), + ); + + $this->load->model('extension/payment/pp_express'); + + $data['transaction'] = $this->model_extension_payment_pp_express->getTransaction($this->request->get['transaction_id']); + $data['lines'] = $this->formatRows($data['transaction']); + $data['view_link'] = $this->url->link('extension/payment/pp_express/info', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('extension/payment/pp_express/search', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_express_view', $data)); + } + + public function doSearch() { + /** + * used to search for transactions from a user account + */ + if (isset($this->request->post['date_start'])) { + + $this->load->model('extension/payment/pp_express'); + + $call_data = array(); + $call_data['METHOD'] = 'TransactionSearch'; + $call_data['STARTDATE'] = gmdate($this->request->post['date_start'] . "\TH:i:s\Z"); + + if (!empty($this->request->post['date_end'])) { + $call_data['ENDDATE'] = gmdate($this->request->post['date_end'] . "\TH:i:s\Z"); + } + + if (!empty($this->request->post['transaction_class'])) { + $call_data['TRANSACTIONCLASS'] = $this->request->post['transaction_class']; + } + + if (!empty($this->request->post['status'])) { + $call_data['STATUS'] = $this->request->post['status']; + } + + if (!empty($this->request->post['buyer_email'])) { + $call_data['EMAIL'] = $this->request->post['buyer_email']; + } + + if (!empty($this->request->post['merchant_email'])) { + $call_data['RECEIVER'] = $this->request->post['merchant_email']; + } + + if (!empty($this->request->post['receipt_id'])) { + $call_data['RECEIPTID'] = $this->request->post['receipt_id']; + } + + if (!empty($this->request->post['transaction_id'])) { + $call_data['TRANSACTIONID'] = $this->request->post['transaction_id']; + } + + if (!empty($this->request->post['invoice_number'])) { + $call_data['INVNUM'] = $this->request->post['invoice_number']; + } + + if (!empty($this->request->post['auction_item_number'])) { + $call_data['AUCTIONITEMNUMBER'] = $this->request->post['auction_item_number']; + } + + if (!empty($this->request->post['amount'])) { + $call_data['AMT'] = number_format($this->request->post['amount'], 2); + $call_data['CURRENCYCODE'] = $this->request->post['currency_code']; + } + + if (!empty($this->request->post['recurring_id'])) { + $call_data['PROFILEID'] = $this->request->post['recurring_id']; + } + + if (!empty($this->request->post['name_salutation'])) { + $call_data['SALUTATION'] = $this->request->post['name_salutation']; + } + + if (!empty($this->request->post['name_first'])) { + $call_data['FIRSTNAME'] = $this->request->post['name_first']; + } + + if (!empty($this->request->post['name_middle'])) { + $call_data['MIDDLENAME'] = $this->request->post['name_middle']; + } + + if (!empty($this->request->post['name_last'])) { + $call_data['LASTNAME'] = $this->request->post['name_last']; + } + + if (!empty($this->request->post['name_suffix'])) { + $call_data['SUFFIX'] = $this->request->post['name_suffix']; + } + + $result = $this->model_extension_payment_pp_express->call($call_data); + + if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning' && $result['ACK'] != 'Warning') { + $response['error'] = false; + $response['result'] = $this->formatRows($result); + } else { + $response['error'] = true; + $response['error_msg'] = $result['L_LONGMESSAGE0']; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } else { + $response['error'] = true; + $response['error_msg'] = 'Enter a start date'; + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($response)); + } + } + + public function live() { + if (isset($this->request->get['merchantId'])) { + $this->load->language('extension/payment/pp_express'); + + $this->load->model('extension/payment/pp_express'); + $this->load->model('setting/setting'); + + $token = $this->model_extension_payment_pp_express->getTokens('live'); + + if (isset($token->access_token)) { + $user_info = $this->model_extension_payment_pp_express->getUserInfo($this->request->get['merchantId'], 'live', $token->access_token); + } else { + $this->session->data['error_api'] = $this->language->get('error_api'); + } + + if (isset($user_info->api_user_name)) { + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_username', $user_info->api_user_name); + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_password', $user_info->api_password); + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_signature', $user_info->signature); + } else { + $this->session->data['error_api'] = $this->language->get('error_api'); + } + } + + $this->response->redirect($this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function sandbox() { + if (isset($this->request->get['merchantId'])) { + $this->load->language('extension/payment/pp_express'); + + $this->load->model('extension/payment/pp_express'); + $this->load->model('setting/setting'); + + $token = $this->model_extension_payment_pp_express->getTokens('sandbox'); + + if (isset($token->access_token)) { + $user_info = $this->model_extension_payment_pp_express->getUserInfo($this->request->get['merchantId'], 'sandbox', $token->access_token); + } else { + $this->session->data['error_api'] = $this->language->get('error_api_sandbox'); + } + + if (isset($user_info->api_user_name)) { + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_username', $user_info->api_user_name); + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_password', $user_info->api_password); + $this->model_setting_setting->editSettingValue('payment_pp_express', 'payment_pp_express_sandbox_signature', $user_info->signature); + } else { + $this->session->data['error_api'] = $this->language->get('error_api_sandbox'); + } + } + $this->response->redirect($this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true)); + } + + private function formatRows($data) { + $return = array(); + + foreach ($data as $k => $v) { + $elements = preg_split("/(\d+)/", $k, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); + if (isset($elements[1]) && isset($elements[0])) { + if ($elements[0] == 'L_TIMESTAMP') { + $v = str_replace('T', ' ', $v); + $v = str_replace('Z', '', $v); + } + $return[$elements[1]][$elements[0]] = $v; + } + } + + return $return; + } + + public function recurringButtons() { + $this->load->model('sale/recurring'); + + $recurring = $this->model_sale_recurring->getRecurring($this->request->get['order_recurring_id']); + + $data['buttons'] = array(); + + if ($recurring['status'] == 2 || $recurring['status'] == 3) { + $data['buttons'][] = array( + 'text' => $this->language->get('button_cancel_recurring'), + 'link' => $this->url->link('extension/payment/pp_express/recurringCancel', 'order_recurring_id=' . $this->request->get['order_recurring_id'] . '&user_token=' . $this->request->get['user_token'], true) + ); + } + + return $this->load->view('sale/recurring_button', $data); + } + + public function connectRedirect() { + if ($this->user->hasPermission('modify', 'extension/extension/payment') && $this->user->hasPermission('modify', 'extension/payment/pp_express')) { + // Install the module before doing the redirect + $this->load->model('setting/extension'); + + $this->model_setting_extension->install('payment', 'pp_express'); + + $this->install(); + + $this->load->model('localisation/country'); + + $country = $this->model_localisation_country->getCountry($this->config->get('config_country_id')); + + $post_data = array( + 'return_url' => $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true), + 'store_url' => HTTPS_CATALOG, + 'store_version' => VERSION, + 'store_country' => (isset($country['iso_code_3']) ? $country['iso_code_3'] : ''), + ); + + // Create Live link + $curl = curl_init($this->opencart_connect_url); + + $post_data['environment'] = 'live'; + + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_FORBID_REUSE, 1); + curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1); + curl_setopt($curl, CURLOPT_POST, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); + + $curl_response = curl_exec($curl); + $curl_response = json_decode($curl_response, true); + + curl_close($curl); + + if (isset($curl_response['url']) && !empty($curl_response['url'])) { + $this->response->redirect($curl_response['url']); + } else { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true)); + } + } else { + $this->response->redirect($this->url->link('error/permission', 'user_token=' . $this->session->data['user_token'], true)); + } + } + + public function promotion() { + $this->load->language('extension/payment/pp_express'); + + $data['connect_link'] = ''; + $data['module_link'] = ''; + + if ($this->config->get('payment_pp_express_username') || $this->config->get('payment_pp_express_sandbox_username')) { + $data['module_link'] = $this->url->link('extension/payment/pp_express', 'user_token=' . $this->session->data['user_token'], true); + } else { + if ($this->user->hasPermission('modify', 'extension/extension/payment')) { + $data['connect_link'] = $this->url->link('extension/payment/pp_express/connectRedirect', 'user_token=' . $this->session->data['user_token'], true); + } + } + + if ($this->config->get("payment_pp_express_status") == 1) { + $data['payment_pp_express_status'] = "enabled"; + } elseif ($this->config->get("payment_pp_express_status") == null) { + $data['payment_pp_express_status'] = ""; + } else { + $data['payment_pp_express_status'] = "disabled"; + } + + return $this->load->view('extension/payment/pp_express_promotion', $data); + } +} diff --git a/public/admin/controller/extension/payment/pp_payflow.php b/public/admin/controller/extension/payment/pp_payflow.php new file mode 100644 index 0000000..92ca1a0 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_payflow.php @@ -0,0 +1,177 @@ +<?php +class ControllerExtensionPaymentPPPayflow extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_payflow'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_payflow', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['vendor'])) { + $data['error_vendor'] = $this->error['vendor']; + } else { + $data['error_vendor'] = ''; + } + + if (isset($this->error['user'])) { + $data['error_user'] = $this->error['user']; + } else { + $data['error_user'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['partner'])) { + $data['error_partner'] = $this->error['partner']; + } else { + $data['error_partner'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_payflow', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['action'] = $this->url->link('extension/payment/pp_payflow', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_payflow_vendor'])) { + $data['payment_pp_payflow_vendor'] = $this->request->post['payment_pp_payflow_vendor']; + } else { + $data['payment_pp_payflow_vendor'] = $this->config->get('payment_pp_payflow_vendor'); + } + + if (isset($this->request->post['payment_pp_payflow_user'])) { + $data['payment_pp_payflow_user'] = $this->request->post['payment_pp_payflow_user']; + } else { + $data['payment_pp_payflow_user'] = $this->config->get('payment_pp_payflow_user'); + } + + if (isset($this->request->post['payment_pp_payflow_password'])) { + $data['payment_pp_payflow_password'] = $this->request->post['payment_pp_payflow_password']; + } else { + $data['payment_pp_payflow_password'] = $this->config->get('payment_pp_payflow_password'); + } + + if (isset($this->request->post['payment_pp_payflow_partner'])) { + $data['payment_pp_payflow_partner'] = $this->request->post['payment_pp_payflow_partner']; + } elseif ($this->config->has('payment_pp_payflow_partner')) { + $data['payment_pp_payflow_partner'] = $this->config->get('payment_pp_payflow_partner'); + } else { + $data['payment_pp_payflow_partner'] = 'PayPal'; + } + + if (isset($this->request->post['payment_pp_payflow_test'])) { + $data['payment_pp_payflow_test'] = $this->request->post['payment_pp_payflow_test']; + } else { + $data['payment_pp_payflow_test'] = $this->config->get('payment_pp_payflow_test'); + } + + if (isset($this->request->post['payment_pp_payflow_transaction'])) { + $data['payment_pp_payflow_transaction'] = $this->request->post['payment_pp_payflow_transaction']; + } else { + $data['payment_pp_payflow_transaction'] = $this->config->get('payment_pp_payflow_transaction'); + } + + if (isset($this->request->post['payment_pp_payflow_total'])) { + $data['payment_pp_payflow_total'] = $this->request->post['payment_pp_payflow_total']; + } else { + $data['payment_pp_payflow_total'] = $this->config->get('payment_pp_payflow_total'); + } + + if (isset($this->request->post['payment_pp_payflow_order_status_id'])) { + $data['payment_pp_payflow_order_status_id'] = $this->request->post['payment_pp_payflow_order_status_id']; + } else { + $data['payment_pp_payflow_order_status_id'] = $this->config->get('payment_pp_payflow_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_payflow_geo_zone_id'])) { + $data['payment_pp_payflow_geo_zone_id'] = $this->request->post['payment_pp_payflow_geo_zone_id']; + } else { + $data['payment_pp_payflow_geo_zone_id'] = $this->config->get('payment_pp_payflow_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_payflow_status'])) { + $data['payment_pp_payflow_status'] = $this->request->post['payment_pp_payflow_status']; + } else { + $data['payment_pp_payflow_status'] = $this->config->get('payment_pp_payflow_status'); + } + + if (isset($this->request->post['payment_pp_payflow_sort_order'])) { + $data['payment_pp_payflow_sort_order'] = $this->request->post['payment_pp_payflow_sort_order']; + } else { + $data['payment_pp_payflow_sort_order'] = $this->config->get('payment_pp_payflow_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_payflow', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_payflow')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_payflow_vendor']) { + $this->error['vendor'] = $this->language->get('error_vendor'); + } + + if (!$this->request->post['payment_pp_payflow_user']) { + $this->error['user'] = $this->language->get('error_user'); + } + + if (!$this->request->post['payment_pp_payflow_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['payment_pp_payflow_partner']) { + $this->error['partner'] = $this->language->get('error_partner'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pp_payflow_iframe.php b/public/admin/controller/extension/payment/pp_payflow_iframe.php new file mode 100644 index 0000000..635751a --- /dev/null +++ b/public/admin/controller/extension/payment/pp_payflow_iframe.php @@ -0,0 +1,483 @@ +<?php +class ControllerExtensionPaymentPPPayflowIframe extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_payflow_iframe'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_payflow_iframe', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['vendor'])) { + $data['error_vendor'] = $this->error['vendor']; + } else { + $data['error_vendor'] = ''; + } + + if (isset($this->error['user'])) { + $data['error_user'] = $this->error['user']; + } else { + $data['error_user'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['partner'])) { + $data['error_partner'] = $this->error['partner']; + } else { + $data['error_partner'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_pp_express'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true), + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe', 'user_token=' . $this->session->data['user_token'], true), + ); + + $data['action'] = $this->url->link('extension/payment/pp_payflow_iframe', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_payflow_iframe_vendor'])) { + $data['payment_pp_payflow_iframe_vendor'] = $this->request->post['payment_pp_payflow_iframe_vendor']; + } else { + $data['payment_pp_payflow_iframe_vendor'] = $this->config->get('payment_pp_payflow_iframe_vendor'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_user'])) { + $data['payment_pp_payflow_iframe_user'] = $this->request->post['payment_pp_payflow_iframe_user']; + } else { + $data['payment_pp_payflow_iframe_user'] = $this->config->get('payment_pp_payflow_iframe_user'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_password'])) { + $data['payment_pp_payflow_iframe_password'] = $this->request->post['payment_pp_payflow_iframe_password']; + } else { + $data['payment_pp_payflow_iframe_password'] = $this->config->get('payment_pp_payflow_iframe_password'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_partner'])) { + $data['payment_pp_payflow_iframe_partner'] = $this->request->post['payment_pp_payflow_iframe_partner']; + } else { + $data['payment_pp_payflow_iframe_partner'] = $this->config->get('payment_pp_payflow_iframe_partner'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_transaction_method'])) { + $data['payment_pp_payflow_iframe_transaction_method'] = $this->request->post['payment_pp_payflow_iframe_transaction_method']; + } else { + $data['payment_pp_payflow_iframe_transaction_method'] = $this->config->get('payment_pp_payflow_iframe_transaction_method'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_test'])) { + $data['payment_pp_payflow_iframe_test'] = $this->request->post['payment_pp_payflow_iframe_test']; + } else { + $data['payment_pp_payflow_iframe_test'] = $this->config->get('payment_pp_payflow_iframe_test'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_total'])) { + $data['payment_pp_payflow_iframe_total'] = $this->request->post['payment_pp_payflow_iframe_total']; + } else { + $data['payment_pp_payflow_iframe_total'] = $this->config->get('payment_pp_payflow_iframe_total'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_payflow_iframe_order_status_id'])) { + $data['payment_pp_payflow_iframe_order_status_id'] = $this->request->post['payment_pp_payflow_iframe_order_status_id']; + } else { + $data['payment_pp_payflow_iframe_order_status_id'] = $this->config->get('payment_pp_payflow_iframe_order_status_id'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_geo_zone_id'])) { + $data['payment_pp_payflow_iframe_geo_zone_id'] = $this->request->post['payment_pp_payflow_iframe_geo_zone_id']; + } else { + $data['payment_pp_payflow_iframe_geo_zone_id'] = $this->config->get('payment_pp_payflow_iframe_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_payflow_iframe_status'])) { + $data['payment_pp_payflow_iframe_status'] = $this->request->post['payment_pp_payflow_iframe_status']; + } else { + $data['payment_pp_payflow_iframe_status'] = $this->config->get('payment_pp_payflow_iframe_status'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_sort_order'])) { + $data['payment_pp_payflow_iframe_sort_order'] = $this->request->post['payment_pp_payflow_iframe_sort_order']; + } else { + $data['payment_pp_payflow_iframe_sort_order'] = $this->config->get('payment_pp_payflow_iframe_sort_order'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_checkout_method'])) { + $data['payment_pp_payflow_iframe_checkout_method'] = $this->request->post['payment_pp_payflow_iframe_checkout_method']; + } else { + $data['payment_pp_payflow_iframe_checkout_method'] = $this->config->get('payment_pp_payflow_iframe_checkout_method'); + } + + if (isset($this->request->post['payment_pp_payflow_iframe_debug'])) { + $data['payment_pp_payflow_iframe_debug'] = $this->request->post['payment_pp_payflow_iframe_debug']; + } else { + $data['payment_pp_payflow_iframe_debug'] = $this->config->get('payment_pp_payflow_iframe_debug'); + } + + $data['post_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentipn'; + $data['cancel_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentcancel'; + $data['error_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymenterror'; + $data['return_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_payflow_iframe/paymentreturn'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_payflow_iframe', $data)); + } + + public function install() { + $this->load->model('extension/payment/pp_payflow_iframe'); + + $this->model_extension_payment_pp_payflow_iframe->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/pp_payflow_iframe'); + + $this->model_extension_payment_pp_payflow_iframe->uninstall(); + } + + public function refund() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->model('sale/order'); + $this->load->language('extension/payment/pp_payflow_iframe'); + + $transaction = $this->model_extension_payment_pp_payflow_iframe->getTransaction($this->request->get['transaction_reference']); + + if ($transaction) { + $this->document->setTitle($this->language->get('heading_refund')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_refund'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $this->request->get['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true) + ); + + $data['transaction_reference'] = $transaction['transaction_reference']; + $data['transaction_amount'] = number_format($transaction['amount'], 2); + $data['cancel'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction['order_id'], true); + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_payflow_iframe_refund', $data)); + } else { + return $this->forward('error/not_found'); + } + } + + public function doRefund() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->language('extension/payment/pp_payflow_iframe'); + $json = array(); + + if (isset($this->request->post['transaction_reference']) && isset($this->request->post['amount'])) { + + $transaction = $this->model_extension_payment_pp_payflow_iframe->getTransaction($this->request->post['transaction_reference']); + + if ($transaction) { + $call_data = array( + 'TRXTYPE' => 'C', + 'TENDER' => 'C', + 'ORIGID' => $transaction['transaction_reference'], + 'AMT' => $this->request->post['amount'], + ); + + $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data); + + if ($result['RESULT'] == 0) { + $json['success'] = $this->language->get('text_refund_issued'); + + $data = array( + 'order_id' => $transaction['order_id'], + 'type' => 'C', + 'transaction_reference' => $result['PNREF'], + 'amount' => $this->request->post['amount'], + ); + + $this->model_extension_payment_pp_payflow_iframe->addTransaction($data); + } else { + $json['error'] = $result['RESPMSG']; + } + } else { + $json['error'] = $this->language->get('error_missing_order'); + } + } else { + $json['error'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->model('sale/order'); + $this->load->language('extension/payment/pp_payflow_iframe'); + + if (isset($this->request->post['order_id']) && isset($this->request->post['amount']) && isset($this->request->post['complete'])) { + $order_id = $this->request->post['order_id']; + $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id); + $paypal_transactions = $this->model_extension_payment_pp_payflow_iframe->getTransactions($order_id); + $order_info = $this->model_sale_order->getOrder($order_id); + + if ($paypal_order && $order_info) { + if ($this->request->post['complete'] == 1) { + $complete = 'Y'; + } else { + $complete = 'N'; + } + + $call_data = array( + 'TRXTYPE' => 'D', + 'TENDER' => 'C', + 'ORIGID' => $paypal_order['transaction_reference'], + 'AMT' => $this->request->post['amount'], + 'CAPTURECOMPLETE' => $complete + ); + + $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data); + + if ($result['RESULT'] == 0) { + + $data = array( + 'order_id' => $order_id, + 'type' => 'D', + 'transaction_reference' => $result['PNREF'], + 'amount' => $this->request->post['amount'] + ); + + $this->model_extension_payment_pp_payflow_iframe->addTransaction($data); + $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, $this->request->post['complete']); + + $actions = array(); + + $actions[] = array( + 'title' => $this->language->get('text_capture'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $result['PNREF'] . '&user_token=' . $this->session->data['user_token'], true), + ); + + $json['success'] = array( + 'transaction_type' => $this->language->get('text_capture'), + 'transaction_reference' => $result['PNREF'], + 'time' => date('Y-m-d H:i:s'), + 'amount' => number_format($this->request->post['amount'], 2), + 'actions' => $actions, + ); + } else { + $json['error'] = $result['RESPMSG']; + } + } else { + $json['error'] = $this->language->get('error_missing_order'); + } + } else { + $json['error'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function void() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->language('extension/payment/pp_payflow_iframe'); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $order_id = $this->request->post['order_id']; + $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id); + + if ($paypal_order) { + $call_data = array( + 'TRXTYPE' => 'V', + 'TENDER' => 'C', + 'ORIGID' => $paypal_order['transaction_reference'], + ); + + $result = $this->model_extension_payment_pp_payflow_iframe->call($call_data); + + if ($result['RESULT'] == 0) { + $json['success'] = $this->language->get('text_void_success'); + $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, 1); + + $data = array( + 'order_id' => $order_id, + 'type' => 'V', + 'transaction_reference' => $result['PNREF'], + 'amount' => '', + ); + + $this->model_extension_payment_pp_payflow_iframe->addTransaction($data); + $this->model_extension_payment_pp_payflow_iframe->updateOrderStatus($order_id, 1); + + $json['success'] = array( + 'transaction_type' => $this->language->get('text_void'), + 'transaction_reference' => $result['PNREF'], + 'time' => date('Y-m-d H:i:s'), + 'amount' => '0.00', + ); + } else { + $json['error'] = $result['RESPMSG']; + } + } else { + $json['error'] = $this->language->get('error_missing_order'); + } + } else { + $json['error'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function order() { + $this->load->model('extension/payment/pp_payflow_iframe'); + $this->load->language('extension/payment/pp_payflow_iframe'); + + $order_id = $this->request->get['order_id']; + + $paypal_order = $this->model_extension_payment_pp_payflow_iframe->getOrder($order_id); + + if ($paypal_order) { + $data['complete'] = $paypal_order['complete']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + $data['transactions'] = array(); + + $transactions = $this->model_extension_payment_pp_payflow_iframe->getTransactions($order_id); + + foreach ($transactions as $transaction) { + $actions = array(); + + switch ($transaction['transaction_type']) { + case 'V': + $transaction_type = $this->language->get('text_void'); + break; + case 'S': + $transaction_type = $this->language->get('text_sale'); + + $actions[] = array( + 'title' => $this->language->get('text_refund'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $transaction['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true), + ); + break; + case 'D': + $transaction_type = $this->language->get('text_capture'); + + $actions[] = array( + 'title' => $this->language->get('text_refund'), + 'href' => $this->url->link('extension/payment/pp_payflow_iframe/refund', 'transaction_reference=' . $transaction['transaction_reference'] . '&user_token=' . $this->session->data['user_token'], true), + ); + break; + case 'A': + $transaction_type = $this->language->get('text_authorise'); + break; + + case 'C': + $transaction_type = $this->language->get('text_refund');# + break; + + default: + $transaction_type = ''; + break; + } + + $data['transactions'][] = array( + 'transaction_reference' => $transaction['transaction_reference'], + 'transaction_type' => $transaction_type, + 'time' => $transaction['time'], + 'amount' => $transaction['amount'], + 'actions' => $actions + ); + } + + return $this->load->view('extension/payment/pp_payflow_iframe_order', $data); + } + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_payflow_iframe')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_payflow_iframe_vendor']) { + $this->error['vendor'] = $this->language->get('error_vendor'); + } + + if (!$this->request->post['payment_pp_payflow_iframe_user']) { + $this->error['user'] = $this->language->get('error_user'); + } + + if (!$this->request->post['payment_pp_payflow_iframe_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['payment_pp_payflow_iframe_partner']) { + $this->error['partner'] = $this->language->get('error_partner'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/pp_pro.php b/public/admin/controller/extension/payment/pp_pro.php new file mode 100644 index 0000000..77ab2d7 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_pro.php @@ -0,0 +1,159 @@ +<?php +class ControllerExtensionPaymentPPPro extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_pro'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_pro', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['signature'])) { + $data['error_signature'] = $this->error['signature']; + } else { + $data['error_signature'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_pro', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pp_pro', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_pro_username'])) { + $data['payment_pp_pro_username'] = $this->request->post['payment_pp_pro_username']; + } else { + $data['payment_pp_pro_username'] = $this->config->get('payment_pp_pro_username'); + } + + if (isset($this->request->post['payment_pp_pro_password'])) { + $data['payment_pp_pro_password'] = $this->request->post['payment_pp_pro_password']; + } else { + $data['payment_pp_pro_password'] = $this->config->get('payment_pp_pro_password'); + } + + if (isset($this->request->post['payment_pp_pro_signature'])) { + $data['payment_pp_pro_signature'] = $this->request->post['payment_pp_pro_signature']; + } else { + $data['payment_pp_pro_signature'] = $this->config->get('payment_pp_pro_signature'); + } + + if (isset($this->request->post['payment_pp_pro_test'])) { + $data['payment_pp_pro_test'] = $this->request->post['payment_pp_pro_test']; + } else { + $data['payment_pp_pro_test'] = $this->config->get('payment_pp_pro_test'); + } + + if (isset($this->request->post['payment_pp_pro_transaction'])) { + $data['payment_pp_pro_transaction'] = $this->request->post['payment_pp_pro_transaction']; + } else { + $data['payment_pp_pro_transaction'] = $this->config->get('payment_pp_pro_transaction'); + } + + if (isset($this->request->post['payment_pp_pro_total'])) { + $data['payment_pp_pro_total'] = $this->request->post['payment_pp_pro_total']; + } else { + $data['payment_pp_pro_total'] = $this->config->get('payment_pp_pro_total'); + } + + if (isset($this->request->post['payment_pp_pro_order_status_id'])) { + $data['payment_pp_pro_order_status_id'] = $this->request->post['payment_pp_pro_order_status_id']; + } else { + $data['payment_pp_pro_order_status_id'] = $this->config->get('payment_pp_pro_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_pro_geo_zone_id'])) { + $data['payment_pp_pro_geo_zone_id'] = $this->request->post['payment_pp_pro_geo_zone_id']; + } else { + $data['payment_pp_pro_geo_zone_id'] = $this->config->get('payment_pp_pro_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_pro_status'])) { + $data['payment_pp_pro_status'] = $this->request->post['payment_pp_pro_status']; + } else { + $data['payment_pp_pro_status'] = $this->config->get('payment_pp_pro_status'); + } + + if (isset($this->request->post['payment_pp_pro_sort_order'])) { + $data['payment_pp_pro_sort_order'] = $this->request->post['payment_pp_pro_sort_order']; + } else { + $data['payment_pp_pro_sort_order'] = $this->config->get('payment_pp_pro_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_pro', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_pro')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_pro_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_pp_pro_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['payment_pp_pro_signature']) { + $this->error['signature'] = $this->language->get('error_signature'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pp_pro_iframe.php b/public/admin/controller/extension/payment/pp_pro_iframe.php new file mode 100644 index 0000000..489b017 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_pro_iframe.php @@ -0,0 +1,771 @@ +<?php +class ControllerExtensionPaymentPPProIframe extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_pro_iframe'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_pro_iframe', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } else { + $data['error'] = @$this->error; + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_pro_iframe_sig'])) { + $data['payment_pp_pro_iframe_sig'] = $this->request->post['payment_pp_pro_iframe_sig']; + } else { + $data['payment_pp_pro_iframe_sig'] = $this->config->get('payment_pp_pro_iframe_sig'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_user'])) { + $data['payment_pp_pro_iframe_user'] = $this->request->post['payment_pp_pro_iframe_user']; + } else { + $data['payment_pp_pro_iframe_user'] = $this->config->get('payment_pp_pro_iframe_user'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_password'])) { + $data['payment_pp_pro_iframe_password'] = $this->request->post['payment_pp_pro_iframe_password']; + } else { + $data['payment_pp_pro_iframe_password'] = $this->config->get('payment_pp_pro_iframe_password'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_transaction_method'])) { + $data['payment_pp_pro_iframe_transaction_method'] = $this->request->post['payment_pp_pro_iframe_transaction_method']; + } else { + $data['payment_pp_pro_iframe_transaction_method'] = $this->config->get('payment_pp_pro_iframe_transaction_method'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_test'])) { + $data['payment_pp_pro_iframe_test'] = $this->request->post['payment_pp_pro_iframe_test']; + } else { + $data['payment_pp_pro_iframe_test'] = $this->config->get('payment_pp_pro_iframe_test'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_total'])) { + $data['payment_pp_pro_iframe_total'] = $this->request->post['payment_pp_pro_iframe_total']; + } else { + $data['payment_pp_pro_iframe_total'] = $this->config->get('payment_pp_pro_iframe_total'); + } + + $this->load->model('localisation/order_status'); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_pro_iframe_canceled_reversal_status_id'])) { + $data['payment_pp_pro_iframe_canceled_reversal_status_id'] = $this->request->post['payment_pp_pro_iframe_canceled_reversal_status_id']; + } else { + $data['payment_pp_pro_iframe_canceled_reversal_status_id'] = $this->config->get('payment_pp_pro_iframe_canceled_reversal_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_completed_status_id'])) { + $data['payment_pp_pro_iframe_completed_status_id'] = $this->request->post['payment_pp_pro_iframe_completed_status_id']; + } else { + $data['payment_pp_pro_iframe_completed_status_id'] = $this->config->get('payment_pp_pro_iframe_completed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_denied_status_id'])) { + $data['payment_pp_pro_iframe_denied_status_id'] = $this->request->post['payment_pp_pro_iframe_denied_status_id']; + } else { + $data['payment_pp_pro_iframe_denied_status_id'] = $this->config->get('payment_pp_pro_iframe_denied_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_expired_status_id'])) { + $data['payment_pp_pro_iframe_expired_status_id'] = $this->request->post['payment_pp_pro_iframe_expired_status_id']; + } else { + $data['payment_pp_pro_iframe_expired_status_id'] = $this->config->get('payment_pp_pro_iframe_expired_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_failed_status_id'])) { + $data['payment_pp_pro_iframe_failed_status_id'] = $this->request->post['payment_pp_pro_iframe_failed_status_id']; + } else { + $data['payment_pp_pro_iframe_failed_status_id'] = $this->config->get('payment_pp_pro_iframe_failed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_pending_status_id'])) { + $data['payment_pp_pro_iframe_pending_status_id'] = $this->request->post['payment_pp_pro_iframe_pending_status_id']; + } else { + $data['payment_pp_pro_iframe_pending_status_id'] = $this->config->get('payment_pp_pro_iframe_pending_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_processed_status_id'])) { + $data['payment_pp_pro_iframe_processed_status_id'] = $this->request->post['payment_pp_pro_iframe_processed_status_id']; + } else { + $data['payment_pp_pro_iframe_processed_status_id'] = $this->config->get('payment_pp_pro_iframe_processed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_processed_status_id'])) { + $data['payment_pp_pro_iframe_processed_status_id'] = $this->request->post['payment_pp_pro_iframe_processed_status_id']; + } else { + $data['payment_pp_pro_iframe_processed_status_id'] = $this->config->get('payment_pp_pro_iframe_processed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_reversed_status_id'])) { + $data['payment_pp_pro_iframe_reversed_status_id'] = $this->request->post['payment_pp_pro_iframe_reversed_status_id']; + } else { + $data['payment_pp_pro_iframe_reversed_status_id'] = $this->config->get('payment_pp_pro_iframe_reversed_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_voided_status_id'])) { + $data['payment_pp_pro_iframe_voided_status_id'] = $this->request->post['payment_pp_pro_iframe_voided_status_id']; + } else { + $data['payment_pp_pro_iframe_voided_status_id'] = $this->config->get('payment_pp_pro_iframe_voided_status_id'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_geo_zone_id'])) { + $data['payment_pp_pro_iframe_geo_zone_id'] = $this->request->post['payment_pp_pro_iframe_geo_zone_id']; + } else { + $data['payment_pp_pro_iframe_geo_zone_id'] = $this->config->get('payment_pp_pro_iframe_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_pro_iframe_status'])) { + $data['payment_pp_pro_iframe_status'] = $this->request->post['payment_pp_pro_iframe_status']; + } else { + $data['payment_pp_pro_iframe_status'] = $this->config->get('payment_pp_pro_iframe_status'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_sort_order'])) { + $data['payment_pp_pro_iframe_sort_order'] = $this->request->post['payment_pp_pro_iframe_sort_order']; + } else { + $data['payment_pp_pro_iframe_sort_order'] = $this->config->get('payment_pp_pro_iframe_sort_order'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_checkout_method'])) { + $data['payment_pp_pro_iframe_checkout_method'] = $this->request->post['payment_pp_pro_iframe_checkout_method']; + } else { + $data['payment_pp_pro_iframe_checkout_method'] = $this->config->get('payment_pp_pro_iframe_checkout_method'); + } + + if (isset($this->request->post['payment_pp_pro_iframe_debug'])) { + $data['payment_pp_pro_iframe_debug'] = $this->request->post['payment_pp_pro_iframe_debug']; + } else { + $data['payment_pp_pro_iframe_debug'] = $this->config->get('payment_pp_pro_iframe_debug'); + } + + $data['ipn_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/pp_pro_iframe/notify'; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_pro_iframe', $data)); + } + + public function install() { + $this->load->model('extension/payment/pp_pro_iframe'); + + $this->model_extension_payment_pp_pro_iframe->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/pp_pro_iframe'); + + $this->model_extension_payment_pp_pro_iframe->uninstall(); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_pro_iframe')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_pro_iframe_sig']) { + $this->error['sig'] = $this->language->get('error_sig'); + } + + if (!$this->request->post['payment_pp_pro_iframe_user']) { + $this->error['user'] = $this->language->get('error_user'); + } + + if (!$this->request->post['payment_pp_pro_iframe_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + return !$this->error; + } + + public function order() { + $this->load->model('extension/payment/pp_pro_iframe'); + $this->load->language('extension/payment/pp_pro_iframe'); + + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->get['order_id']); + + if ($paypal_order) { + $data['paypal_order'] = $paypal_order; + + $data['user_token'] = $this->session->data['user_token']; + + $data['order_id'] = $this->request->get['order_id']; + + $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($data['paypal_order']['paypal_iframe_order_id']), 2); + $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($data['paypal_order']['paypal_iframe_order_id']), 2); + + $data['paypal_order']['captured'] = $captured; + $data['paypal_order']['refunded'] = $refunded; + $data['paypal_order']['remaining'] = number_format($data['paypal_order']['total'] - $captured, 2); + + $data['transactions'] = array(); + + $data['view_link'] = $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'], true); + $data['refund_link'] = $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'], true); + $data['resend_link'] = $this->url->link('extension/payment/pp_pro_iframe/resend', 'user_token=' . $this->session->data['user_token'], true); + + $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($paypal_order['paypal_iframe_order_id']), 2); + $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($paypal_order['paypal_iframe_order_id']), 2); + + $data['paypal_order'] = $paypal_order; + + $data['paypal_order']['captured'] = $captured; + $data['paypal_order']['refunded'] = $refunded; + $data['paypal_order']['remaining'] = number_format($paypal_order['total'] - $captured, 2); + + foreach ($paypal_order['transactions'] as $transaction) { + $data['transactions'][] = array( + 'paypal_iframe_order_transaction_id' => $transaction['paypal_iframe_order_transaction_id'], + 'transaction_id' => $transaction['transaction_id'], + 'amount' => $transaction['amount'], + 'date_added' => $transaction['date_added'], + 'payment_type' => $transaction['payment_type'], + 'payment_status' => $transaction['payment_status'], + 'pending_reason' => $transaction['pending_reason'], + 'view' => $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'] . "&transaction_id=" . $transaction['transaction_id'] . '&order_id=' . $this->request->get['order_id'], true), + 'refund' => $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . "&transaction_id=" . $transaction['transaction_id'] . "&order_id=" . $this->request->get['order_id'], true), + 'resend' => $this->url->link('extension/payment/pp_pro_iframe/resend', 'user_token=' . $this->session->data['user_token'] . "&paypal_iframe_order_transaction_id=" . $transaction['paypal_iframe_order_transaction_id'], true), + ); + } + + $data['reauthorise_link'] = $this->url->link('extension/payment/pp_pro_iframe/reauthorise', 'user_token=' . $this->session->data['user_token'], true); + + return $this->load->view('extension/payment/pp_pro_iframe_order', $data); + } + } + + public function refund() { + $this->load->language('extension/payment/pp_pro_iframe'); + $this->load->model('extension/payment/pp_pro_iframe'); + + $this->document->setTitle($this->language->get('text_refund')); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_refund'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'], true) + ); + + //button actions + $data['action'] = $this->url->link('extension/payment/pp_pro_iframe/doRefund', 'user_token=' . $this->session->data['user_token'], true); + + if (isset($this->request->get['order_id'])) { + $data['cancel'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true); + } else { + $data['cancel'] = ''; + } + + $data['transaction_id'] = $this->request->get['transaction_id']; + + $pp_transaction = $this->model_extension_payment_pp_pro_iframe->getTransaction($this->request->get['transaction_id']); + + $data['amount_original'] = $pp_transaction['AMT']; + $data['currency_code'] = $pp_transaction['CURRENCYCODE']; + + $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefundedTransaction($this->request->get['transaction_id']), 2); + + if ($refunded != 0.00) { + $data['refund_available'] = number_format($data['amount_original'] + $refunded, 2); + $data['attention'] = $this->language->get('text_current_refunds') . ': ' . $data['refund_available']; + } else { + $data['refund_available'] = ''; + $data['attention'] = ''; + } + + $data['user_token'] = $this->session->data['user_token']; + + if (isset($this->session->data['error'])) { + $data['error'] = $this->session->data['error']; + unset($this->session->data['error']); + } else { + $data['error'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_pro_iframe_refund', $data)); + } + + public function doRefund() { + /** + * used to issue a refund for a captured payment + * + * refund can be full or partial + */ + if (isset($this->request->post['transaction_id']) && isset($this->request->post['refund_full'])) { + + $this->load->model('extension/payment/pp_pro_iframe'); + $this->load->language('extension/payment/pp_pro_iframe'); + + if ($this->request->post['refund_full'] == 0 && $this->request->post['amount'] == 0) { + $this->session->data['error'] = $this->language->get('error_capture'); + $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } else { + $order_id = $this->model_extension_payment_pp_pro_iframe->getOrderId($this->request->post['transaction_id']); + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($order_id); + + if ($paypal_order) { + $call_data = array(); + $call_data['METHOD'] = 'RefundTransaction'; + $call_data['TRANSACTIONID'] = $this->request->post['transaction_id']; + $call_data['NOTE'] = urlencode($this->request->post['refund_message']); + $call_data['MSGSUBID'] = uniqid(mt_rand(), true); + + $current_transaction = $this->model_extension_payment_pp_pro_iframe->getLocalTransaction($this->request->post['transaction_id']); + + if ($this->request->post['refund_full'] == 1) { + $call_data['REFUNDTYPE'] = 'Full'; + } else { + $call_data['REFUNDTYPE'] = 'Partial'; + $call_data['AMT'] = number_format($this->request->post['amount'], 2); + $call_data['CURRENCYCODE'] = $this->request->post['currency_code']; + } + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + $transaction = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $this->request->post['transaction_id'], + 'note' => $this->request->post['refund_message'], + 'msgsubid' => $call_data['MSGSUBID'], + 'receipt_id' => '', + 'payment_type' => '', + 'payment_status' => 'Refunded', + 'transaction_entity' => 'payment', + 'pending_reason' => '', + 'amount' => '-' . (isset($call_data['AMT']) ? $call_data['AMT'] : $current_transaction['amount']), + 'debug_data' => json_encode($result) + ); + + if ($result == false) { + $transaction['payment_status'] = 'Failed'; + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction, $call_data); + $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true)); + } else if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + + $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID']; + $transaction['payment_type'] = $result['REFUNDSTATUS']; + $transaction['pending_reason'] = $result['PENDINGREASON']; + $transaction['amount'] = '-' . $result['GROSSREFUNDAMT']; + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction); + + if ($result['TOTALREFUNDEDAMOUNT'] == $this->request->post['amount_original']) { + $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($this->request->post['transaction_id'], 'Refunded'); + } else { + $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($this->request->post['transaction_id'], 'Partially-Refunded'); + } + + //redirect back to the order + $this->response->redirect($this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $paypal_order['order_id'], true)); + } else { + if ($this->config->get('payment_pp_pro_iframe_debug')) { + $log = new Log('pp_pro_iframe.log'); + $log->write(json_encode($result)); + } + + $this->session->data['error'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error') . (isset($result['L_LONGMESSAGE0']) ? '<br />' . $result['L_LONGMESSAGE0'] : ''); + $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } else { + $this->session->data['error'] = $this->language->get('error_data_missing'); + $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } + } else { + $this->session->data['error'] = $this->language->get('error_data'); + $this->response->redirect($this->url->link('extension/payment/pp_pro_iframe/refund', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->post['transaction_id'], true)); + } + } + + public function reauthorise() { + $this->load->language('extension/payment/pp_pro_iframe'); + $this->load->model('extension/payment/pp_pro_iframe'); + + $json = array(); + + if (isset($this->request->post['order_id'])) { + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']); + + $call_data = array(); + $call_data['METHOD'] = 'DoReauthorization'; + $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id']; + $call_data['AMT'] = number_format($paypal_order['total'], 2); + $call_data['CURRENCYCODE'] = $paypal_order['currency_code']; + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + $this->model_extension_payment_pp_pro_iframe->updateAuthorizationId($paypal_order['paypal_iframe_order_id'], $result['AUTHORIZATIONID']); + + $transaction = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_order['authorization_id'], + 'note' => '', + 'msgsubid' => '', + 'receipt_id' => '', + 'payment_type' => 'instant', + 'payment_status' => $result['PAYMENTSTATUS'], + 'transaction_entity' => 'auth', + 'pending_reason' => $result['PENDINGREASON'], + 'amount' => '-' . '', + 'debug_data' => json_encode($result) + ); + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction); + + $transaction['date_added'] = date("Y-m-d H:i:s"); + + $json['data'] = $transaction; + $json['error'] = false; + $json['msg'] = 'Ok'; + } else { + $json['error'] = true; + $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : $this->language->get('error_general')); + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function info() { + $this->load->model('extension/payment/pp_pro_iframe'); + $this->load->language('extension/payment/pp_pro_iframe'); + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_transaction'), + 'href' => $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'] . '&transaction_id=' . $this->request->get['transaction_id'], true) + ); + + $transaction = $this->model_extension_payment_pp_pro_iframe->getTransaction($this->request->get['transaction_id']); + $transaction = array_map('urldecode', $transaction); + + $data['transaction'] = $transaction; + $data['view_link'] = $this->url->link('extension/payment/pp_pro_iframe/info', 'user_token=' . $this->session->data['user_token'], true); + $data['user_token'] = $this->session->data['user_token']; + + $this->document->setTitle($this->language->get('text_transaction')); + + if (isset($this->request->get['order_id'])) { + $data['back'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'], true); + } else { + $data['back'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_pro_iframe_transaction', $data)); + } + + public function capture() { + $this->load->language('extension/payment/pp_pro_iframe'); + /* + * used to capture authorised payments + * capture can be full or partial amounts + */ + if (isset($this->request->post['order_id']) && $this->request->post['amount'] > 0 && isset($this->request->post['order_id']) && isset($this->request->post['complete'])) { + + $this->load->model('extension/payment/pp_pro_iframe'); + + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']); + + if ($this->request->post['complete'] == 1) { + $complete = 'Complete'; + } else { + $complete = 'NotComplete'; + } + + $call_data = array(); + $call_data['METHOD'] = 'DoCapture'; + $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id']; + $call_data['AMT'] = number_format($this->request->post['amount'], 2); + $call_data['CURRENCYCODE'] = $paypal_order['currency_code']; + $call_data['COMPLETETYPE'] = $complete; + $call_data['MSGSUBID'] = uniqid(mt_rand(), true); + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + $transaction = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_order['authorization_id'], + 'note' => '', + 'msgsubid' => $call_data['MSGSUBID'], + 'receipt_id' => '', + 'payment_type' => '', + 'payment_status' => '', + 'pending_reason' => '', + 'transaction_entity' => 'payment', + 'amount' => '', + 'debug_data' => json_encode($result) + ); + + if ($result == false) { + $transaction['amount'] = number_format($this->request->post['amount'], 2); + $paypal_iframe_order_transaction_id = $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction, $call_data); + + $json['error'] = true; + + $json['failed_transaction']['paypal_iframe_order_transaction_id'] = $paypal_iframe_order_transaction_id; + $json['failed_transaction']['amount'] = $transaction['amount']; + $json['failed_transaction']['date_added'] = date("Y-m-d H:i:s"); + + $json['msg'] = $this->language->get('error_timeout'); + } else if (isset($result['ACK']) && $result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + $transaction['transaction_id'] = $result['TRANSACTIONID']; + $transaction['payment_type'] = $result['PAYMENTTYPE']; + $transaction['payment_status'] = $result['PAYMENTSTATUS']; + $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : ''); + $transaction['amount'] = $result['AMT']; + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction); + + unset($transaction['debug_data']); + $transaction['date_added'] = date("Y-m-d H:i:s"); + + $captured = number_format($this->model_extension_payment_pp_pro_iframe->getTotalCaptured($paypal_order['paypal_iframe_order_id']), 2); + $refunded = number_format($this->model_extension_payment_pp_pro_iframe->getTotalRefunded($paypal_order['paypal_iframe_order_id']), 2); + + $transaction['captured'] = $captured; + $transaction['refunded'] = $refunded; + $transaction['remaining'] = number_format($paypal_order['total'] - $captured, 2); + + $transaction['status'] = 0; + if ($transaction['remaining'] == 0.00) { + $transaction['status'] = 1; + $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']); + } + + $transaction['void'] = ''; + + if ($this->request->post['complete'] == 1 && $transaction['remaining'] > 0) { + $transaction['void'] = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_order['authorization_id'], + 'note' => '', + 'msgsubid' => '', + 'receipt_id' => '', + 'payment_type' => '', + 'payment_status' => 'Void', + 'pending_reason' => '', + 'amount' => '', + 'debug_data' => 'Voided after capture', + 'transaction_entity' => 'auth', + ); + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction['void']); + $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']); + $transaction['void']['date_added'] = date("Y-m-d H:i:s"); + $transaction['status'] = 1; + } + + $json['data'] = $transaction; + $json['error'] = false; + $json['msg'] = 'Ok'; + } else { + $json['error'] = true; + $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : 'There was an error'); + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function void() { + $this->load->language('extension/payment/pp_pro_iframe'); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/pp_pro_iframe'); + + $paypal_order = $this->model_extension_payment_pp_pro_iframe->getOrder($this->request->post['order_id']); + + $call_data = array(); + $call_data['METHOD'] = 'DoVoid'; + $call_data['AUTHORIZATIONID'] = $paypal_order['authorization_id']; + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + if ($result['ACK'] != 'Failure' && $result['ACK'] != 'FailureWithWarning') { + $transaction = array( + 'paypal_iframe_order_id' => $paypal_order['paypal_iframe_order_id'], + 'transaction_id' => '', + 'parent_id' => $paypal_order['authorization_id'], + 'note' => '', + 'msgsubid' => '', + 'receipt_id' => '', + 'payment_type' => 'void', + 'payment_status' => 'Void', + 'pending_reason' => '', + 'transaction_entity' => 'auth', + 'amount' => '', + 'debug_data' => json_encode($result) + ); + + $this->model_extension_payment_pp_pro_iframe->addTransaction($transaction); + $this->model_extension_payment_pp_pro_iframe->updateOrder('Complete', $this->request->post['order_id']); + + unset($transaction['debug_data']); + $transaction['date_added'] = date("Y-m-d H:i:s"); + + $json['data'] = $transaction; + $json['error'] = false; + $json['msg'] = 'Transaction void'; + } else { + $json['error'] = true; + $json['msg'] = (isset($result['L_SHORTMESSAGE0']) ? $result['L_SHORTMESSAGE0'] : $this->language->get('error_general')); + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function resend() { + $this->load->model('extension/payment/pp_pro_iframe'); + $this->load->language('extension/payment/pp_pro_iframe'); + + $json = array(); + + if (isset($this->request->get['paypal_iframe_order_transaction_id'])) { + $transaction = $this->model_extension_payment_pp_pro_iframe->getFailedTransaction($this->request->get['paypal_iframe_order_transaction_id']); + + if ($transaction) { + $call_data = json_decode($transaction['call_data'], true); + + $result = $this->model_extension_payment_pp_pro_iframe->call($call_data); + + if ($result) { + $parent_transaction = $this->model_extension_payment_pp_pro_iframe->getLocalTransaction($transaction['parent_id']); + + if ($parent_transaction['amount'] == abs($transaction['amount'])) { + $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($transaction['parent_id'], 'Refunded'); + } else { + $this->model_extension_payment_pp_pro_iframe->updateRefundTransaction($transaction['parent_id'], 'Partially-Refunded'); + } + + if (isset($result['REFUNDTRANSACTIONID'])) { + $transaction['transaction_id'] = $result['REFUNDTRANSACTIONID']; + } else { + $transaction['transaction_id'] = $result['TRANSACTIONID']; + } + + if (isset($result['PAYMENTTYPE'])) { + $transaction['payment_type'] = $result['PAYMENTTYPE']; + } else { + $transaction['payment_type'] = $result['REFUNDSTATUS']; + } + + if (isset($result['PAYMENTSTATUS'])) { + $transaction['payment_status'] = $result['PAYMENTSTATUS']; + } else { + $transaction['payment_status'] = 'Refunded'; + } + + if (isset($result['AMT'])) { + $transaction['amount'] = $result['AMT']; + } else { + $transaction['amount'] = $transaction['amount']; + } + + $transaction['pending_reason'] = (isset($result['PENDINGREASON']) ? $result['PENDINGREASON'] : ''); + + $this->model_extension_payment_pp_pro_iframe->updateTransaction($transaction); + + $json['success'] = $this->language->get('success_transaction_resent'); + } else { + $json['error'] = $this->language->get('error_timeout'); + } + } else { + $json['error'] = $this->language->get('error_transaction_missing'); + } + } else { + $json['error'] = $this->language->get('error_missing_data'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/pp_standard.php b/public/admin/controller/extension/payment/pp_standard.php new file mode 100644 index 0000000..ba9acd8 --- /dev/null +++ b/public/admin/controller/extension/payment/pp_standard.php @@ -0,0 +1,187 @@ +<?php +class ControllerExtensionPaymentPPStandard extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/pp_standard'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_pp_standard', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['email'])) { + $data['error_email'] = $this->error['email']; + } else { + $data['error_email'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/pp_standard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/pp_standard', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_pp_standard_email'])) { + $data['payment_pp_standard_email'] = $this->request->post['payment_pp_standard_email']; + } else { + $data['payment_pp_standard_email'] = $this->config->get('payment_pp_standard_email'); + } + + if (isset($this->request->post['payment_pp_standard_test'])) { + $data['payment_pp_standard_test'] = $this->request->post['payment_pp_standard_test']; + } else { + $data['payment_pp_standard_test'] = $this->config->get('payment_pp_standard_test'); + } + + if (isset($this->request->post['payment_pp_standard_transaction'])) { + $data['payment_pp_standard_transaction'] = $this->request->post['payment_pp_standard_transaction']; + } else { + $data['payment_pp_standard_transaction'] = $this->config->get('payment_pp_standard_transaction'); + } + + if (isset($this->request->post['payment_pp_standard_debug'])) { + $data['payment_pp_standard_debug'] = $this->request->post['payment_pp_standard_debug']; + } else { + $data['payment_pp_standard_debug'] = $this->config->get('payment_pp_standard_debug'); + } + + if (isset($this->request->post['payment_pp_standard_total'])) { + $data['payment_pp_standard_total'] = $this->request->post['payment_pp_standard_total']; + } else { + $data['payment_pp_standard_total'] = $this->config->get('payment_pp_standard_total'); + } + + if (isset($this->request->post['payment_pp_standard_canceled_reversal_status_id'])) { + $data['payment_pp_standard_canceled_reversal_status_id'] = $this->request->post['payment_pp_standard_canceled_reversal_status_id']; + } else { + $data['payment_pp_standard_canceled_reversal_status_id'] = $this->config->get('payment_pp_standard_canceled_reversal_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_completed_status_id'])) { + $data['payment_pp_standard_completed_status_id'] = $this->request->post['payment_pp_standard_completed_status_id']; + } else { + $data['payment_pp_standard_completed_status_id'] = $this->config->get('payment_pp_standard_completed_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_denied_status_id'])) { + $data['payment_pp_standard_denied_status_id'] = $this->request->post['payment_pp_standard_denied_status_id']; + } else { + $data['payment_pp_standard_denied_status_id'] = $this->config->get('payment_pp_standard_denied_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_expired_status_id'])) { + $data['payment_pp_standard_expired_status_id'] = $this->request->post['payment_pp_standard_expired_status_id']; + } else { + $data['payment_pp_standard_expired_status_id'] = $this->config->get('payment_pp_standard_expired_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_failed_status_id'])) { + $data['payment_pp_standard_failed_status_id'] = $this->request->post['payment_pp_standard_failed_status_id']; + } else { + $data['payment_pp_standard_failed_status_id'] = $this->config->get('payment_pp_standard_failed_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_pending_status_id'])) { + $data['payment_pp_standard_pending_status_id'] = $this->request->post['payment_pp_standard_pending_status_id']; + } else { + $data['payment_pp_standard_pending_status_id'] = $this->config->get('payment_pp_standard_pending_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_processed_status_id'])) { + $data['payment_pp_standard_processed_status_id'] = $this->request->post['payment_pp_standard_processed_status_id']; + } else { + $data['payment_pp_standard_processed_status_id'] = $this->config->get('payment_pp_standard_processed_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_refunded_status_id'])) { + $data['payment_pp_standard_refunded_status_id'] = $this->request->post['payment_pp_standard_refunded_status_id']; + } else { + $data['payment_pp_standard_refunded_status_id'] = $this->config->get('payment_pp_standard_refunded_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_reversed_status_id'])) { + $data['payment_pp_standard_reversed_status_id'] = $this->request->post['payment_pp_standard_reversed_status_id']; + } else { + $data['payment_pp_standard_reversed_status_id'] = $this->config->get('payment_pp_standard_reversed_status_id'); + } + + if (isset($this->request->post['payment_pp_standard_voided_status_id'])) { + $data['payment_pp_standard_voided_status_id'] = $this->request->post['payment_pp_standard_voided_status_id']; + } else { + $data['payment_pp_standard_voided_status_id'] = $this->config->get('payment_pp_standard_voided_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_pp_standard_geo_zone_id'])) { + $data['payment_pp_standard_geo_zone_id'] = $this->request->post['payment_pp_standard_geo_zone_id']; + } else { + $data['payment_pp_standard_geo_zone_id'] = $this->config->get('payment_pp_standard_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_pp_standard_status'])) { + $data['payment_pp_standard_status'] = $this->request->post['payment_pp_standard_status']; + } else { + $data['payment_pp_standard_status'] = $this->config->get('payment_pp_standard_status'); + } + + if (isset($this->request->post['payment_pp_standard_sort_order'])) { + $data['payment_pp_standard_sort_order'] = $this->request->post['payment_pp_standard_sort_order']; + } else { + $data['payment_pp_standard_sort_order'] = $this->config->get('payment_pp_standard_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/pp_standard', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/pp_standard')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_pp_standard_email']) { + $this->error['email'] = $this->language->get('error_email'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/realex.php b/public/admin/controller/extension/payment/realex.php new file mode 100644 index 0000000..e9c7547 --- /dev/null +++ b/public/admin/controller/extension/payment/realex.php @@ -0,0 +1,408 @@ +<?php +class ControllerExtensionPaymentRealex extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/realex'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_realex', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + $data['notify_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/realex/notify'; + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + if (isset($this->error['error_live_url'])) { + $data['error_live_url'] = $this->error['error_live_url']; + } else { + $data['error_live_url'] = ''; + } + + if (isset($this->error['error_demo_url'])) { + $data['error_demo_url'] = $this->error['error_demo_url']; + } else { + $data['error_demo_url'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/realex', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/realex', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_realex_merchant_id'])) { + $data['payment_realex_merchant_id'] = $this->request->post['payment_realex_merchant_id']; + } else { + $data['payment_realex_merchant_id'] = $this->config->get('payment_realex_merchant_id'); + } + + if (isset($this->request->post['payment_realex_secret'])) { + $data['payment_realex_secret'] = $this->request->post['payment_realex_secret']; + } else { + $data['payment_realex_secret'] = $this->config->get('payment_realex_secret'); + } + + if (isset($this->request->post['payment_realex_rebate_password'])) { + $data['payment_realex_rebate_password'] = $this->request->post['payment_realex_rebate_password']; + } else { + $data['payment_realex_rebate_password'] = $this->config->get('payment_realex_rebate_password'); + } + + if (isset($this->request->post['payment_realex_live_demo'])) { + $data['payment_realex_live_demo'] = $this->request->post['payment_realex_live_demo']; + } else { + $data['payment_realex_live_demo'] = $this->config->get('payment_realex_live_demo'); + } + + if (isset($this->request->post['payment_realex_geo_zone_id'])) { + $data['payment_realex_geo_zone_id'] = $this->request->post['payment_realex_geo_zone_id']; + } else { + $data['payment_realex_geo_zone_id'] = $this->config->get('payment_realex_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_realex_total'])) { + $data['payment_realex_total'] = $this->request->post['payment_realex_total']; + } else { + $data['payment_realex_total'] = $this->config->get('payment_realex_total'); + } + + if (isset($this->request->post['payment_realex_sort_order'])) { + $data['payment_realex_sort_order'] = $this->request->post['payment_realex_sort_order']; + } else { + $data['payment_realex_sort_order'] = $this->config->get('payment_realex_sort_order'); + } + + if (isset($this->request->post['payment_realex_status'])) { + $data['payment_realex_status'] = $this->request->post['payment_realex_status']; + } else { + $data['payment_realex_status'] = $this->config->get('payment_realex_status'); + } + + if (isset($this->request->post['payment_realex_debug'])) { + $data['payment_realex_debug'] = $this->request->post['payment_realex_debug']; + } else { + $data['payment_realex_debug'] = $this->config->get('payment_realex_debug'); + } + + if (isset($this->request->post['payment_realex_account'])) { + $data['payment_realex_account'] = $this->request->post['payment_realex_account']; + } else { + $data['payment_realex_account'] = $this->config->get('payment_realex_account'); + } + + if (isset($this->request->post['payment_realex_auto_settle'])) { + $data['payment_realex_auto_settle'] = $this->request->post['payment_realex_auto_settle']; + } else { + $data['payment_realex_auto_settle'] = $this->config->get('payment_realex_auto_settle'); + } + + if (isset($this->request->post['payment_realex_card_select'])) { + $data['payment_realex_card_select'] = $this->request->post['payment_realex_card_select']; + } else { + $data['payment_realex_card_select'] = $this->config->get('payment_realex_card_select'); + } + + if (isset($this->request->post['payment_realex_tss_check'])) { + $data['payment_realex_tss_check'] = $this->request->post['payment_realex_tss_check']; + } else { + $data['payment_realex_tss_check'] = $this->config->get('payment_realex_tss_check'); + } + + if (isset($this->request->post['payment_realex_order_status_success_settled_id'])) { + $data['payment_realex_order_status_success_settled_id'] = $this->request->post['payment_realex_order_status_success_settled_id']; + } else { + $data['payment_realex_order_status_success_settled_id'] = $this->config->get('payment_realex_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_realex_order_status_success_unsettled_id'])) { + $data['payment_realex_order_status_success_unsettled_id'] = $this->request->post['payment_realex_order_status_success_unsettled_id']; + } else { + $data['payment_realex_order_status_success_unsettled_id'] = $this->config->get('payment_realex_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_realex_order_status_decline_id'])) { + $data['payment_realex_order_status_decline_id'] = $this->request->post['payment_realex_order_status_decline_id']; + } else { + $data['payment_realex_order_status_decline_id'] = $this->config->get('payment_realex_order_status_decline_id'); + } + + if (isset($this->request->post['payment_realex_order_status_decline_pending_id'])) { + $data['payment_realex_order_status_decline_pending_id'] = $this->request->post['payment_realex_order_status_decline_pending_id']; + } else { + $data['payment_realex_order_status_decline_pending_id'] = $this->config->get('payment_realex_order_status_decline_pending_id'); + } + + if (isset($this->request->post['payment_realex_order_status_decline_stolen_id'])) { + $data['payment_realex_order_status_decline_stolen_id'] = $this->request->post['payment_realex_order_status_decline_stolen_id']; + } else { + $data['payment_realex_order_status_decline_stolen_id'] = $this->config->get('payment_realex_order_status_decline_stolen_id'); + } + + if (isset($this->request->post['payment_realex_order_status_decline_bank_id'])) { + $data['payment_realex_order_status_decline_bank_id'] = $this->request->post['payment_realex_order_status_decline_bank_id']; + } else { + $data['payment_realex_order_status_decline_bank_id'] = $this->config->get('payment_realex_order_status_decline_bank_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_realex_live_url'])) { + $data['payment_realex_live_url'] = $this->request->post['payment_realex_live_url']; + } else { + $data['payment_realex_live_url'] = $this->config->get('payment_realex_live_url'); + } + + if (empty($data['payment_realex_live_url'])) { + $data['payment_realex_live_url'] = 'https://hpp.realexpayments.com/pay'; + } + + if (isset($this->request->post['payment_realex_demo_url'])) { + $data['payment_realex_demo_url'] = $this->request->post['payment_realex_demo_url']; + } else { + $data['payment_realex_demo_url'] = $this->config->get('payment_realex_demo_url'); + } + + if (empty($data['payment_realex_demo_url'])) { + $data['payment_realex_demo_url'] = 'https://hpp.sandbox.realexpayments.com/pay'; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/realex', $data)); + } + + public function install() { + $this->load->model('extension/payment/realex'); + + $this->model_extension_payment_realex->install(); + } + + public function order() { + if ($this->config->get('payment_realex_status')) { + $this->load->model('extension/payment/realex'); + + $realex_order = $this->model_extension_payment_realex->getOrder($this->request->get['order_id']); + + if (!empty($realex_order)) { + $this->load->language('extension/payment/realex'); + + $realex_order['total_captured'] = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']); + + $realex_order['total_formatted'] = $this->currency->format($realex_order['total'], $realex_order['currency_code'], 1, true); + $realex_order['total_captured_formatted'] = $this->currency->format($realex_order['total_captured'], $realex_order['currency_code'], 1, true); + + $data['realex_order'] = $realex_order; + + $data['auto_settle'] = $realex_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/realex_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/realex'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/realex'); + + $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_realex->void($this->request->post['order_id']); + + $this->model_extension_payment_realex->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (isset($void_response->result) && $void_response->result == '00') { + $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'void', 0.00); + $this->model_extension_payment_realex->updateVoidStatus($realex_order['realex_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/realex'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/realex'); + + $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_realex->capture($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_realex->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (isset($capture_response->result) && $capture_response->result == '00') { + $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'payment', $this->request->post['amount']); + + $total_captured = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']); + + if ($total_captured >= $realex_order['total'] || $realex_order['settle_type'] == 0) { + $this->model_extension_payment_realex->updateCaptureStatus($realex_order['realex_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $this->model_extension_payment_realex->updateForRebate($realex_order['realex_order_id'], $capture_response->pasref, $capture_response->orderid); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/realex'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/realex'); + + $realex_order = $this->model_extension_payment_realex->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_realex->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_realex->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if (isset($rebate_response->result) && $rebate_response->result == '00') { + $this->model_extension_payment_realex->addTransaction($realex_order['realex_order_id'], 'rebate', $this->request->post['amount']*-1); + + $total_rebated = $this->model_extension_payment_realex->getTotalRebated($realex_order['realex_order_id']); + $total_captured = $this->model_extension_payment_realex->getTotalCaptured($realex_order['realex_order_id']); + + if ($total_captured <= 0 && $realex_order['capture_status'] == 1) { + $this->model_extension_payment_realex->updateRebateStatus($realex_order['realex_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']*-1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/realex')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_realex_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_realex_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + if (!$this->request->post['payment_realex_live_url']) { + $this->error['error_live_url'] = $this->language->get('error_live_url'); + } + + if (!$this->request->post['payment_realex_demo_url']) { + $this->error['error_demo_url'] = $this->language->get('error_demo_url'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/realex_remote.php b/public/admin/controller/extension/payment/realex_remote.php new file mode 100644 index 0000000..43e9e5a --- /dev/null +++ b/public/admin/controller/extension/payment/realex_remote.php @@ -0,0 +1,371 @@ +<?php +class ControllerExtensionPaymentRealexRemote extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/realex_remote'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_realex_remote', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['error_merchant_id'])) { + $data['error_merchant_id'] = $this->error['error_merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['error_secret'])) { + $data['error_secret'] = $this->error['error_secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/realex_remote', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/realex_remote', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_realex_remote_merchant_id'])) { + $data['payment_realex_remote_merchant_id'] = $this->request->post['payment_realex_remote_merchant_id']; + } else { + $data['payment_realex_remote_merchant_id'] = $this->config->get('payment_realex_remote_merchant_id'); + } + + if (isset($this->request->post['payment_realex_remote_secret'])) { + $data['payment_realex_remote_secret'] = $this->request->post['payment_realex_remote_secret']; + } else { + $data['payment_realex_remote_secret'] = $this->config->get('payment_realex_remote_secret'); + } + + if (isset($this->request->post['payment_realex_remote_rebate_password'])) { + $data['payment_realex_remote_rebate_password'] = $this->request->post['payment_realex_remote_rebate_password']; + } else { + $data['payment_realex_remote_rebate_password'] = $this->config->get('payment_realex_remote_rebate_password'); + } + + if (isset($this->request->post['payment_realex_remote_geo_zone_id'])) { + $data['payment_realex_remote_geo_zone_id'] = $this->request->post['payment_realex_remote_geo_zone_id']; + } else { + $data['payment_realex_remote_geo_zone_id'] = $this->config->get('payment_realex_remote_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_realex_remote_total'])) { + $data['payment_realex_remote_total'] = $this->request->post['payment_realex_remote_total']; + } else { + $data['payment_realex_remote_total'] = $this->config->get('payment_realex_remote_total'); + } + + if (isset($this->request->post['payment_realex_remote_sort_order'])) { + $data['payment_realex_remote_sort_order'] = $this->request->post['payment_realex_remote_sort_order']; + } else { + $data['payment_realex_remote_sort_order'] = $this->config->get('payment_realex_remote_sort_order'); + } + + if (isset($this->request->post['payment_realex_remote_status'])) { + $data['payment_realex_remote_status'] = $this->request->post['payment_realex_remote_status']; + } else { + $data['payment_realex_remote_status'] = $this->config->get('payment_realex_remote_status'); + } + + if (isset($this->request->post['payment_realex_remote_card_data_status'])) { + $data['payment_realex_remote_card_data_status'] = $this->request->post['payment_realex_remote_card_data_status']; + } else { + $data['payment_realex_remote_card_data_status'] = $this->config->get('payment_realex_remote_card_data_status'); + } + + if (isset($this->request->post['payment_realex_remote_debug'])) { + $data['payment_realex_remote_debug'] = $this->request->post['payment_realex_remote_debug']; + } else { + $data['payment_realex_remote_debug'] = $this->config->get('payment_realex_remote_debug'); + } + + if (isset($this->request->post['payment_realex_remote_account'])) { + $data['payment_realex_remote_account'] = $this->request->post['payment_realex_remote_account']; + } else { + $data['payment_realex_remote_account'] = $this->config->get('payment_realex_remote_account'); + } + + if (isset($this->request->post['payment_realex_remote_auto_settle'])) { + $data['payment_realex_remote_auto_settle'] = $this->request->post['payment_realex_remote_auto_settle']; + } else { + $data['payment_realex_remote_auto_settle'] = $this->config->get('payment_realex_remote_auto_settle'); + } + + if (isset($this->request->post['payment_realex_remote_tss_check'])) { + $data['payment_realex_remote_tss_check'] = $this->request->post['payment_realex_remote_tss_check']; + } else { + $data['payment_realex_remote_tss_check'] = $this->config->get('payment_realex_remote_tss_check'); + } + + if (isset($this->request->post['payment_realex_remote_3d'])) { + $data['payment_realex_remote_3d'] = $this->request->post['payment_realex_remote_3d']; + } else { + $data['payment_realex_remote_3d'] = $this->config->get('payment_realex_remote_3d'); + } + + if (isset($this->request->post['payment_realex_remote_liability'])) { + $data['payment_realex_remote_liability'] = $this->request->post['payment_realex_remote_liability']; + } else { + $data['payment_realex_remote_liability'] = $this->config->get('payment_realex_remote_liability'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_success_settled_id'])) { + $data['payment_realex_remote_order_status_success_settled_id'] = $this->request->post['payment_realex_remote_order_status_success_settled_id']; + } else { + $data['payment_realex_remote_order_status_success_settled_id'] = $this->config->get('payment_realex_remote_order_status_success_settled_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_success_unsettled_id'])) { + $data['payment_realex_remote_order_status_success_unsettled_id'] = $this->request->post['payment_realex_remote_order_status_success_unsettled_id']; + } else { + $data['payment_realex_remote_order_status_success_unsettled_id'] = $this->config->get('payment_realex_remote_order_status_success_unsettled_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_decline_id'])) { + $data['payment_realex_remote_order_status_decline_id'] = $this->request->post['payment_realex_remote_order_status_decline_id']; + } else { + $data['payment_realex_remote_order_status_decline_id'] = $this->config->get('payment_realex_remote_order_status_decline_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_decline_pending_id'])) { + $data['payment_realex_remote_order_status_decline_pending_id'] = $this->request->post['payment_realex_remote_order_status_decline_pending_id']; + } else { + $data['payment_realex_remote_order_status_decline_pending_id'] = $this->config->get('payment_realex_remote_order_status_decline_pending_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_decline_stolen_id'])) { + $data['payment_realex_remote_order_status_decline_stolen_id'] = $this->request->post['payment_realex_remote_order_status_decline_stolen_id']; + } else { + $data['payment_realex_remote_order_status_decline_stolen_id'] = $this->config->get('payment_realex_remote_order_status_decline_stolen_id'); + } + + if (isset($this->request->post['payment_realex_remote_order_status_decline_bank_id'])) { + $data['payment_realex_remote_order_status_decline_bank_id'] = $this->request->post['payment_realex_remote_order_status_decline_bank_id']; + } else { + $data['payment_realex_remote_order_status_decline_bank_id'] = $this->config->get('payment_realex_remote_order_status_decline_bank_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/realex_remote', $data)); + } + + public function install() { + $this->load->model('extension/payment/realex_remote'); + $this->model_extension_payment_realex_remote->install(); + } + + public function order() { + if ($this->config->get('payment_realex_remote_status')) { + $this->load->model('extension/payment/realex_remote'); + + $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->get['order_id']); + + if (!empty($realex_order)) { + $this->load->language('extension/payment/realex_remote'); + + $realex_order['total_captured'] = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']); + + $realex_order['total_formatted'] = $this->currency->format($realex_order['total'], $realex_order['currency_code'], 1, true); + $realex_order['total_captured_formatted'] = $this->currency->format($realex_order['total_captured'], $realex_order['currency_code'], 1, true); + + $data['realex_order'] = $realex_order; + + $data['auto_settle'] = $realex_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/realex_remote_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/realex_remote'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/realex_remote'); + + $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_realex_remote->void($this->request->post['order_id']); + + $this->model_extension_payment_realex_remote->logger('Void result:\r\n' . print_r($void_response, 1)); + + if (isset($void_response->result) && $void_response->result == '00') { + $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'void', 0.00); + $this->model_extension_payment_realex_remote->updateVoidStatus($realex_order['realex_remote_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response->message) && !empty($void_response->message) ? (string)$void_response->message : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function capture() { + $this->load->language('extension/payment/realex'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/realex_remote'); + + $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']); + + $capture_response = $this->model_extension_payment_realex_remote->capture($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_realex_remote->logger('Settle result:\r\n' . print_r($capture_response, 1)); + + if (isset($capture_response->result) && $capture_response->result == '00') { + $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'payment', $this->request->post['amount']); + $total_captured = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']); + + if ($total_captured >= $realex_order['total'] || $realex_order['settle_type'] == 0) { + $this->model_extension_payment_realex_remote->updateCaptureStatus($realex_order['realex_remote_order_id'], 1); + $capture_status = 1; + $json['msg'] = $this->language->get('text_capture_ok_order'); + } else { + $capture_status = 0; + $json['msg'] = $this->language->get('text_capture_ok'); + } + + $this->model_extension_payment_realex_remote->updateForRebate($realex_order['realex_remote_order_id'], $capture_response->pasref, $capture_response->orderid); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = (float)$this->request->post['amount']; + $json['data']['capture_status'] = $capture_status; + $json['data']['total'] = (float)$total_captured; + $json['data']['total_formatted'] = $this->currency->format($total_captured, $realex_order['currency_code'], 1, true); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($capture_response->message) && !empty($capture_response->message) ? (string)$capture_response->message : 'Unable to capture'; + + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/realex_remote'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/realex_remote'); + + $realex_order = $this->model_extension_payment_realex_remote->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_realex_remote->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_realex_remote->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if (isset($rebate_response->result) && $rebate_response->result == '00') { + $this->model_extension_payment_realex_remote->addTransaction($realex_order['realex_remote_order_id'], 'rebate', $this->request->post['amount']*-1); + + $total_rebated = $this->model_extension_payment_realex_remote->getTotalRebated($realex_order['realex_remote_order_id']); + $total_captured = $this->model_extension_payment_realex_remote->getTotalCaptured($realex_order['realex_remote_order_id']); + + if ($total_captured <= 0 && $realex_order['capture_status'] == 1) { + $this->model_extension_payment_realex_remote->updateRebateStatus($realex_order['realex_remote_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_captured'] = (float)$total_captured; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response->message) && !empty($rebate_response->message) ? (string)$rebate_response->message : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/realex_remote')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_realex_remote_merchant_id']) { + $this->error['error_merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_realex_remote_secret']) { + $this->error['error_secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/sagepay_direct.php b/public/admin/controller/extension/payment/sagepay_direct.php new file mode 100644 index 0000000..22c5bbe --- /dev/null +++ b/public/admin/controller/extension/payment/sagepay_direct.php @@ -0,0 +1,327 @@ +<?php +class ControllerExtensionPaymentSagepayDirect extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/sagepay_direct'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_sagepay_direct', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['vendor'])) { + $data['error_vendor'] = $this->error['vendor']; + } else { + $data['error_vendor'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/sagepay_direct', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/sagepay_direct', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_sagepay_direct_vendor'])) { + $data['payment_sagepay_direct_vendor'] = $this->request->post['payment_sagepay_direct_vendor']; + } else { + $data['payment_sagepay_direct_vendor'] = $this->config->get('payment_sagepay_direct_vendor'); + } + + if (isset($this->request->post['payment_sagepay_direct_password'])) { + $data['payment_sagepay_direct_password'] = $this->request->post['payment_sagepay_direct_password']; + } else { + $data['payment_sagepay_direct_password'] = $this->config->get('payment_sagepay_direct_password'); + } + + if (isset($this->request->post['payment_sagepay_direct_test'])) { + $data['payment_sagepay_direct_test'] = $this->request->post['payment_sagepay_direct_test']; + } else { + $data['payment_sagepay_direct_test'] = $this->config->get('payment_sagepay_direct_test'); + } + + if (isset($this->request->post['payment_sagepay_direct_transaction'])) { + $data['payment_sagepay_direct_transaction'] = $this->request->post['payment_sagepay_direct_transaction']; + } else { + $data['payment_sagepay_direct_transaction'] = $this->config->get('payment_sagepay_direct_transaction'); + } + + if (isset($this->request->post['payment_sagepay_direct_total'])) { + $data['payment_sagepay_direct_total'] = $this->request->post['payment_sagepay_direct_total']; + } else { + $data['payment_sagepay_direct_total'] = $this->config->get('payment_sagepay_direct_total'); + } + + if (isset($this->request->post['payment_sagepay_direct_card'])) { + $data['payment_sagepay_direct_card'] = $this->request->post['payment_sagepay_direct_card']; + } else { + $data['payment_sagepay_direct_card'] = $this->config->get('payment_sagepay_direct_card'); + } + + if (isset($this->request->post['payment_sagepay_direct_order_status_id'])) { + $data['payment_sagepay_direct_order_status_id'] = $this->request->post['payment_sagepay_direct_order_status_id']; + } else { + $data['payment_sagepay_direct_order_status_id'] = $this->config->get('payment_sagepay_direct_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_sagepay_direct_geo_zone_id'])) { + $data['payment_sagepay_direct_geo_zone_id'] = $this->request->post['payment_sagepay_direct_geo_zone_id']; + } else { + $data['payment_sagepay_direct_geo_zone_id'] = $this->config->get('payment_sagepay_direct_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_sagepay_direct_status'])) { + $data['payment_sagepay_direct_status'] = $this->request->post['payment_sagepay_direct_status']; + } else { + $data['payment_sagepay_direct_status'] = $this->config->get('payment_sagepay_direct_status'); + } + + if (isset($this->request->post['payment_sagepay_direct_debug'])) { + $data['payment_sagepay_direct_debug'] = $this->request->post['payment_sagepay_direct_debug']; + } else { + $data['payment_sagepay_direct_debug'] = $this->config->get('payment_sagepay_direct_debug'); + } + + if (isset($this->request->post['payment_sagepay_direct_sort_order'])) { + $data['payment_sagepay_direct_sort_order'] = $this->request->post['payment_sagepay_direct_sort_order']; + } else { + $data['payment_sagepay_direct_sort_order'] = $this->config->get('payment_sagepay_direct_sort_order'); + } + + if (isset($this->request->post['payment_sagepay_direct_cron_job_token'])) { + $data['payment_sagepay_direct_cron_job_token'] = $this->request->post['payment_sagepay_direct_cron_job_token']; + } elseif ($this->config->get('payment_sagepay_direct_cron_job_token')) { + $data['payment_sagepay_direct_cron_job_token'] = $this->config->get('payment_sagepay_direct_cron_job_token'); + } else { + $data['payment_sagepay_direct_cron_job_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['sagepay_direct_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/sagepay_direct/cron&token=' . $data['payment_sagepay_direct_cron_job_token']; + + if ($this->config->get('payment_sagepay_direct_last_cron_job_run')) { + $data['payment_sagepay_direct_last_cron_job_run'] = $this->config->get('payment_sagepay_direct_last_cron_job_run'); + } else { + $data['payment_sagepay_direct_last_cron_job_run'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/sagepay_direct', $data)); + } + + public function install() { + $this->load->model('extension/payment/sagepay_direct'); + $this->model_extension_payment_sagepay_direct->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/sagepay_direct'); + $this->model_extension_payment_sagepay_direct->uninstall(); + } + + public function order() { + if ($this->config->get('payment_sagepay_direct_status')) { + $this->load->model('extension/payment/sagepay_direct'); + + $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->get['order_id']); + + if (!empty($sagepay_direct_order)) { + $this->load->language('extension/payment/sagepay_direct'); + + $sagepay_direct_order['total_released'] = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']); + + $sagepay_direct_order['total_formatted'] = $this->currency->format($sagepay_direct_order['total'], $sagepay_direct_order['currency_code'], false, false); + $sagepay_direct_order['total_released_formatted'] = $this->currency->format($sagepay_direct_order['total_released'], $sagepay_direct_order['currency_code'], false, false); + + $data['sagepay_direct_order'] = $sagepay_direct_order; + + $data['auto_settle'] = $sagepay_direct_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/sagepay_direct_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/sagepay_direct'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/sagepay_direct'); + + $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_sagepay_direct->void($this->request->post['order_id']); + + $this->model_extension_payment_sagepay_direct->logger('Void result', $void_response); + + if ($void_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'void', 0.00); + $this->model_extension_payment_sagepay_direct->updateVoidStatus($sagepay_direct_order['sagepay_direct_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['StatuesDetail']) && !empty($void_response['StatuesDetail']) ? (string)$void_response['StatuesDetail'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/sagepay_direct'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/sagepay_direct'); + + $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_sagepay_direct->release($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_sagepay_direct->logger('Release result', $release_response); + + if ($release_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'payment', $this->request->post['amount']); + + $total_released = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']); + + if ($total_released >= $sagepay_direct_order['total'] || $sagepay_direct_order['settle_type'] == 0) { + $this->model_extension_payment_sagepay_direct->updateReleaseStatus($sagepay_direct_order['sagepay_direct_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (float)$total_released; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($release_response['StatusDetail']) && !empty($release_response['StatusDetail']) ? (string)$release_response['StatusDetail'] : 'Unable to release'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/sagepay_direct'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/sagepay_direct'); + + $sagepay_direct_order = $this->model_extension_payment_sagepay_direct->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_sagepay_direct->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_sagepay_direct->logger('Rebate result', $rebate_response); + + if ($rebate_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_direct->addTransaction($sagepay_direct_order['sagepay_direct_order_id'], 'rebate', $this->request->post['amount'] * -1); + + $total_rebated = $this->model_extension_payment_sagepay_direct->getTotalRebated($sagepay_direct_order['sagepay_direct_order_id']); + $total_released = $this->model_extension_payment_sagepay_direct->getTotalReleased($sagepay_direct_order['sagepay_direct_order_id']); + + if ($total_released <= 0 && $sagepay_direct_order['release_status'] == 1) { + $this->model_extension_payment_sagepay_direct->updateRebateStatus($sagepay_direct_order['sagepay_direct_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response['StatusDetail']) && !empty($rebate_response['StatusDetail']) ? (string)$rebate_response['StatusDetail'] : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_direct')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_sagepay_direct_vendor']) { + $this->error['vendor'] = $this->language->get('error_vendor'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/sagepay_server.php b/public/admin/controller/extension/payment/sagepay_server.php new file mode 100644 index 0000000..6bd0427 --- /dev/null +++ b/public/admin/controller/extension/payment/sagepay_server.php @@ -0,0 +1,328 @@ +<?php +class ControllerExtensionPaymentSagepayServer extends Controller { + private $error = array(); + + public function index() { + + $this->load->language('extension/payment/sagepay_server'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_sagepay_server', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['vendor'])) { + $data['error_vendor'] = $this->error['vendor']; + } else { + $data['error_vendor'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/sagepay_server', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/sagepay_server', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_sagepay_server_vendor'])) { + $data['payment_sagepay_server_vendor'] = $this->request->post['payment_sagepay_server_vendor']; + } else { + $data['payment_sagepay_server_vendor'] = $this->config->get('payment_sagepay_server_vendor'); + } + + if (isset($this->request->post['payment_sagepay_server_password'])) { + $data['payment_sagepay_server_password'] = $this->request->post['payment_sagepay_server_password']; + } else { + $data['payment_sagepay_server_password'] = $this->config->get('payment_sagepay_server_password'); + } + + if (isset($this->request->post['payment_sagepay_server_test'])) { + $data['payment_sagepay_server_test'] = $this->request->post['payment_sagepay_server_test']; + } else { + $data['payment_sagepay_server_test'] = $this->config->get('payment_sagepay_server_test'); + } + + if (isset($this->request->post['payment_sagepay_server_transaction'])) { + $data['payment_sagepay_server_transaction'] = $this->request->post['payment_sagepay_server_transaction']; + } else { + $data['payment_sagepay_server_transaction'] = $this->config->get('payment_sagepay_server_transaction'); + } + + if (isset($this->request->post['payment_sagepay_server_total'])) { + $data['payment_sagepay_server_total'] = $this->request->post['payment_sagepay_server_total']; + } else { + $data['payment_sagepay_server_total'] = $this->config->get('payment_sagepay_server_total'); + } + + if (isset($this->request->post['payment_sagepay_server_card'])) { + $data['payment_sagepay_server_card'] = $this->request->post['payment_sagepay_server_card']; + } else { + $data['payment_sagepay_server_card'] = $this->config->get('payment_sagepay_server_card'); + } + + if (isset($this->request->post['payment_sagepay_server_order_status_id'])) { + $data['payment_sagepay_server_order_status_id'] = $this->request->post['payment_sagepay_server_order_status_id']; + } else { + $data['payment_sagepay_server_order_status_id'] = $this->config->get('payment_sagepay_server_order_status_id'); + } + + if (isset($this->request->post['payment_sagepay_server_cron_job_token'])) { + $data['payment_sagepay_server_cron_job_token'] = $this->request->post['payment_sagepay_server_cron_job_token']; + } elseif ($this->config->get('payment_sagepay_server_cron_job_token')) { + $data['payment_sagepay_server_cron_job_token'] = $this->config->get('payment_sagepay_server_cron_job_token'); + } else { + $data['payment_sagepay_server_cron_job_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['sagepay_server_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/sagepay_server/cron&token=' . $data['payment_sagepay_server_cron_job_token']; + + if ($this->config->get('payment_sagepay_server_last_cron_job_run')) { + $data['payment_sagepay_server_last_cron_job_run'] = $this->config->get('payment_sagepay_server_last_cron_job_run'); + } else { + $data['payment_sagepay_server_last_cron_job_run'] = ''; + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_sagepay_server_geo_zone_id'])) { + $data['payment_sagepay_server_geo_zone_id'] = $this->request->post['payment_sagepay_server_geo_zone_id']; + } else { + $data['payment_sagepay_server_geo_zone_id'] = $this->config->get('payment_sagepay_server_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_sagepay_server_status'])) { + $data['payment_sagepay_server_status'] = $this->request->post['payment_sagepay_server_status']; + } else { + $data['payment_sagepay_server_status'] = $this->config->get('payment_sagepay_server_status'); + } + + if (isset($this->request->post['payment_sagepay_server_debug'])) { + $data['payment_sagepay_server_debug'] = $this->request->post['payment_sagepay_server_debug']; + } else { + $data['payment_sagepay_server_debug'] = $this->config->get('payment_sagepay_server_debug'); + } + + if (isset($this->request->post['payment_sagepay_server_sort_order'])) { + $data['payment_sagepay_server_sort_order'] = $this->request->post['payment_sagepay_server_sort_order']; + } else { + $data['payment_sagepay_server_sort_order'] = $this->config->get('payment_sagepay_server_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/sagepay_server', $data)); + } + + public function install() { + $this->load->model('extension/payment/sagepay_server'); + $this->model_extension_payment_sagepay_server->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/sagepay_server'); + $this->model_extension_payment_sagepay_server->uninstall(); + } + + public function order() { + if ($this->config->get('payment_sagepay_server_status')) { + $this->load->model('extension/payment/sagepay_server'); + + $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->get['order_id']); + + if (!empty($sagepay_server_order)) { + $this->load->language('extension/payment/sagepay_server'); + + $sagepay_server_order['total_released'] = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']); + + $sagepay_server_order['total_formatted'] = $this->currency->format($sagepay_server_order['total'], $sagepay_server_order['currency_code'], false, false); + $sagepay_server_order['total_released_formatted'] = $this->currency->format($sagepay_server_order['total_released'], $sagepay_server_order['currency_code'], false, false); + + $data['sagepay_server_order'] = $sagepay_server_order; + + $data['auto_settle'] = $sagepay_server_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/sagepay_server_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/sagepay_server'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/sagepay_server'); + + $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_sagepay_server->void($this->request->post['order_id']); + + $this->model_extension_payment_sagepay_server->logger('Void result', $void_response); + + if ($void_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'void', 0.00); + $this->model_extension_payment_sagepay_server->updateVoidStatus($sagepay_server_order['sagepay_server_order_id'], 1); + + $json['msg'] = $this->language->get('text_void_ok'); + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($void_response['StatuesDetail']) && !empty($void_response['StatuesDetail']) ? (string)$void_response['StatuesDetail'] : 'Unable to void'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/sagepay_server'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($this->request->post['amount']) && $this->request->post['amount'] > 0) { + $this->load->model('extension/payment/sagepay_server'); + + $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_sagepay_server->release($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_sagepay_server->logger('Release result', $release_response); + + if ($release_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'payment', $this->request->post['amount']); + + $total_released = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']); + + if ($total_released >= $sagepay_server_order['total'] || $sagepay_server_order['settle_type'] == 0) { + $this->model_extension_payment_sagepay_server->updateReleaseStatus($sagepay_server_order['sagepay_server_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount']; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (float)$total_released; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($release_response['StatusDetail']) && !empty($release_response['StatusDetail']) ? (string)$release_response['StatusDetail'] : 'Unable to release'; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/sagepay_server'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/sagepay_server'); + + $sagepay_server_order = $this->model_extension_payment_sagepay_server->getOrder($this->request->post['order_id']); + + $rebate_response = $this->model_extension_payment_sagepay_server->rebate($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_sagepay_server->logger('Rebate result', $rebate_response); + + if ($rebate_response['Status'] == 'OK') { + $this->model_extension_payment_sagepay_server->addTransaction($sagepay_server_order['sagepay_server_order_id'], 'rebate', $this->request->post['amount'] * -1); + + $total_rebated = $this->model_extension_payment_sagepay_server->getTotalRebated($sagepay_server_order['sagepay_server_order_id']); + $total_released = $this->model_extension_payment_sagepay_server->getTotalReleased($sagepay_server_order['sagepay_server_order_id']); + + if ($total_released <= 0 && $sagepay_server_order['release_status'] == 1) { + $this->model_extension_payment_sagepay_server->updateRebateStatus($sagepay_server_order['sagepay_server_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['date_added'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->request->post['amount'] * -1; + $json['data']['total_released'] = (float)$total_released; + $json['data']['total_rebated'] = (float)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($rebate_response['StatusDetail']) && !empty($rebate_response['StatusDetail']) ? (string)$rebate_response['StatusDetail'] : 'Unable to rebate'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_server')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_sagepay_server_vendor']) { + $this->error['vendor'] = $this->language->get('error_vendor'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/sagepay_us.php b/public/admin/controller/extension/payment/sagepay_us.php new file mode 100644 index 0000000..1a92ba7 --- /dev/null +++ b/public/admin/controller/extension/payment/sagepay_us.php @@ -0,0 +1,131 @@ +<?php +class ControllerExtensionPaymentSagepayUS extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/sagepay_us'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_sagepay_us', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['merchant_id'])) { + $data['error_merchant_id'] = $this->error['merchant_id']; + } else { + $data['error_merchant_id'] = ''; + } + + if (isset($this->error['merchant_key'])) { + $data['error_merchant_key'] = $this->error['merchant_key']; + } else { + $data['error_merchant_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/sagepay_us', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/sagepay_us', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_sagepay_us_merchant_id'])) { + $data['payment_sagepay_us_merchant_id'] = $this->request->post['payment_sagepay_us_merchant_id']; + } else { + $data['payment_sagepay_us_merchant_id'] = $this->config->get('payment_sagepay_us_merchant_id'); + } + + if (isset($this->request->post['payment_sagepay_us_merchant_key'])) { + $data['payment_sagepay_us_merchant_key'] = $this->request->post['payment_sagepay_us_merchant_key']; + } else { + $data['payment_sagepay_us_merchant_key'] = $this->config->get('payment_sagepay_us_merchant_key'); + } + + if (isset($this->request->post['payment_sagepay_us_total'])) { + $data['payment_sagepay_us_total'] = $this->request->post['payment_sagepay_us_total']; + } else { + $data['payment_sagepay_us_total'] = $this->config->get('payment_sagepay_us_total'); + } + + if (isset($this->request->post['payment_sagepay_us_order_status_id'])) { + $data['payment_sagepay_us_order_status_id'] = $this->request->post['payment_sagepay_us_order_status_id']; + } else { + $data['payment_sagepay_us_order_status_id'] = $this->config->get('payment_sagepay_us_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_sagepay_us_geo_zone_id'])) { + $data['payment_sagepay_us_geo_zone_id'] = $this->request->post['payment_sagepay_us_geo_zone_id']; + } else { + $data['payment_sagepay_us_geo_zone_id'] = $this->config->get('payment_sagepay_us_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_sagepay_us_status'])) { + $data['payment_sagepay_us_status'] = $this->request->post['payment_sagepay_us_status']; + } else { + $data['payment_sagepay_us_status'] = $this->config->get('payment_sagepay_us_status'); + } + + if (isset($this->request->post['payment_sagepay_us_sort_order'])) { + $data['payment_sagepay_us_sort_order'] = $this->request->post['payment_sagepay_us_sort_order']; + } else { + $data['payment_sagepay_us_sort_order'] = $this->config->get('payment_sagepay_us_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/sagepay_us', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/sagepay_us')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_sagepay_us_merchant_id']) { + $this->error['merchant_id'] = $this->language->get('error_merchant_id'); + } + + if (!$this->request->post['payment_sagepay_us_merchant_key']) { + $this->error['merchant_key'] = $this->language->get('error_merchant_key'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/securetrading_pp.php b/public/admin/controller/extension/payment/securetrading_pp.php new file mode 100644 index 0000000..de4850c --- /dev/null +++ b/public/admin/controller/extension/payment/securetrading_pp.php @@ -0,0 +1,475 @@ +<?php +class ControllerExtensionPaymentSecureTradingPp extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + $this->load->model('localisation/geo_zone'); + $this->load->model('localisation/order_status'); + $this->load->language('extension/payment/securetrading_pp'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->request->post['payment_securetrading_pp_site_reference'] = trim($this->request->post['payment_securetrading_pp_site_reference']); + + $this->model_setting_setting->editSetting('payment_securetrading_pp', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->request->post['payment_securetrading_pp_site_reference'])) { + $data['payment_securetrading_pp_site_reference'] = $this->request->post['payment_securetrading_pp_site_reference']; + } else { + $data['payment_securetrading_pp_site_reference'] = $this->config->get('payment_securetrading_pp_site_reference'); + } + + if (isset($this->request->post['payment_securetrading_pp_username'])) { + $data['payment_securetrading_pp_username'] = $this->request->post['payment_securetrading_pp_username']; + } else { + $data['payment_securetrading_pp_username'] = $this->config->get('payment_securetrading_pp_username'); + } + + if (isset($this->request->post['payment_securetrading_pp_password'])) { + $data['payment_securetrading_pp_password'] = $this->request->post['payment_securetrading_pp_password']; + } else { + $data['payment_securetrading_pp_password'] = $this->config->get('payment_securetrading_pp_password'); + } + + if (isset($this->request->post['payment_securetrading_pp_notification_password'])) { + $data['payment_securetrading_pp_notification_password'] = $this->request->post['payment_securetrading_pp_notification_password']; + } else { + $data['payment_securetrading_pp_notification_password'] = $this->config->get('payment_securetrading_pp_notification_password'); + } + + if (isset($this->request->post['payment_securetrading_pp_site_security_password'])) { + $data['payment_securetrading_pp_site_security_password'] = $this->request->post['payment_securetrading_pp_site_security_password']; + } else { + $data['payment_securetrading_pp_site_security_password'] = $this->config->get('payment_securetrading_pp_site_security_password'); + } + + if (isset($this->request->post['payment_securetrading_pp_site_security_status'])) { + $data['payment_securetrading_pp_site_security_status'] = $this->request->post['payment_securetrading_pp_site_security_status']; + } else { + $data['payment_securetrading_pp_site_security_status'] = $this->config->get('payment_securetrading_pp_site_security_status'); + } + + if (isset($this->request->post['payment_securetrading_pp_webservice_username'])) { + $data['payment_securetrading_pp_webservice_username'] = $this->request->post['payment_securetrading_pp_webservice_username']; + } else { + $data['payment_securetrading_pp_webservice_username'] = $this->config->get('payment_securetrading_pp_webservice_username'); + } + + if (isset($this->request->post['payment_securetrading_pp_webservice_password'])) { + $data['payment_securetrading_pp_webservice_password'] = $this->request->post['payment_securetrading_pp_webservice_password']; + } else { + $data['payment_securetrading_pp_webservice_password'] = $this->config->get('payment_securetrading_pp_webservice_password'); + } + + if (isset($this->request->post['payment_securetrading_pp_order_status_id'])) { + $data['payment_securetrading_pp_order_status_id'] = $this->request->post['payment_securetrading_pp_order_status_id']; + } elseif($this->config->get('payment_securetrading_pp_order_status_id') != '') { + $data['payment_securetrading_pp_order_status_id'] = $this->config->get('payment_securetrading_pp_order_status_id'); + } else { + $data['payment_securetrading_pp_order_status_id'] = 1; + } + + if (isset($this->request->post['payment_securetrading_pp_declined_order_status_id'])) { + $data['payment_securetrading_pp_declined_order_status_id'] = $this->request->post['payment_securetrading_pp_declined_order_status_id']; + } elseif($this->config->get('payment_securetrading_pp_declined_order_status_id') != '') { + $data['payment_securetrading_pp_declined_order_status_id'] = $this->config->get('payment_securetrading_pp_declined_order_status_id'); + } else { + $data['payment_securetrading_pp_declined_order_status_id'] = 8; + } + + if (isset($this->request->post['payment_securetrading_pp_refunded_order_status_id'])) { + $data['payment_securetrading_pp_refunded_order_status_id'] = $this->request->post['payment_securetrading_pp_refunded_order_status_id']; + } elseif($this->config->get('payment_securetrading_pp_refunded_order_status_id') != '') { + $data['payment_securetrading_pp_refunded_order_status_id'] = $this->config->get('payment_securetrading_pp_refunded_order_status_id'); + } else { + $data['payment_securetrading_pp_refunded_order_status_id'] = 11; + } + + if (isset($this->request->post['payment_securetrading_pp_authorisation_reversed_order_status_id'])) { + $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = $this->request->post['payment_securetrading_pp_authorisation_reversed_order_status_id']; + } elseif($this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id') != '') { + $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = $this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id'); + } else { + $data['payment_securetrading_pp_authorisation_reversed_order_status_id'] = 12; + } + + if (isset($this->request->post['payment_securetrading_pp_settle_status'])) { + $data['payment_securetrading_pp_settle_status'] = $this->request->post['payment_securetrading_pp_settle_status']; + } else { + $data['payment_securetrading_pp_settle_status'] = $this->config->get('payment_securetrading_pp_settle_status'); + } + + if (isset($this->request->post['payment_securetrading_pp_settle_due_date'])) { + $data['payment_securetrading_pp_settle_due_date'] = $this->request->post['payment_securetrading_pp_settle_due_date']; + } else { + $data['payment_securetrading_pp_settle_due_date'] = $this->config->get('payment_securetrading_pp_settle_due_date'); + } + + if (isset($this->request->post['payment_securetrading_pp_geo_zone_id'])) { + $data['payment_securetrading_pp_geo_zone_id'] = $this->request->post['payment_securetrading_pp_geo_zone_id']; + } else { + $data['payment_securetrading_pp_geo_zone_id'] = $this->config->get('payment_securetrading_pp_geo_zone_id'); + } + + if (isset($this->request->post['payment_securetrading_pp_status'])) { + $data['payment_securetrading_pp_status'] = $this->request->post['payment_securetrading_pp_status']; + } else { + $data['payment_securetrading_pp_status'] = $this->config->get('payment_securetrading_pp_status'); + } + + if (isset($this->request->post['payment_securetrading_pp_sort_order'])) { + $data['payment_securetrading_pp_sort_order'] = $this->request->post['payment_securetrading_pp_sort_order']; + } else { + $data['payment_securetrading_pp_sort_order'] = $this->config->get('payment_securetrading_pp_sort_order'); + } + + if (isset($this->request->post['payment_securetrading_pp_total'])) { + $data['payment_securetrading_pp_total'] = $this->request->post['payment_securetrading_pp_total']; + } else { + $data['payment_securetrading_pp_total'] = $this->config->get('payment_securetrading_pp_total'); + } + + if (isset($this->request->post['payment_securetrading_pp_parent_css'])) { + $data['payment_securetrading_pp_parent_css'] = $this->request->post['payment_securetrading_pp_parent_css']; + } else { + $data['payment_securetrading_pp_parent_css'] = $this->config->get('payment_securetrading_pp_parent_css'); + } + + if (isset($this->request->post['payment_securetrading_pp_child_css'])) { + $data['payment_securetrading_pp_child_css'] = $this->request->post['payment_securetrading_pp_child_css']; + } else { + $data['payment_securetrading_pp_child_css'] = $this->config->get('payment_securetrading_pp_child_css'); + } + + if (isset($this->request->post['payment_securetrading_pp_cards_accepted'])) { + $data['payment_securetrading_pp_cards_accepted'] = $this->request->post['payment_securetrading_pp_cards_accepted']; + } else { + $data['payment_securetrading_pp_cards_accepted'] = $this->config->get('payment_securetrading_pp_cards_accepted'); + + if ($data['payment_securetrading_pp_cards_accepted'] == null) { + $data['payment_securetrading_pp_cards_accepted'] = array(); + } + } + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['site_reference'])) { + $data['error_site_reference'] = $this->error['site_reference']; + } else { + $data['error_site_reference'] = ''; + } + + if (isset($this->error['cards_accepted'])) { + $data['error_cards_accepted'] = $this->error['cards_accepted']; + } else { + $data['error_cards_accepted'] = ''; + } + + if (isset($this->error['notification_password'])) { + $data['error_notification_password'] = $this->error['notification_password']; + } else { + $data['error_notification_password'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/securetrading_pp', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + $data['cards'] = array( + 'AMEX' => 'American Express', + 'VISA' => 'Visa', + 'DELTA' => 'Visa Debit', + 'ELECTRON' => 'Visa Electron', + 'PURCHASING' => 'Visa Purchasing', + 'VPAY' => 'V Pay', + 'MASTERCARD' => 'MasterCard', + 'MASTERCARDDEBIT' => 'MasterCard Debit', + 'MAESTRO' => 'Maestro', + 'PAYPAL' => 'PayPal', + ); + + $data['settlement_statuses'] = array( + '0' => $this->language->get('text_pending_settlement'), + '1' => $this->language->get('text_pending_settlement_manually_overriden'), + '2' => $this->language->get('text_pending_suspended'), + '100' => $this->language->get('text_pending_settled'), + ); + + $data['action'] = $this->url->link('extension/payment/securetrading_pp', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/securetrading_pp', $data)); + } + + public function install() { + $this->load->model('extension/payment/securetrading_pp'); + $this->model_extension_payment_securetrading_pp->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/securetrading_pp'); + $this->model_extension_payment_securetrading_pp->uninstall(); + } + + public function order() { + if ($this->config->get('payment_securetrading_pp_status')) { + $this->load->model('extension/payment/securetrading_pp'); + + $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->get['order_id']); + + if (!empty($securetrading_pp_order)) { + $this->load->language('extension/payment/securetrading_pp'); + + $securetrading_pp_order['total_released'] = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']); + + $securetrading_pp_order['total_formatted'] = $this->currency->format($securetrading_pp_order['total'], $securetrading_pp_order['currency_code'], false, false); + $securetrading_pp_order['total_released_formatted'] = $this->currency->format($securetrading_pp_order['total_released'], $securetrading_pp_order['currency_code'], false, false); + + $data['securetrading_pp_order'] = $securetrading_pp_order; + + $data['auto_settle'] = $securetrading_pp_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/securetrading_pp_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/securetrading_pp'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/securetrading_pp'); + + $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_securetrading_pp->void($this->request->post['order_id']); + + $this->model_extension_payment_securetrading_pp->logger('Void result:\r\n' . print_r($void_response, 1)); + + if ($void_response !== false) { + $response_xml = simplexml_load_string($void_response); + + if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') { + $json['msg'] = (string)$response_xml->response->error->message; + $json['error'] = true; + } else { + + $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'reversed', 0.00); + $this->model_extension_payment_securetrading_pp->updateVoidStatus($securetrading_pp_order['securetrading_pp_order_id'], 1); + + $this->data = array( + 'order_status_id' => $this->config->get('payment_securetrading_pp_authorisation_reversed_order_status_id'), + 'notify' => false, + 'comment' => '', + ); + + $this->load->model('sale/order'); + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $this->data); + + $json['msg'] = $this->language->get('text_authorisation_reversed'); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } + } else { + $json['msg'] = $this->language->get('error_connection'); + $json['error'] = true; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/securetrading_pp'); + $json = array(); + + $amount = number_format($this->request->post['amount'], 2); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($amount) && $amount > 0) { + $this->load->model('extension/payment/securetrading_pp'); + + $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_securetrading_pp->release($this->request->post['order_id'], $amount); + + $this->model_extension_payment_securetrading_pp->logger('Release result:\r\n' . print_r($release_response, 1)); + + if ($release_response !== false) { + $response_xml = simplexml_load_string($release_response); + + if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') { + $json['error'] = true; + $json['msg'] = (string)$response_xml->response->error->message; + } else { + $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'payment', $amount); + + $total_released = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']); + + if ($total_released >= $securetrading_pp_order['total'] || $securetrading_pp_order['settle_type'] == 100) { + $this->model_extension_payment_securetrading_pp->updateReleaseStatus($securetrading_pp_order['securetrading_pp_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + + $this->load->model('sale/order'); + + $history = array(); + $history['order_status_id'] = $this->config->get('securetrading_pp_order_status_success_settled_id'); + $history['comment'] = ''; + $history['notify'] = ''; + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $amount; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (double)$total_released; + $json['error'] = false; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_connection'); + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/securetrading_pp'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/securetrading_pp'); + + $securetrading_pp_order = $this->model_extension_payment_securetrading_pp->getOrder($this->request->post['order_id']); + + $amount = number_format($this->request->post['amount'], 2); + + $rebate_response = $this->model_extension_payment_securetrading_pp->rebate($this->request->post['order_id'], $amount); + + $this->model_extension_payment_securetrading_pp->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if ($rebate_response !== false) { + $response_xml = simplexml_load_string($rebate_response); + + $error_code = (string)$response_xml->response->error->code; + + if ($error_code == '0') { + + $this->model_extension_payment_securetrading_pp->addTransaction($securetrading_pp_order['securetrading_pp_order_id'], 'rebate', $amount * -1); + + $total_rebated = $this->model_extension_payment_securetrading_pp->getTotalRebated($securetrading_pp_order['securetrading_pp_order_id']); + $total_released = $this->model_extension_payment_securetrading_pp->getTotalReleased($securetrading_pp_order['securetrading_pp_order_id']); + + if ($total_released <= 0 && $securetrading_pp_order['release_status'] == 1) { + $json['status'] = 1; + $json['message'] = $this->language->get('text_refund_issued'); + + $this->model_extension_payment_securetrading_pp->updateRebateStatus($securetrading_pp_order['securetrading_pp_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + + $this->load->model('sale/order'); + + $history = array(); + $history['order_status_id'] = $this->config->get('payment_securetrading_pp_refunded_order_status_id'); + $history['comment'] = ''; + $history['notify'] = ''; + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $amount * -1; + $json['data']['total_released'] = (double)$total_released; + $json['data']['total_rebated'] = (double)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = (string)$response_xml->response->error->message; + } + } else { + $json['status'] = 0; + $json['message'] = $this->language->get('error_connection'); + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/securetrading_pp')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_securetrading_pp_site_reference']) { + $this->error['site_reference'] = $this->language->get('error_site_reference'); + } + + if (empty($this->request->post['payment_securetrading_pp_cards_accepted'])) { + $this->error['cards_accepted'] = $this->language->get('error_cards_accepted'); + } + + if (!$this->request->post['payment_securetrading_pp_notification_password']) { + $this->error['notification_password'] = $this->language->get('error_notification_password'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/securetrading_ws.php b/public/admin/controller/extension/payment/securetrading_ws.php new file mode 100644 index 0000000..8e702ec --- /dev/null +++ b/public/admin/controller/extension/payment/securetrading_ws.php @@ -0,0 +1,570 @@ +<?php +class ControllerExtensionPaymentSecureTradingWs extends Controller { + private $error = array(); + + public function index() { + $this->load->model('setting/setting'); + $this->load->model('localisation/geo_zone'); + $this->load->model('localisation/order_status'); + $this->load->model('localisation/currency'); + $this->load->language('extension/payment/securetrading_ws'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->request->post['payment_securetrading_ws_site_reference'] = trim($this->request->post['payment_securetrading_ws_site_reference']); + $this->request->post['payment_securetrading_ws_username'] = trim($this->request->post['payment_securetrading_ws_username']); + + $this->model_setting_setting->editSetting('payment_securetrading_ws', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->request->post['payment_securetrading_ws_site_reference'])) { + $data['payment_securetrading_ws_site_reference'] = $this->request->post['payment_securetrading_ws_site_reference']; + } else { + $data['payment_securetrading_ws_site_reference'] = $this->config->get('payment_securetrading_ws_site_reference'); + } + + if (isset($this->request->post['payment_securetrading_ws_username'])) { + $data['payment_securetrading_ws_username'] = $this->request->post['payment_securetrading_ws_username']; + } else { + $data['payment_securetrading_ws_username'] = $this->config->get('payment_securetrading_ws_username'); + } + + if (isset($this->request->post['payment_securetrading_ws_password'])) { + $data['payment_securetrading_ws_password'] = $this->request->post['payment_securetrading_ws_password']; + } else { + $data['payment_securetrading_ws_password'] = $this->config->get('payment_securetrading_ws_password'); + } + + if (isset($this->request->post['payment_securetrading_ws_csv_username'])) { + $data['payment_securetrading_ws_csv_username'] = $this->request->post['payment_securetrading_ws_csv_username']; + } else { + $data['payment_securetrading_ws_csv_username'] = $this->config->get('payment_securetrading_ws_csv_username'); + } + + if (isset($this->request->post['payment_securetrading_ws_csv_password'])) { + $data['payment_securetrading_ws_csv_password'] = $this->request->post['payment_securetrading_ws_csv_password']; + } else { + $data['payment_securetrading_ws_csv_password'] = $this->config->get('payment_securetrading_ws_csv_password'); + } + + $this->config->set('payment_securetrading_ws_3d_secure', 1); + + if (isset($this->request->post['payment_securetrading_ws_3d_secure'])) { + $data['payment_securetrading_ws_3d_secure'] = $this->request->post['payment_securetrading_ws_3d_secure']; + } else { + $data['payment_securetrading_ws_3d_secure'] = $this->config->get('payment_securetrading_ws_3d_secure'); + } + + if (isset($this->request->post['payment_securetrading_ws_cards_accepted'])) { + $data['payment_securetrading_ws_cards_accepted'] = $this->request->post['payment_securetrading_ws_cards_accepted']; + } else { + $data['payment_securetrading_ws_cards_accepted'] = $this->config->get('payment_securetrading_ws_cards_accepted'); + + if ($data['payment_securetrading_ws_cards_accepted'] == null) { + $data['payment_securetrading_ws_cards_accepted'] = array(); + } + } + + if (isset($this->request->post['payment_securetrading_ws_order_status_id'])) { + $data['payment_securetrading_ws_order_status_id'] = $this->request->post['payment_securetrading_ws_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_order_status_id') != '') { + $data['payment_securetrading_ws_order_status_id'] = $this->config->get('payment_securetrading_ws_order_status_id'); + } else { + $data['payment_securetrading_ws_order_status_id'] = 1; + } + + if (isset($this->request->post['payment_securetrading_ws_failed_order_status_id'])) { + $data['payment_securetrading_ws_failed_order_status_id'] = $this->request->post['payment_securetrading_ws_failed_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_failed_order_status_id') != '') { + $data['payment_securetrading_ws_failed_order_status_id'] = $this->config->get('payment_securetrading_ws_failed_order_status_id'); + } else { + $data['payment_securetrading_ws_failed_order_status_id'] = 10; + } + + if (isset($this->request->post['payment_securetrading_ws_declined_order_status_id'])) { + $data['payment_securetrading_ws_declined_order_status_id'] = $this->request->post['payment_securetrading_ws_declined_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_declined_order_status_id') != '') { + $data['payment_securetrading_ws_declined_order_status_id'] = $this->config->get('payment_securetrading_ws_declined_order_status_id'); + } else { + $data['payment_securetrading_ws_declined_order_status_id'] = 8; + } + + if (isset($this->request->post['payment_securetrading_ws_refunded_order_status_id'])) { + $data['payment_securetrading_ws_refunded_order_status_id'] = $this->request->post['payment_securetrading_ws_refunded_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_refunded_order_status_id') != '') { + $data['payment_securetrading_ws_refunded_order_status_id'] = $this->config->get('payment_securetrading_ws_refunded_order_status_id'); + } else { + $data['payment_securetrading_ws_refunded_order_status_id'] = 11; + } + + if (isset($this->request->post['payment_securetrading_ws_authorisation_reversed_order_status_id'])) { + $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = $this->request->post['payment_securetrading_ws_authorisation_reversed_order_status_id']; + } elseif ($this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id') != '') { + $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = $this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id'); + } else { + $data['payment_securetrading_ws_authorisation_reversed_order_status_id'] = 12; + } + + if (isset($this->request->post['payment_securetrading_ws_settle_status'])) { + $data['payment_securetrading_ws_settle_status'] = $this->request->post['payment_securetrading_ws_settle_status']; + } else { + $data['payment_securetrading_ws_settle_status'] = $this->config->get('payment_securetrading_ws_settle_status'); + } + + if (isset($this->request->post['payment_securetrading_ws_settle_due_date'])) { + $data['payment_securetrading_ws_settle_due_date'] = $this->request->post['payment_securetrading_ws_settle_due_date']; + } else { + $data['payment_securetrading_ws_settle_due_date'] = $this->config->get('payment_securetrading_ws_settle_due_date'); + } + + if (isset($this->request->post['payment_securetrading_ws_geo_zone'])) { + $data['payment_securetrading_ws_geo_zone_id'] = $this->request->post['payment_securetrading_ws_geo_zone_id']; + } else { + $data['payment_securetrading_ws_geo_zone_id'] = $this->config->get('payment_securetrading_ws_geo_zone_id'); + } + + if (isset($this->request->post['payment_securetrading_ws_status'])) { + $data['payment_securetrading_ws_status'] = $this->request->post['payment_securetrading_ws_status']; + } else { + $data['payment_securetrading_ws_status'] = $this->config->get('payment_securetrading_ws_status'); + } + + if (isset($this->request->post['payment_securetrading_ws_sort_order'])) { + $data['payment_securetrading_ws_sort_order'] = $this->request->post['payment_securetrading_ws_sort_order']; + } else { + $data['payment_securetrading_ws_sort_order'] = $this->config->get('payment_securetrading_ws_sort_order'); + } + + if (isset($this->request->post['payment_securetrading_ws_total'])) { + $data['payment_securetrading_ws_total'] = $this->request->post['payment_securetrading_ws_total']; + } else { + $data['payment_securetrading_ws_total'] = $this->config->get('payment_securetrading_ws_total'); + } + + $this->document->setTitle($this->language->get('heading_title')); + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['site_reference'])) { + $data['error_site_reference'] = $this->error['site_reference']; + } else { + $data['error_site_reference'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['cards_accepted'])) { + $data['error_cards_accepted'] = $this->error['cards_accepted']; + } else { + $data['error_cards_accepted'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/securetrading_ws', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['cards'] = array( + 'AMEX' => 'American Express', + 'VISA' => 'Visa', + 'DELTA' => 'Visa Debit', + 'ELECTRON' => 'Visa Electron', + 'PURCHASING' => 'Visa Purchasing', + 'VPAY' => 'V Pay', + 'MASTERCARD' => 'MasterCard', + 'MASTERCARDDEBIT' => 'MasterCard Debit', + 'MAESTRO' => 'Maestro', + 'PAYPAL' => 'PayPal', + ); + + $data['settlement_statuses'] = array( + '0' => $this->language->get('text_pending_settlement'), + '1' => $this->language->get('text_pending_settlement_manually_overriden'), + '2' => $this->language->get('text_pending_suspended'), + '100' => $this->language->get('text_pending_settled'), + ); + + $data['action'] = $this->url->link('extension/payment/securetrading_ws', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + $data['myst_status'] = !empty($data['securetrading_ws_csv_username']) && !empty($data['securetrading_ws_csv_password']); + $data['hours'] = array(); + + for ($i = 0; $i < 24; $i++) { + $data['hours'][] = str_pad($i, 2, '0', STR_PAD_LEFT); + } + + $data['minutes'] = array(); + + for ($i = 0; $i < 60; $i++) { + $data['minutes'][] = str_pad($i, 2, '0', STR_PAD_LEFT); + } + + $data['currencies'] = $this->model_localisation_currency->getCurrencies(); + + $data['user_token'] = $this->session->data['user_token']; + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/securetrading_ws', $data)); + } + + public function install() { + $this->load->model('extension/payment/securetrading_ws'); + $this->model_extension_payment_securetrading_ws->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/securetrading_ws'); + $this->model_extension_payment_securetrading_ws->uninstall(); + } + + public function downloadTransactions() { + $this->load->model('extension/payment/securetrading_ws'); + $this->load->language('extension/payment/securetrading_ws'); + + $csv_data = $this->request->post; + $csv_data['detail'] = true; + + $response = $this->model_extension_payment_securetrading_ws->getCsv($csv_data); + + header('Content-Type: application/octet-stream'); + header('Content-Disposition: attachment; filename="' . $this->language->get('text_transactions') . '.csv"'); + header('Expires: 0'); + header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); + header('Pragma: public'); + header('Content-Length: ' . strlen($response)); + + if (ob_get_level()) { + ob_end_clean(); + } + + echo $response; + exit(); + } + + public function showTransactions() { + $this->load->model('extension/payment/securetrading_ws'); + $this->load->language('extension/payment/securetrading_ws'); + + $csv_data = $this->request->post; + $csv_data['detail'] = false; + + $response = $this->model_extension_payment_securetrading_ws->getCsv($csv_data); + + $data['transactions'] = array(); + + $status_mapping = array( + '0' => $this->language->get('text_ok'), + '70000' => $this->language->get('text_denied'), + ); + + $settle_status_mapping = array( + '0' => $this->language->get('text_pending_settlement'), + '1' => $this->language->get('text_manual_settlement'), + '2' => $this->language->get('text_suspended'), + '3' => $this->language->get('text_cancelled'), + '10' => $this->language->get('text_settling'), + '100' => $this->language->get('text_settled'), + ); + + if ($response) { + $lines = array_filter(explode("\n", $response)); + + $csv = array(); + $keys = str_getcsv($lines[0]); + + for ($i = 1; $i < count($lines); $i++) { + $csv[] = array_combine($keys, str_getcsv($lines[$i])); + } + + foreach ($csv as $row) { + $data['transactions'][] = array( + 'order_id' => $row['orderreference'], + 'order_href' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $row['orderreference'], true), + 'transaction_reference' => $row['transactionreference'], + 'customer' => $row['billingfirstname'] . ' ' . $row['billinglastname'], + 'total' => $row['mainamount'], + 'currency' => $row['currencyiso3a'], + 'settle_status' => $settle_status_mapping[$row['settlestatus']], + 'status' => $status_mapping[$row['errorcode']], + 'type' => $row['requesttypedescription'], + 'payment_type' => $row['paymenttypedescription'], + ); + } + } + + return $this->load->view('extension/payment/securetrading_ws_transactions', $data); + } + + public function order() { + + if ($this->config->get('payment_securetrading_ws_status')) { + $this->load->model('extension/payment/securetrading_ws'); + + $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->get['order_id']); + + if (!empty($securetrading_ws_order)) { + $this->load->language('extension/payment/securetrading_ws'); + + $securetrading_ws_order['total_released'] = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']); + + $securetrading_ws_order['total_formatted'] = $this->currency->format($securetrading_ws_order['total'], $securetrading_ws_order['currency_code'], false, false); + $securetrading_ws_order['total_released_formatted'] = $this->currency->format($securetrading_ws_order['total_released'], $securetrading_ws_order['currency_code'], false, false); + + $data['securetrading_ws_order'] = $securetrading_ws_order; + + $data['auto_settle'] = $securetrading_ws_order['settle_type']; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/securetrading_ws_order', $data); + } + } + } + + public function void() { + $this->load->language('extension/payment/securetrading_ws'); + $json = array(); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '') { + $this->load->model('extension/payment/securetrading_ws'); + + $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']); + + $void_response = $this->model_extension_payment_securetrading_ws->void($this->request->post['order_id']); + + $this->model_extension_payment_securetrading_ws->logger('Void result:\r\n' . print_r($void_response, 1)); + + if ($void_response !== false) { + $response_xml = simplexml_load_string($void_response); + + if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') { + $json['msg'] = (string)$response_xml->response->error->message; + $json['error'] = true; + } else { + + $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'reversed', 0.00); + $this->model_extension_payment_securetrading_ws->updateVoidStatus($securetrading_ws_order['securetrading_ws_order_id'], 1); + + $this->data = array( + 'order_status_id' => $this->config->get('payment_securetrading_ws_authorisation_reversed_order_status_id'), + 'notify' => false, + 'comment' => '', + ); + + $this->load->model('sale/order'); + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $this->data); + + $json['msg'] = $this->language->get('text_authorisation_reversed'); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['error'] = false; + } + } else { + $json['msg'] = $this->language->get('error_connection'); + $json['error'] = true; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + public function release() { + $this->load->language('extension/payment/securetrading_ws'); + $json = array(); + + $amount = number_format($this->request->post['amount'], 2); + + if (isset($this->request->post['order_id']) && $this->request->post['order_id'] != '' && isset($amount) && $amount > 0) { + $this->load->model('extension/payment/securetrading_ws'); + + $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']); + + $release_response = $this->model_extension_payment_securetrading_ws->release($this->request->post['order_id'], $amount); + + $this->model_extension_payment_securetrading_ws->logger('Release result:\r\n' . print_r($release_response, 1)); + + if ($release_response !== false) { + $response_xml = simplexml_load_string($release_response); + + if ($response_xml->response['type'] == 'ERROR' || (string)$response_xml->response->error->code != '0') { + $json['error'] = true; + $json['msg'] = (string)$response_xml->response->error->message; + } else { + $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'payment', $amount); + + $total_released = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']); + + if ($total_released >= $securetrading_ws_order['total'] || $securetrading_ws_order['settle_type'] == 100) { + $this->model_extension_payment_securetrading_ws->updateReleaseStatus($securetrading_ws_order['securetrading_ws_order_id'], 1); + $release_status = 1; + $json['msg'] = $this->language->get('text_release_ok_order'); + + $this->load->model('sale/order'); + + $history = array(); + $history['order_status_id'] = $this->config->get('securetrading_ws_order_status_success_settled_id'); + $history['comment'] = ''; + $history['notify'] = ''; + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history); + } else { + $release_status = 0; + $json['msg'] = $this->language->get('text_release_ok'); + } + + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $amount; + $json['data']['release_status'] = $release_status; + $json['data']['total'] = (double)$total_released; + $json['error'] = false; + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_connection'); + } + } else { + $json['error'] = true; + $json['msg'] = $this->language->get('error_data_missing'); + } + + $this->response->setOutput(json_encode($json)); + } + + public function rebate() { + $this->load->language('extension/payment/securetrading_ws'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/securetrading_ws'); + + $securetrading_ws_order = $this->model_extension_payment_securetrading_ws->getOrder($this->request->post['order_id']); + + $amount = number_format($this->request->post['amount'], 2); + + $rebate_response = $this->model_extension_payment_securetrading_ws->rebate($this->request->post['order_id'], $amount); + + $this->model_extension_payment_securetrading_ws->logger('Rebate result:\r\n' . print_r($rebate_response, 1)); + + if ($rebate_response !== false) { + $response_xml = simplexml_load_string($rebate_response); + + $error_code = (string)$response_xml->response->error->code; + + if ($error_code == '0') { + + $this->model_extension_payment_securetrading_ws->addTransaction($securetrading_ws_order['securetrading_ws_order_id'], 'rebate', $amount * -1); + + $total_rebated = $this->model_extension_payment_securetrading_ws->getTotalRebated($securetrading_ws_order['securetrading_ws_order_id']); + $total_released = $this->model_extension_payment_securetrading_ws->getTotalReleased($securetrading_ws_order['securetrading_ws_order_id']); + + if ($total_released <= 0 && $securetrading_ws_order['release_status'] == 1) { + $json['status'] = 1; + $json['message'] = $this->language->get('text_refund_issued'); + + $this->model_extension_payment_securetrading_ws->updateRebateStatus($securetrading_ws_order['securetrading_ws_order_id'], 1); + $rebate_status = 1; + $json['msg'] = $this->language->get('text_rebate_ok_order'); + + $this->load->model('sale/order'); + + $history = array(); + $history['order_status_id'] = $this->config->get('payment_securetrading_ws_refunded_order_status_id'); + $history['comment'] = ''; + $history['notify'] = ''; + + $this->model_sale_order->addOrderHistory($this->request->post['order_id'], $history); + } else { + $rebate_status = 0; + $json['msg'] = $this->language->get('text_rebate_ok'); + } + + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $amount * -1; + $json['data']['total_released'] = (double)$total_released; + $json['data']['total_rebated'] = (double)$total_rebated; + $json['data']['rebate_status'] = $rebate_status; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = (string)$response_xml->response->error->message; + } + } else { + $json['status'] = 0; + $json['message'] = $this->language->get('error_connection'); + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/securetrading_pp')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_securetrading_ws_site_reference']) { + $this->error['site_reference'] = $this->language->get('error_site_reference'); + } + + if (!$this->request->post['payment_securetrading_ws_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['payment_securetrading_ws_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (empty($this->request->post['payment_securetrading_ws_cards_accepted'])) { + $this->error['cards_accepted'] = $this->language->get('error_cards_accepted'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/skrill.php b/public/admin/controller/extension/payment/skrill.php new file mode 100644 index 0000000..f53b107 --- /dev/null +++ b/public/admin/controller/extension/payment/skrill.php @@ -0,0 +1,157 @@ +<?php +class ControllerExtensionPaymentSkrill extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/skrill'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_skrill', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['email'])) { + $data['error_email'] = $this->error['email']; + } else { + $data['error_email'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/skrill', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/skrill', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_skrill_email'])) { + $data['payment_skrill_email'] = $this->request->post['payment_skrill_email']; + } else { + $data['payment_skrill_email'] = $this->config->get('payment_skrill_email'); + } + + if (isset($this->request->post['payment_skrill_secret'])) { + $data['payment_skrill_secret'] = $this->request->post['payment_skrill_secret']; + } else { + $data['payment_skrill_secret'] = $this->config->get('payment_skrill_secret'); + } + + if (isset($this->request->post['payment_skrill_total'])) { + $data['payment_skrill_total'] = $this->request->post['payment_skrill_total']; + } else { + $data['payment_skrill_total'] = $this->config->get('payment_skrill_total'); + } + + if (isset($this->request->post['payment_skrill_order_status_id'])) { + $data['payment_skrill_order_status_id'] = $this->request->post['payment_skrill_order_status_id']; + } else { + $data['payment_skrill_order_status_id'] = $this->config->get('payment_skrill_order_status_id'); + } + + if (isset($this->request->post['payment_skrill_pending_status_id'])) { + $data['payment_skrill_pending_status_id'] = $this->request->post['payment_skrill_pending_status_id']; + } else { + $data['payment_skrill_pending_status_id'] = $this->config->get('payment_skrill_pending_status_id'); + } + + if (isset($this->request->post['payment_skrill_canceled_status_id'])) { + $data['payment_skrill_canceled_status_id'] = $this->request->post['payment_skrill_canceled_status_id']; + } else { + $data['payment_skrill_canceled_status_id'] = $this->config->get('payment_skrill_canceled_status_id'); + } + + if (isset($this->request->post['payment_skrill_failed_status_id'])) { + $data['payment_skrill_failed_status_id'] = $this->request->post['payment_skrill_failed_status_id']; + } else { + $data['payment_skrill_failed_status_id'] = $this->config->get('payment_skrill_failed_status_id'); + } + + if (isset($this->request->post['payment_skrill_chargeback_status_id'])) { + $data['payment_skrill_chargeback_status_id'] = $this->request->post['payment_skrill_chargeback_status_id']; + } else { + $data['payment_skrill_chargeback_status_id'] = $this->config->get('payment_skrill_chargeback_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_skrill_geo_zone_id'])) { + $data['payment_skrill_geo_zone_id'] = $this->request->post['payment_skrill_geo_zone_id']; + } else { + $data['payment_skrill_geo_zone_id'] = $this->config->get('payment_skrill_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_skrill_status'])) { + $data['payment_skrill_status'] = $this->request->post['payment_skrill_status']; + } else { + $data['payment_skrill_status'] = $this->config->get('payment_skrill_status'); + } + + if (isset($this->request->post['payment_skrill_sort_order'])) { + $data['payment_skrill_sort_order'] = $this->request->post['payment_skrill_sort_order']; + } else { + $data['payment_skrill_sort_order'] = $this->config->get('payment_skrill_sort_order'); + } + + if (isset($this->request->post['payment_skrill_rid'])) { + $data['payment_skrill_rid'] = $this->request->post['payment_skrill_rid']; + } else { + $data['payment_skrill_rid'] = $this->config->get('payment_skrill_rid'); + } + + if (isset($this->request->post['payment_skrill_custnote'])) { + $data['payment_skrill_custnote'] = $this->request->post['payment_skrill_custnote']; + } else { + $data['payment_skrill_custnote'] = $this->config->get('payment_skrill_custnote'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/skrill', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/skrill')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_skrill_email']) { + $this->error['email'] = $this->language->get('error_email'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/squareup.php b/public/admin/controller/extension/payment/squareup.php new file mode 100644 index 0000000..1ab2916 --- /dev/null +++ b/public/admin/controller/extension/payment/squareup.php @@ -0,0 +1,1079 @@ +<?php + +class ControllerExtensionPaymentSquareup extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/squareup'); + + $this->load->model('extension/payment/squareup'); + $this->load->model('setting/setting'); + + $this->load->library('squareup'); + + if ($this->request->server['HTTPS']) { + $server = HTTPS_SERVER; + } else { + $server = HTTP_SERVER; + } + + $previous_setting = $this->model_setting_setting->getSetting('payment_squareup'); + + try { + if ($this->config->get('payment_squareup_access_token')) { + if (!$this->squareup->verifyToken($this->config->get('payment_squareup_access_token'))) { + unset($previous_setting['payment_squareup_merchant_id']); + unset($previous_setting['payment_squareup_merchant_name']); + unset($previous_setting['payment_squareup_access_token']); + unset($previous_setting['payment_squareup_access_token_expires']); + unset($previous_setting['payment_squareup_locations']); + unset($previous_setting['payment_squareup_sandbox_locations']); + + $this->config->set('payment_squareup_merchant_id', null); + } else { + if (!$this->config->get('payment_squareup_locations')) { + $previous_setting['payment_squareup_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_access_token'), $first_location_id); + $previous_setting['payment_squareup_location_id'] = $first_location_id; + } + } + } + + if (!$this->config->get('payment_squareup_sandbox_locations') && $this->config->get('payment_squareup_sandbox_token')) { + $previous_setting['payment_squareup_sandbox_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_sandbox_token'), $first_location_id); + $previous_setting['payment_squareup_sandbox_location_id'] = $first_location_id; + } + + $this->model_setting_setting->editSetting('payment_squareup', $previous_setting); + } catch (\Squareup\Exception $e) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('text_location_error'), $e->getMessage()) + )); + } + + $previous_config = new Config(); + + foreach ($previous_setting as $key => $value) { + $previous_config->set($key, $value); + } + + if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) { + $this->model_setting_setting->editSetting('payment_squareup', array_merge($previous_setting, $this->request->post)); + + $this->session->data['success'] = $this->language->get('text_success'); + + if (isset($this->request->get['save_and_auth'])) { + $this->response->redirect($this->squareup->authLink($this->request->post['payment_squareup_client_id'])); + } else { + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + } + + $this->document->setTitle($this->language->get('heading_title')); + + $data['error_status'] = $this->getValidationError('status'); + $data['error_display_name'] = $this->getValidationError('display_name'); + $data['error_client_id'] = $this->getValidationError('client_id'); + $data['error_client_secret'] = $this->getValidationError('client_secret'); + $data['error_delay_capture'] = $this->getValidationError('delay_capture'); + $data['error_sandbox_client_id'] = $this->getValidationError('sandbox_client_id'); + $data['error_sandbox_token'] = $this->getValidationError('sandbox_token'); + $data['error_location'] = $this->getValidationError('location'); + $data['error_cron_email'] = $this->getValidationError('cron_email'); + $data['error_cron_acknowledge'] = $this->getValidationError('cron_acknowledge'); + + $data['payment_squareup_status'] = $this->getSettingValue('payment_squareup_status'); + $data['payment_squareup_status_authorized'] = $this->getSettingValue('payment_squareup_status_authorized'); + $data['payment_squareup_status_captured'] = $this->getSettingValue('payment_squareup_status_captured'); + $data['payment_squareup_status_voided'] = $this->getSettingValue('payment_squareup_status_voided'); + $data['payment_squareup_status_failed'] = $this->getSettingValue('payment_squareup_status_failed'); + $data['payment_squareup_display_name'] = $this->getSettingValue('payment_squareup_display_name'); + $data['payment_squareup_client_id'] = $this->getSettingValue('payment_squareup_client_id'); + $data['payment_squareup_client_secret'] = $this->getSettingValue('payment_squareup_client_secret'); + $data['payment_squareup_enable_sandbox'] = $this->getSettingValue('payment_squareup_enable_sandbox'); + $data['payment_squareup_debug'] = $this->getSettingValue('payment_squareup_debug'); + $data['payment_squareup_sort_order'] = $this->getSettingValue('payment_squareup_sort_order'); + $data['payment_squareup_total'] = $this->getSettingValue('payment_squareup_total'); + $data['payment_squareup_geo_zone_id'] = $this->getSettingValue('payment_squareup_geo_zone_id'); + $data['payment_squareup_sandbox_client_id'] = $this->getSettingValue('payment_squareup_sandbox_client_id'); + $data['payment_squareup_sandbox_token'] = $this->getSettingValue('payment_squareup_sandbox_token'); + $data['payment_squareup_locations'] = $this->getSettingValue('payment_squareup_locations', $previous_config->get('payment_squareup_locations')); + $data['payment_squareup_location_id'] = $this->getSettingValue('payment_squareup_location_id'); + $data['payment_squareup_sandbox_locations'] = $this->getSettingValue('payment_squareup_sandbox_locations', $previous_config->get('payment_squareup_sandbox_locations')); + $data['payment_squareup_sandbox_location_id'] = $this->getSettingValue('payment_squareup_sandbox_location_id'); + $data['payment_squareup_delay_capture'] = $this->getSettingValue('payment_squareup_delay_capture'); + $data['payment_squareup_recurring_status'] = $this->getSettingValue('payment_squareup_recurring_status'); + $data['payment_squareup_cron_email_status'] = $this->getSettingValue('payment_squareup_cron_email_status'); + $data['payment_squareup_cron_email'] = $this->getSettingValue('payment_squareup_cron_email', $this->config->get('config_email')); + $data['payment_squareup_cron_token'] = $this->getSettingValue('payment_squareup_cron_token'); + $data['payment_squareup_cron_acknowledge'] = $this->getSettingValue('payment_squareup_cron_acknowledge', null, true); + $data['payment_squareup_notify_recurring_success'] = $this->getSettingValue('payment_squareup_notify_recurring_success'); + $data['payment_squareup_notify_recurring_fail'] = $this->getSettingValue('payment_squareup_notify_recurring_fail'); + $data['payment_squareup_merchant_id'] = $this->getSettingValue('payment_squareup_merchant_id', $previous_config->get('payment_squareup_merchant_id')); + $data['payment_squareup_merchant_name'] = $this->getSettingValue('payment_squareup_merchant_name', $previous_config->get('payment_squareup_merchant_name')); + + if ($previous_config->get('payment_squareup_access_token') && $previous_config->get('payment_squareup_access_token_expires')) { + $expiration_time = date_create_from_format('Y-m-d\TH:i:s\Z', $previous_config->get('payment_squareup_access_token_expires')); + $now = date_create(); + + $delta = $expiration_time->getTimestamp() - $now->getTimestamp(); + $expiration_date_formatted = $expiration_time->format('l, F jS, Y h:i:s A, e'); + + if ($delta < 0) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('text_token_expired'), $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true)) + )); + } else if ($delta < (5 * 24 * 60 * 60)) { // token is valid, just about to expire + $this->pushAlert(array( + 'type' => 'warning', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('text_token_expiry_warning'), $expiration_date_formatted, $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true)) + )); + } + + $data['access_token_expires_time'] = $expiration_date_formatted; + } else if ($previous_config->get('payment_squareup_client_id')) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('text_token_revoked'), $this->squareup->authLink($previous_config->get('payment_squareup_client_id'))) + )); + + $data['access_token_expires_time'] = $this->language->get('text_na'); + } + + if ($previous_config->get('payment_squareup_client_id')) { + $data['payment_squareup_auth_link'] = $this->squareup->authLink($previous_config->get('payment_squareup_client_id')); + } else { + $data['payment_squareup_auth_link'] = null; + } + + $data['payment_squareup_redirect_uri'] = str_replace('&', '&', $this->url->link('extension/payment/squareup/oauth_callback', '', true)); + $data['payment_squareup_refresh_link'] = $this->url->link('extension/payment/squareup/refresh_token', 'user_token=' . $this->session->data['user_token'], true); + + if ($this->config->get('payment_squareup_enable_sandbox')) { + $this->pushAlert(array( + 'type' => 'warning', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('text_sandbox_enabled') + )); + } + + if (isset($this->error['warning'])) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->error['warning'] + )); + } + + // Insert success message from the session + if (isset($this->session->data['success'])) { + $this->pushAlert(array( + 'type' => 'success', + 'icon' => 'exclamation-circle', + 'text' => $this->session->data['success'] + )); + + unset($this->session->data['success']); + } + + if ($this->request->server['HTTPS']) { + // Push the SSL reminder alert + $this->pushAlert(array( + 'type' => 'info', + 'icon' => 'lock', + 'text' => $this->language->get('text_notification_ssl') + )); + } else { + // Push the SSL reminder alert + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_no_ssl') + )); + } + + $tabs = array( + 'tab-transaction', + 'tab-setting', + 'tab-recurring', + 'tab-cron' + ); + + if (isset($this->request->get['tab']) && in_array($this->request->get['tab'], $tabs)) { + $data['tab'] = $this->request->get['tab']; + } else if (isset($this->error['cron_email']) || isset($this->error['cron_acknowledge'])) { + $data['tab'] = 'tab-cron'; + } else if ($this->error) { + $data['tab'] = 'tab-setting'; + } else { + $data['tab'] = $tabs[1]; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = html_entity_decode($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + $data['action_save_auth'] = html_entity_decode($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'] . '&save_and_auth=1', true)); + $data['cancel'] = html_entity_decode($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + $data['url_list_transactions'] = html_entity_decode($this->url->link('extension/payment/squareup/transactions', 'user_token=' . $this->session->data['user_token'] . '&page={PAGE}', true)); + + $this->load->model('localisation/language'); + $data['languages'] = array(); + foreach ($this->model_localisation_language->getLanguages() as $language) { + $data['languages'][] = array( + 'language_id' => $language['language_id'], + 'name' => $language['name'] . ($language['code'] == $this->config->get('config_language') ? $this->language->get('text_default') : ''), + 'image' => 'language/' . $language['code'] . '/'. $language['code'] . '.png' + ); + } + + $this->load->model('localisation/order_status'); + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $this->load->model('localisation/geo_zone'); + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $data['payment_squareup_cron_command'] = PHP_BINDIR . '/php -d session.save_path=' . session_save_path() . ' ' . DIR_SYSTEM . 'library/squareup/cron.php ' . parse_url($server, PHP_URL_HOST) . ' 443 > /dev/null 2> /dev/null'; + + if (!$this->config->get('payment_squareup_cron_token')) { + $data['payment_squareup_cron_token'] = md5(mt_rand()); + } + + $data['payment_squareup_cron_url'] = 'https://' . parse_url($server, PHP_URL_HOST) . dirname(parse_url($server, PHP_URL_PATH)) . '/index.php?route=extension/recurring/squareup/recurring&cron_token={CRON_TOKEN}'; + + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $data['alerts'] = $this->pullAlerts(); + + $this->clearAlerts(); + + $this->response->setOutput($this->load->view('extension/payment/squareup', $data)); + } + + public function transaction_info() { + $this->load->language('extension/payment/squareup'); + + $this->load->model('extension/payment/squareup'); + + $this->load->library('squareup'); + + if (isset($this->request->get['squareup_transaction_id'])) { + $squareup_transaction_id = $this->request->get['squareup_transaction_id']; + } else { + $squareup_transaction_id = 0; + } + + $transaction_info = $this->model_extension_payment_squareup->getTransaction($squareup_transaction_id); + + if (empty($transaction_info)) { + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->document->setTitle(sprintf($this->language->get('heading_title_transaction'), $transaction_info['transaction_id'])); + + $data['alerts'] = $this->pullAlerts(); + + $this->clearAlerts(); + + $data['text_edit'] = sprintf($this->language->get('heading_title_transaction'), $transaction_info['transaction_id']); + + $amount = $this->currency->format($transaction_info['transaction_amount'], $transaction_info['transaction_currency']); + + $data['confirm_capture'] = sprintf($this->language->get('text_confirm_capture'), $amount); + $data['confirm_void'] = sprintf($this->language->get('text_confirm_void'), $amount); + $data['confirm_refund'] = $this->language->get('text_confirm_refund'); + $data['insert_amount'] = sprintf($this->language->get('text_insert_amount'), $amount, $transaction_info['transaction_currency']); + $data['text_loading'] = $this->language->get('text_loading_short'); + + $data['billing_address_company'] = $transaction_info['billing_address_company']; + $data['billing_address_street'] = $transaction_info['billing_address_street_1'] . ' ' . $transaction_info['billing_address_street_2']; + $data['billing_address_city'] = $transaction_info['billing_address_city']; + $data['billing_address_postcode'] = $transaction_info['billing_address_postcode']; + $data['billing_address_province'] = $transaction_info['billing_address_province']; + $data['billing_address_country'] = $transaction_info['billing_address_country']; + + $data['transaction_id'] = $transaction_info['transaction_id']; + $data['merchant'] = $transaction_info['merchant_id']; + $data['order_id'] = $transaction_info['order_id']; + $data['type'] = $transaction_info['transaction_type']; + $data['amount'] = $amount; + $data['currency'] = $transaction_info['transaction_currency']; + $data['browser'] = $transaction_info['device_browser']; + $data['ip'] = $transaction_info['device_ip']; + $data['date_created'] = date($this->language->get('datetime_format'), strtotime($transaction_info['created_at'])); + + $data['cancel'] = $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'] . '&tab=tab-transaction', true); + + $data['url_order'] = $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction_info['order_id'], true); + $data['url_void'] = $this->url->link('extension/payment/squareup' . '/void', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true); + $data['url_capture'] = $this->url->link('extension/payment/squareup' . '/capture', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true); + $data['url_refund'] = $this->url->link('extension/payment/squareup' . '/refund', 'user_token=' . $this->session->data['user_token'] . '&preserve_alert=true&squareup_transaction_id=' . $transaction_info['squareup_transaction_id'], true); + $data['url_transaction'] = sprintf( + Squareup::VIEW_TRANSACTION_URL, + $transaction_info['transaction_id'], + $transaction_info['location_id'] + ); + + $data['is_authorized'] = in_array($transaction_info['transaction_type'], array('AUTHORIZED')); + $data['is_captured'] = in_array($transaction_info['transaction_type'], array('CAPTURED')); + + $data['has_refunds'] = (bool)$transaction_info['is_refunded']; + + if ($data['has_refunds']) { + $refunds = @json_decode($transaction_info['refunds'], true); + + $data['refunds'] = array(); + + $data['text_refunds'] = sprintf($this->language->get('text_refunds'), count($refunds)); + + foreach ($refunds as $refund) { + $amount = $this->currency->format( + $this->squareup->standardDenomination( + $refund['amount_money']['amount'], + $refund['amount_money']['currency'] + ), + $refund['amount_money']['currency'] + ); + + $fee = $this->currency->format( + $this->squareup->standardDenomination( + $refund['processing_fee_money']['amount'], + $refund['processing_fee_money']['currency'] + ), + $refund['processing_fee_money']['currency'] + ); + + $data['refunds'][] = array( + 'date_created' => date($this->language->get('datetime_format'), strtotime($refund['created_at'])), + 'reason' => $refund['reason'], + 'status' => $refund['status'], + 'amount' => $amount, + 'fee' => $fee + ); + } + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => sprintf($this->language->get('heading_title_transaction'), $transaction_info['squareup_transaction_id']), + 'href' => $this->url->link('extension/payment/squareup/transaction_info', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $squareup_transaction_id, true) + ); + + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/squareup_transaction_info', $data)); + } + + public function transactions() { + $this->load->language('extension/payment/squareup'); + + $this->load->model('extension/payment/squareup'); + + if (isset($this->request->get['page'])) { + $page = (int)$this->request->get['page']; + } else { + $page = 1; + } + + $result = array( + 'transactions' => array(), + 'pagination' => '' + ); + + $filter_data = array( + 'start' => ($page - 1) * (int)$this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + if (isset($this->request->get['order_id'])) { + $filter_data['order_id'] = $this->request->get['order_id']; + } + + $transactions_total = $this->model_extension_payment_squareup->getTotalTransactions($filter_data); + $transactions = $this->model_extension_payment_squareup->getTransactions($filter_data); + + $this->load->model('sale/order'); + + foreach ($transactions as $transaction) { + $amount = $this->currency->format($transaction['transaction_amount'], $transaction['transaction_currency']); + + $order_info = $this->model_sale_order->getOrder($transaction['order_id']); + + $result['transactions'][] = array( + 'squareup_transaction_id' => $transaction['squareup_transaction_id'], + 'transaction_id' => $transaction['transaction_id'], + 'url_order' => $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $transaction['order_id'], true), + 'url_void' => $this->url->link('extension/payment/squareup/void', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true), + 'url_capture' => $this->url->link('extension/payment/squareup/capture', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true), + 'url_refund' => $this->url->link('extension/payment/squareup/refund', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true), + 'confirm_capture' => sprintf($this->language->get('text_confirm_capture'), $amount), + 'confirm_void' => sprintf($this->language->get('text_confirm_void'), $amount), + 'confirm_refund' => $this->language->get('text_confirm_refund'), + 'insert_amount' => sprintf($this->language->get('text_insert_amount'), $amount, $transaction['transaction_currency']), + 'order_id' => $transaction['order_id'], + 'type' => $transaction['transaction_type'], + 'num_refunds' => count(@json_decode($transaction['refunds'], true)), + 'amount' => $amount, + 'customer' => $order_info['firstname'] . ' ' . $order_info['lastname'], + 'ip' => $transaction['device_ip'], + 'date_created' => date($this->language->get('datetime_format'), strtotime($transaction['created_at'])), + 'url_info' => $this->url->link('extension/payment/squareup/transaction_info', 'user_token=' . $this->session->data['user_token'] . '&squareup_transaction_id=' . $transaction['squareup_transaction_id'], true) + ); + } + + $pagination = new Pagination(); + $pagination->total = $transactions_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = '{page}'; + + $result['pagination'] = $pagination->render(); + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($result)); + } + + public function refresh_token() { + $this->load->language('extension/payment/squareup'); + + if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_permission') + )); + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->load->model('setting/setting'); + + $this->load->library('squareup'); + + try { + $response = $this->squareup->refreshToken(); + + if (!isset($response['access_token']) || !isset($response['token_type']) || !isset($response['expires_at']) || !isset($response['merchant_id']) || + $response['merchant_id'] != $this->config->get('payment_squareup_merchant_id')) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_refresh_access_token') + )); + } else { + $settings = $this->model_setting_setting->getSetting('payment_squareup'); + + $settings['payment_squareup_access_token'] = $response['access_token']; + $settings['payment_squareup_access_token_expires'] = $response['expires_at']; + + $this->model_setting_setting->editSetting('payment_squareup', $settings); + + $this->pushAlert(array( + 'type' => 'success', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('text_refresh_access_token_success') + )); + } + } catch (\Squareup\Exception $e) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('error_token'), $e->getMessage()) + )); + } + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function oauth_callback() { + $this->load->language('extension/payment/squareup'); + + if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_permission') + )); + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + $this->load->model('setting/setting'); + + $this->load->library('squareup'); + + if (isset($this->request->get['error']) || isset($this->request->get['error_description'])) { + // auth error + if ($this->request->get['error'] == 'access_denied' && $this->request->get['error_description'] == 'user_denied') { + // user rejected giving auth permissions to his store + $this->pushAlert(array( + 'type' => 'warning', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_user_rejected_connect_attempt') + )); + } + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + // verify parameters for the redirect from Square (against random url crawling) + if (!isset($this->request->get['state']) || !isset($this->request->get['code']) || !isset($this->request->get['response_type'])) { + // missing or wrong info + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_possible_xss') + )); + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + // verify the state (against cross site requests) + if (!isset($this->session->data['payment_squareup_oauth_state']) || $this->session->data['payment_squareup_oauth_state'] != $this->request->get['state']) { + // state mismatch + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('error_possible_xss') + )); + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + try { + $token = $this->squareup->exchangeCodeForAccessToken($this->request->get['code']); + + $previous_setting = $this->model_setting_setting->getSetting('payment_squareup'); + + $previous_setting['payment_squareup_locations'] = $this->squareup->fetchLocations($token['access_token'], $first_location_id); + + if ( + !isset($previous_setting['payment_squareup_location_id']) || + (isset($previous_setting['payment_squareup_location_id']) && !in_array( + $previous_setting['payment_squareup_location_id'], + array_map( + function($location) { + return $location['id']; + }, + $previous_setting['payment_squareup_locations'] + ) + )) + ) { + $previous_setting['payment_squareup_location_id'] = $first_location_id; + } + + if (!$this->config->get('payment_squareup_sandbox_locations') && $this->config->get('payment_squareup_sandbox_token')) { + $previous_setting['payment_squareup_sandbox_locations'] = $this->squareup->fetchLocations($this->config->get('payment_squareup_sandbox_token'), $first_location_id); + $previous_setting['payment_squareup_sandbox_location_id'] = $first_location_id; + } + + $previous_setting['payment_squareup_merchant_id'] = $token['merchant_id']; + $previous_setting['payment_squareup_merchant_name'] = ''; // only available in v1 of the API, not populated for now + $previous_setting['payment_squareup_access_token'] = $token['access_token']; + $previous_setting['payment_squareup_access_token_expires'] = $token['expires_at']; + + $this->model_setting_setting->editSetting('payment_squareup', $previous_setting); + + unset($this->session->data['payment_squareup_oauth_state']); + unset($this->session->data['payment_squareup_oauth_redirect']); + + $this->pushAlert(array( + 'type' => 'success', + 'icon' => 'exclamation-circle', + 'text' => $this->language->get('text_refresh_access_token_success') + )); + } catch (\Squareup\Exception $e) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => sprintf($this->language->get('error_token'), $e->getMessage()) + )); + } + + $this->response->redirect($this->url->link('extension/payment/squareup', 'user_token=' . $this->session->data['user_token'], true)); + } + + public function capture() { + $this->transactionAction(function($transaction_info, &$json) { + $updated_transaction = $this->squareup->captureTransaction($transaction_info['location_id'], $transaction_info['transaction_id']); + + $status = $updated_transaction['tenders'][0]['card_details']['status']; + + $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status); + + $json['order_history_data'] = array( + 'notify' => 1, + 'order_id' => $transaction_info['order_id'], + 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id'], $status), + 'comment' => $this->language->get('squareup_status_comment_' . strtolower($status)), + ); + + $json['success'] = $this->language->get('text_success_capture'); + }); + } + + public function void() { + $this->transactionAction(function($transaction_info, &$json) { + $updated_transaction = $this->squareup->voidTransaction($transaction_info['location_id'], $transaction_info['transaction_id']); + + $status = $updated_transaction['tenders'][0]['card_details']['status']; + + $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status); + + $json['order_history_data'] = array( + 'notify' => 1, + 'order_id' => $transaction_info['order_id'], + 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id'], $status), + 'comment' => $this->language->get('squareup_status_comment_' . strtolower($status)), + ); + + $json['success'] = $this->language->get('text_success_void'); + }); + } + + public function refund() { + $this->transactionAction(function($transaction_info, &$json) { + if (!empty($this->request->post['reason'])) { + $reason = $this->request->post['reason']; + } else { + $reason = $this->language->get('text_no_reason_provided'); + } + + if (!empty($this->request->post['amount'])) { + $amount = preg_replace('~[^0-9\.\,]~', '', $this->request->post['amount']); + + if (strpos($amount, ',') !== FALSE && strpos($amount, '.') !== FALSE) { + $amount = (float)str_replace(',', '', $amount); + } else if (strpos($amount, ',') !== FALSE && strpos($amount, '.') === FALSE) { + $amount = (float)str_replace(',', '.', $amount); + } else { + $amount = (float)$amount; + } + } else { + $amount = 0; + } + + $currency = $transaction_info['transaction_currency']; + $tenders = @json_decode($transaction_info['tenders'], true); + + $updated_transaction = $this->squareup->refundTransaction($transaction_info['location_id'], $transaction_info['transaction_id'], $reason, $amount, $currency, $tenders[0]['id']); + + $status = $updated_transaction['tenders'][0]['card_details']['status']; + + $refunds = array(); + + if (!empty($updated_transaction['refunds'])) { + $refunds = $updated_transaction['refunds']; + } + + $this->model_extension_payment_squareup->updateTransaction($transaction_info['squareup_transaction_id'], $status, $refunds); + + $last_refund = array_pop($refunds); + + if ($last_refund) { + $refunded_amount = $this->currency->format( + $this->squareup->standardDenomination( + $last_refund['amount_money']['amount'], + $last_refund['amount_money']['currency'] + ), + $last_refund['amount_money']['currency'] + ); + + $comment = sprintf($this->language->get('text_refunded_amount'), $refunded_amount, $last_refund['status'], $last_refund['reason']); + + $json['order_history_data'] = array( + 'notify' => 1, + 'order_id' => $transaction_info['order_id'], + 'order_status_id' => $this->model_extension_payment_squareup->getOrderStatusId($transaction_info['order_id']), + 'comment' => $comment, + ); + + $json['success'] = $this->language->get('text_success_refund'); + } else { + $json['error'] = $this->language->get('error_no_refund'); + } + }); + } + + public function order() { + $this->load->language('extension/payment/squareup'); + + $data['url_list_transactions'] = html_entity_decode($this->url->link('extension/payment/squareup/transactions', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $this->request->get['order_id'] . '&page={PAGE}', true)); + $data['user_token'] = $this->session->data['user_token']; + $data['order_id'] = $this->request->get['order_id']; + + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + return $this->load->view('extension/payment/squareup_order', $data); + } + + public function install() { + $this->load->model('extension/payment/squareup'); + + $this->model_extension_payment_squareup->createTables(); + } + + public function uninstall() { + $this->load->model('extension/payment/squareup'); + + $this->model_extension_payment_squareup->dropTables(); + } + + public function recurringButtons() { + if (!$this->user->hasPermission('modify', 'sale/recurring')) { + return; + } + + $this->load->model('extension/payment/squareup'); + + $this->load->language('extension/payment/squareup'); + + if (isset($this->request->get['order_recurring_id'])) { + $order_recurring_id = $this->request->get['order_recurring_id']; + } else { + $order_recurring_id = 0; + } + + $recurring_info = $this->model_sale_recurring->getRecurring($order_recurring_id); + + $data['button_text'] = $this->language->get('button_cancel_recurring'); + + if ($recurring_info['status'] == ModelExtensionPaymentSquareup::RECURRING_ACTIVE) { + $data['order_recurring_id'] = $order_recurring_id; + } else { + $data['order_recurring_id'] = ''; + } + + $this->load->model('sale/order'); + + $order_info = $this->model_sale_order->getOrder($recurring_info['order_id']); + + $data['order_id'] = $recurring_info['order_id']; + $data['store_id'] = $order_info['store_id']; + $data['order_status_id'] = $order_info['order_status_id']; + $data['comment'] = $this->language->get('text_order_history_cancel'); + $data['notify'] = 1; + + $data['catalog'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG; + + // API login + $this->load->model('user/api'); + + $api_info = $this->model_user_api->getApi($this->config->get('config_api_id')); + + if ($api_info && $this->user->hasPermission('modify', 'sale/order')) { + $session = new Session($this->config->get('session_engine'), $this->registry); + + $session->start(); + + $this->model_user_api->deleteApiSessionBySessonId($session->getId()); + + $this->model_user_api->addApiSession($api_info['api_id'], $session->getId(), $this->request->server['REMOTE_ADDR']); + + $session->data['api_id'] = $api_info['api_id']; + + $data['api_token'] = $session->getId(); + } else { + $data['api_token'] = ''; + } + + $data['cancel'] = html_entity_decode($this->url->link('extension/payment/squareup/recurringCancel', 'order_recurring_id=' . $order_recurring_id . '&user_token=' . $this->session->data['user_token'], true)); + + return $this->load->view('extension/payment/squareup_recurring_buttons', $data); + } + + public function recurringCancel() { + $this->load->language('extension/payment/squareup'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'sale/recurring')) { + $json['error'] = $this->language->get('error_permission_recurring'); + } else { + $this->load->model('sale/recurring'); + + if (isset($this->request->get['order_recurring_id'])) { + $order_recurring_id = $this->request->get['order_recurring_id']; + } else { + $order_recurring_id = 0; + } + + $recurring_info = $this->model_sale_recurring->getRecurring($order_recurring_id); + + if ($recurring_info) { + $this->load->model('extension/payment/squareup'); + + $this->model_extension_payment_squareup->editOrderRecurringStatus($order_recurring_id, ModelExtensionPaymentSquareup::RECURRING_CANCELLED); + + $json['success'] = $this->language->get('text_canceled_success'); + + } else { + $json['error'] = $this->language->get('error_not_found'); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (empty($this->request->post['payment_squareup_client_id']) || strlen($this->request->post['payment_squareup_client_id']) > 32) { + $this->error['client_id'] = $this->language->get('error_client_id'); + } + + if (empty($this->request->post['payment_squareup_client_secret']) || strlen($this->request->post['payment_squareup_client_secret']) > 50) { + $this->error['client_secret'] = $this->language->get('error_client_secret'); + } + + if (!empty($this->request->post['payment_squareup_enable_sandbox'])) { + if (empty($this->request->post['payment_squareup_sandbox_client_id']) || strlen($this->request->post['payment_squareup_sandbox_client_id']) > 42) { + $this->error['sandbox_client_id'] = $this->language->get('error_sandbox_client_id'); + } + + if (empty($this->request->post['payment_squareup_sandbox_token']) || strlen($this->request->post['payment_squareup_sandbox_token']) > 42) { + $this->error['sandbox_token'] = $this->language->get('error_sandbox_token'); + } + + if ($this->config->get('payment_squareup_merchant_id') && !$this->config->get('payment_squareup_sandbox_locations')) { + $this->error['warning'] = $this->language->get('text_no_appropriate_locations_warning'); + } + + if ($this->config->get('payment_squareup_sandbox_locations') && isset($this->request->post['payment_squareup_sandbox_location_id']) && !in_array($this->request->post['payment_squareup_sandbox_location_id'], array_map(function($location) { + return $location['id']; + }, $this->config->get('payment_squareup_sandbox_locations')))) { + $this->error['location'] = $this->language->get('error_no_location_selected'); + } + } else { + if ($this->config->get('payment_squareup_merchant_id') && !$this->config->get('payment_squareup_locations')) { + $this->error['warning'] = $this->language->get('text_no_appropriate_locations_warning'); + } + + if ($this->config->get('payment_squareup_locations') && isset($this->request->post['payment_squareup_location_id']) && !in_array($this->request->post['payment_squareup_location_id'], array_map(function($location) { + return $location['id']; + }, $this->config->get('payment_squareup_locations')))) { + $this->error['location'] = $this->language->get('error_no_location_selected'); + } + } + + if (!empty($this->request->post['payment_squareup_cron_email_status'])) { + if (!filter_var($this->request->post['payment_squareup_cron_email'], FILTER_VALIDATE_EMAIL)) { + $this->error['cron_email'] = $this->language->get('error_invalid_email'); + } + } + + if (!isset($this->request->get['save_and_auth']) && empty($this->request->post['payment_squareup_cron_acknowledge'])) { + $this->error['cron_acknowledge'] = $this->language->get('error_cron_acknowledge'); + } + + if ($this->error && empty($this->error['warning'])) { + $this->error['warning'] = $this->language->get('error_form'); + } + + return !$this->error; + } + + protected function transactionAction($callback) { + $this->load->language('extension/payment/squareup'); + + $this->load->model('extension/payment/squareup'); + + $this->load->library('squareup'); + + $json = array(); + + if (!$this->user->hasPermission('modify', 'extension/payment/squareup')) { + $json['error'] = $this->language->get('error_permission'); + } + + if (isset($this->request->get['squareup_transaction_id'])) { + $squareup_transaction_id = $this->request->get['squareup_transaction_id']; + } else { + $squareup_transaction_id = 0; + } + + $transaction_info = $this->model_extension_payment_squareup->getTransaction($squareup_transaction_id); + + if (empty($transaction_info)) { + $json['error'] = $this->language->get('error_transaction_missing'); + } else { + try { + $callback($transaction_info, $json); + } catch (\Squareup\Exception $e) { + $json['error'] = $e->getMessage(); + } + } + + if (isset($this->request->get['preserve_alert'])) { + if (!empty($json['error'])) { + $this->pushAlert(array( + 'type' => 'danger', + 'icon' => 'exclamation-circle', + 'text' => $json['error'] + )); + } + + if (!empty($json['success'])) { + $this->pushAlert(array( + 'type' => 'success', + 'icon' => 'exclamation-circle', + 'text' => $json['success'] + )); + } + } + + $this->response->addHeader('Content-Type: application/json'); + $this->response->setOutput(json_encode($json)); + } + + protected function pushAlert($alert) { + $this->session->data['payment_squareup_alerts'][] = $alert; + } + + protected function pullAlerts() { + if (isset($this->session->data['payment_squareup_alerts'])) { + return $this->session->data['payment_squareup_alerts']; + } else { + return array(); + } + } + + protected function clearAlerts() { + unset($this->session->data['payment_squareup_alerts']); + } + + protected function getSettingValue($key, $default = null, $checkbox = false) { + if ($checkbox) { + if ($this->request->server['REQUEST_METHOD'] == 'POST' && !isset($this->request->post[$key])) { + return $default; + } else { + return $this->config->get($key); + } + } + + if (isset($this->request->post[$key])) { + return $this->request->post[$key]; + } else if ($this->config->has($key)) { + return $this->config->get($key); + } else { + return $default; + } + } + + protected function getValidationError($key) { + if (isset($this->error[$key])) { + return $this->error[$key]; + } else { + return ''; + } + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/twocheckout.php b/public/admin/controller/extension/payment/twocheckout.php new file mode 100644 index 0000000..38ff762 --- /dev/null +++ b/public/admin/controller/extension/payment/twocheckout.php @@ -0,0 +1,143 @@ +<?php +class ControllerExtensionPaymentTwoCheckout extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/twocheckout'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_twocheckout', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['account'])) { + $data['error_account'] = $this->error['account']; + } else { + $data['error_account'] = ''; + } + + if (isset($this->error['secret'])) { + $data['error_secret'] = $this->error['secret']; + } else { + $data['error_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/twocheckout', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/twocheckout', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_twocheckout_account'])) { + $data['payment_twocheckout_account'] = $this->request->post['payment_twocheckout_account']; + } else { + $data['payment_twocheckout_account'] = $this->config->get('payment_twocheckout_account'); + } + + if (isset($this->request->post['payment_twocheckout_secret'])) { + $data['payment_twocheckout_secret'] = $this->request->post['payment_twocheckout_secret']; + } else { + $data['payment_twocheckout_secret'] = $this->config->get('payment_twocheckout_secret'); + } + + if (isset($this->request->post['payment_twocheckout_display'])) { + $data['payment_twocheckout_display'] = $this->request->post['payment_twocheckout_display']; + } else { + $data['payment_twocheckout_display'] = $this->config->get('payment_twocheckout_display'); + } + + if (isset($this->request->post['payment_twocheckout_test'])) { + $data['payment_twocheckout_test'] = $this->request->post['payment_twocheckout_test']; + } else { + $data['payment_twocheckout_test'] = $this->config->get('payment_twocheckout_test'); + } + + if (isset($this->request->post['payment_twocheckout_total'])) { + $data['payment_twocheckout_total'] = $this->request->post['payment_twocheckout_total']; + } else { + $data['payment_twocheckout_total'] = $this->config->get('payment_twocheckout_total'); + } + + if (isset($this->request->post['payment_twocheckout_order_status_id'])) { + $data['payment_twocheckout_order_status_id'] = $this->request->post['payment_twocheckout_order_status_id']; + } else { + $data['payment_twocheckout_order_status_id'] = $this->config->get('payment_twocheckout_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_twocheckout_geo_zone_id'])) { + $data['payment_twocheckout_geo_zone_id'] = $this->request->post['payment_twocheckout_geo_zone_id']; + } else { + $data['payment_twocheckout_geo_zone_id'] = $this->config->get('payment_twocheckout_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_twocheckout_status'])) { + $data['payment_twocheckout_status'] = $this->request->post['payment_twocheckout_status']; + } else { + $data['payment_twocheckout_status'] = $this->config->get('payment_twocheckout_status'); + } + + if (isset($this->request->post['payment_twocheckout_sort_order'])) { + $data['payment_twocheckout_sort_order'] = $this->request->post['payment_twocheckout_sort_order']; + } else { + $data['payment_twocheckout_sort_order'] = $this->config->get('payment_twocheckout_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/twocheckout', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/twocheckout')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_twocheckout_account']) { + $this->error['account'] = $this->language->get('error_account'); + } + + if (!$this->request->post['payment_twocheckout_secret']) { + $this->error['secret'] = $this->language->get('error_secret'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/web_payment_software.php b/public/admin/controller/extension/payment/web_payment_software.php new file mode 100644 index 0000000..fa3a467 --- /dev/null +++ b/public/admin/controller/extension/payment/web_payment_software.php @@ -0,0 +1,142 @@ +<?php +class ControllerExtensionPaymentWebPaymentSoftware extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/web_payment_software'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_web_payment_software', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['login'])) { + $data['error_login'] = $this->error['login']; + } else { + $data['error_login'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/web_payment_software', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/web_payment_software', 'user_token=' . $this->session->data['user_token'], true); + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_web_payment_software_merchant_name'])) { + $data['payment_web_payment_software_merchant_name'] = $this->request->post['payment_web_payment_software_merchant_name']; + } else { + $data['payment_web_payment_software_merchant_name'] = $this->config->get('payment_web_payment_software_merchant_name'); + } + + if (isset($this->request->post['payment_web_payment_software_merchant_key'])) { + $data['payment_web_payment_software_merchant_key'] = $this->request->post['payment_web_payment_software_merchant_key']; + } else { + $data['payment_web_payment_software_merchant_key'] = $this->config->get('payment_web_payment_software_merchant_key'); + } + + if (isset($this->request->post['payment_web_payment_software_mode'])) { + $data['payment_web_payment_software_mode'] = $this->request->post['payment_web_payment_software_mode']; + } else { + $data['payment_web_payment_software_mode'] = $this->config->get('payment_web_payment_software_mode'); + } + + if (isset($this->request->post['payment_web_payment_software_method'])) { + $data['payment_web_payment_software_method'] = $this->request->post['payment_web_payment_software_method']; + } else { + $data['payment_web_payment_software_method'] = $this->config->get('payment_web_payment_software_method'); + } + + if (isset($this->request->post['payment_web_payment_software_order_status_id'])) { + $data['payment_web_payment_software_order_status_id'] = $this->request->post['payment_web_payment_software_order_status_id']; + } else { + $data['payment_web_payment_software_order_status_id'] = $this->config->get('payment_web_payment_software_order_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_web_payment_software_geo_zone_id'])) { + $data['payment_web_payment_software_geo_zone_id'] = $this->request->post['payment_web_payment_software_geo_zone_id']; + } else { + $data['payment_web_payment_software_geo_zone_id'] = $this->config->get('payment_web_payment_software_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_web_payment_software_status'])) { + $data['payment_web_payment_software_status'] = $this->request->post['payment_web_payment_software_status']; + } else { + $data['payment_web_payment_software_status'] = $this->config->get('payment_web_payment_software_status'); + } + + if (isset($this->request->post['payment_web_payment_software_total'])) { + $data['payment_web_payment_software_total'] = $this->request->post['payment_web_payment_software_total']; + } else { + $data['payment_web_payment_software_total'] = $this->config->get('payment_web_payment_software_total'); + } + + if (isset($this->request->post['payment_web_payment_software_sort_order'])) { + $data['payment_web_payment_software_sort_order'] = $this->request->post['payment_web_payment_software_sort_order']; + } else { + $data['payment_web_payment_software_sort_order'] = $this->config->get('payment_web_payment_software_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/web_payment_software', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/web_payment_software')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_web_payment_software_merchant_name']) { + $this->error['login'] = $this->language->get('error_login'); + } + + if (!$this->request->post['payment_web_payment_software_merchant_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/payment/wechat_pay.php b/public/admin/controller/extension/payment/wechat_pay.php new file mode 100644 index 0000000..754bb13 --- /dev/null +++ b/public/admin/controller/extension/payment/wechat_pay.php @@ -0,0 +1,177 @@ +<?php +/** + * @package OpenCart + * @author Meng Wenbin + * @copyright Copyright (c) 2010 - 2017, Chengdu Guangda Network Technology Co. Ltd. (https://www.opencart.cn/) + * @license https://opensource.org/licenses/GPL-3.0 + * @link https://www.opencart.cn + */ + +class ControllerExtensionPaymentWechatPay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/wechat_pay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_wechat_pay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['app_id'])) { + $data['error_app_id'] = $this->error['app_id']; + } else { + $data['error_app_id'] = ''; + } + + if (isset($this->error['app_secret'])) { + $data['error_app_secret'] = $this->error['app_secret']; + } else { + $data['error_app_secret'] = ''; + } + + if (isset($this->error['mch_id'])) { + $data['error_mch_id'] = $this->error['mch_id']; + } else { + $data['error_mch_id'] = ''; + } + + if (isset($this->error['api_secret'])) { + $data['error_api_secret'] = $this->error['api_secret']; + } else { + $data['error_api_secret'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/wechat_pay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/wechat_pay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_wechat_pay_app_id'])) { + $data['payment_wechat_pay_app_id'] = $this->request->post['payment_wechat_pay_app_id']; + } else { + $data['payment_wechat_pay_app_id'] = $this->config->get('payment_wechat_pay_app_id'); + } + + if (isset($this->request->post['payment_wechat_pay_app_secret'])) { + $data['payment_wechat_pay_app_secret'] = $this->request->post['payment_wechat_pay_app_secret']; + } else { + $data['payment_wechat_pay_app_secret'] = $this->config->get('payment_wechat_pay_app_secret'); + } + + if (isset($this->request->post['payment_wechat_pay_mch_id'])) { + $data['payment_wechat_pay_mch_id'] = $this->request->post['payment_wechat_pay_mch_id']; + } else { + $data['payment_wechat_pay_mch_id'] = $this->config->get('payment_wechat_pay_mch_id'); + } + + if (isset($this->request->post['payment_wechat_pay_api_secret'])) { + $data['payment_wechat_pay_api_secret'] = $this->request->post['payment_wechat_pay_api_secret']; + } else { + $data['payment_wechat_pay_api_secret'] = $this->config->get('payment_wechat_pay_api_secret'); + } + + if (isset($this->request->post['payment_wechat_pay_total'])) { + $data['payment_wechat_pay_total'] = $this->request->post['payment_wechat_pay_total']; + } else { + $data['payment_wechat_pay_total'] = $this->config->get('payment_wechat_pay_total'); + } + + if (isset($this->request->post['payment_wechat_pay_currency'])) { + $data['payment_wechat_pay_currency'] = $this->request->post['payment_wechat_pay_currency']; + } else { + $data['payment_wechat_pay_currency'] = $this->config->get('payment_wechat_pay_currency'); + } + + if (isset($this->request->post['payment_wechat_pay_completed_status_id'])) { + $data['payment_wechat_pay_completed_status_id'] = $this->request->post['payment_wechat_pay_completed_status_id']; + } else { + $data['payment_wechat_pay_completed_status_id'] = $this->config->get('payment_wechat_pay_completed_status_id'); + } + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_wechat_pay_geo_zone_id'])) { + $data['payment_wechat_pay_geo_zone_id'] = $this->request->post['payment_wechat_pay_geo_zone_id']; + } else { + $data['payment_wechat_pay_geo_zone_id'] = $this->config->get('payment_wechat_pay_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['payment_wechat_pay_status'])) { + $data['payment_wechat_pay_status'] = $this->request->post['payment_wechat_pay_status']; + } else { + $data['payment_wechat_pay_status'] = $this->config->get('payment_wechat_pay_status'); + } + + if (isset($this->request->post['payment_wechat_pay_sort_order'])) { + $data['payment_wechat_pay_sort_order'] = $this->request->post['payment_wechat_pay_sort_order']; + } else { + $data['payment_wechat_pay_sort_order'] = $this->config->get('payment_wechat_pay_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/wechat_pay', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/wechat_pay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_wechat_pay_app_id']) { + $this->error['app_id'] = $this->language->get('error_app_id'); + } + + if (!$this->request->post['payment_wechat_pay_app_secret']) { + $this->error['app_secret'] = $this->language->get('error_app_secret'); + } + + if (!$this->request->post['payment_wechat_pay_mch_id']) { + $this->error['mch_id'] = $this->language->get('error_mch_id'); + } + + if (!$this->request->post['payment_wechat_pay_api_secret']) { + $this->error['api_secret'] = $this->language->get('error_api_secret'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/payment/worldpay.php b/public/admin/controller/extension/payment/worldpay.php new file mode 100644 index 0000000..d421bab --- /dev/null +++ b/public/admin/controller/extension/payment/worldpay.php @@ -0,0 +1,287 @@ +<?php +class ControllerExtensionPaymentWorldpay extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/payment/worldpay'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('payment_worldpay', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true)); + } + + if (isset($this->error['error_service_key'])) { + $data['error_service_key'] = $this->error['error_service_key']; + } else { + $data['error_service_key'] = ''; + } + + if (isset($this->error['error_client_key'])) { + $data['error_client_key'] = $this->error['error_client_key']; + } else { + $data['error_client_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/payment/worldpay', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/payment/worldpay', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=payment', true); + + if (isset($this->request->post['payment_worldpay_service_key'])) { + $data['payment_worldpay_service_key'] = $this->request->post['payment_worldpay_service_key']; + } else { + $data['payment_worldpay_service_key'] = $this->config->get('payment_worldpay_service_key'); + } + + if (isset($this->request->post['payment_worldpay_client_key'])) { + $data['payment_worldpay_client_key'] = $this->request->post['payment_worldpay_client_key']; + } else { + $data['payment_worldpay_client_key'] = $this->config->get('payment_worldpay_client_key'); + } + + if (isset($this->request->post['payment_worldpay_total'])) { + $data['payment_worldpay_total'] = $this->request->post['payment_worldpay_total']; + } else { + $data['payment_worldpay_total'] = $this->config->get('payment_worldpay_total'); + } + + if (isset($this->request->post['payment_worldpay_card'])) { + $data['payment_worldpay_card'] = $this->request->post['payment_worldpay_card']; + } else { + $data['payment_worldpay_card'] = $this->config->get('payment_worldpay_card'); + } + + if (isset($this->request->post['payment_worldpay_order_status_id'])) { + $data['payment_worldpay_order_status_id'] = $this->request->post['payment_worldpay_order_status_id']; + } else { + $data['payment_worldpay_order_status_id'] = $this->config->get('payment_worldpay_order_status_id'); + } + + if (isset($this->request->post['payment_worldpay_geo_zone_id'])) { + $data['payment_worldpay_geo_zone_id'] = $this->request->post['payment_worldpay_geo_zone_id']; + } else { + $data['payment_worldpay_geo_zone_id'] = $this->config->get('payment_worldpay_geo_zone_id'); + } + + if (isset($this->request->post['payment_worldpay_status'])) { + $data['payment_worldpay_status'] = $this->request->post['payment_worldpay_status']; + } else { + $data['payment_worldpay_status'] = $this->config->get('payment_worldpay_status'); + } + + if (isset($this->request->post['payment_worldpay_debug'])) { + $data['payment_worldpay_debug'] = $this->request->post['payment_worldpay_debug']; + } else { + $data['payment_worldpay_debug'] = $this->config->get('payment_worldpay_debug'); + } + + if (isset($this->request->post['payment_worldpay_sort_order'])) { + $data['payment_worldpay_sort_order'] = $this->request->post['payment_worldpay_sort_order']; + } else { + $data['payment_worldpay_sort_order'] = $this->config->get('payment_worldpay_sort_order'); + } + + if (isset($this->request->post['payment_worldpay_secret_token'])) { + $data['payment_worldpay_secret_token'] = $this->request->post['payment_worldpay_secret_token']; + } elseif ($this->config->get('payment_worldpay_secret_token')) { + $data['payment_worldpay_secret_token'] = $this->config->get('payment_worldpay_secret_token'); + } else { + $data['payment_worldpay_secret_token'] = sha1(uniqid(mt_rand(), 1)); + } + + $data['payment_worldpay_webhook_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/worldpay/webhook&token=' . $data['payment_worldpay_secret_token']; + + $data['payment_worldpay_cron_job_url'] = HTTPS_CATALOG . 'index.php?route=extension/payment/worldpay/cron&token=' . $data['payment_worldpay_secret_token']; + + if ($this->config->get('payment_worldpay_last_cron_job_run')) { + $data['payment_worldpay_last_cron_job_run'] = $this->config->get('payment_worldpay_last_cron_job_run'); + } else { + $data['payment_worldpay_last_cron_job_run'] = ''; + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + if (isset($this->request->post['payment_worldpay_success_status_id'])) { + $data['payment_worldpay_success_status_id'] = $this->request->post['payment_worldpay_success_status_id']; + } else { + $data['payment_worldpay_success_status_id'] = $this->config->get('payment_worldpay_success_status_id'); + } + + if (isset($this->request->post['payment_worldpay_failed_status_id'])) { + $data['payment_worldpay_failed_status_id'] = $this->request->post['payment_worldpay_failed_status_id']; + } else { + $data['payment_worldpay_failed_status_id'] = $this->config->get('payment_worldpay_failed_status_id'); + } + + if (isset($this->request->post['payment_worldpay_settled_status_id'])) { + $data['payment_worldpay_settled_status_id'] = $this->request->post['payment_worldpay_settled_status_id']; + } else { + $data['payment_worldpay_settled_status_id'] = $this->config->get('payment_worldpay_settled_status_id'); + } + + if (isset($this->request->post['payment_worldpay_refunded_status_id'])) { + $data['payment_worldpay_refunded_status_id'] = $this->request->post['payment_worldpay_refunded_status_id']; + } else { + $data['payment_worldpay_refunded_status_id'] = $this->config->get('payment_worldpay_refunded_status_id'); + } + + if (isset($this->request->post['payment_worldpay_partially_refunded_status_id'])) { + $data['payment_worldpay_partially_refunded_status_id'] = $this->request->post['payment_worldpay_partially_refunded_status_id']; + } else { + $data['payment_worldpay_partially_refunded_status_id'] = $this->config->get('payment_worldpay_partially_refunded_status_id'); + } + + if (isset($this->request->post['payment_worldpay_charged_back_status_id'])) { + $data['payment_worldpay_charged_back_status_id'] = $this->request->post['payment_worldpay_charged_back_status_id']; + } else { + $data['payment_worldpay_charged_back_status_id'] = $this->config->get('payment_worldpay_charged_back_status_id'); + } + + if (isset($this->request->post['payment_worldpay_information_requested_status_id'])) { + $data['payment_worldpay_information_requested_status_id'] = $this->request->post['payment_worldpay_information_requested_status_id']; + } else { + $data['payment_worldpay_information_requested_status_id'] = $this->config->get('payment_worldpay_information_requested_status_id'); + } + + if (isset($this->request->post['payment_worldpay_information_supplied_status_id'])) { + $data['payment_worldpay_information_supplied_status_id'] = $this->request->post['payment_worldpay_information_supplied_status_id']; + } else { + $data['payment_worldpay_information_supplied_status_id'] = $this->config->get('payment_worldpay_information_supplied_status_id'); + } + + if (isset($this->request->post['payment_worldpay_chargeback_reversed_status_id'])) { + $data['payment_worldpay_chargeback_reversed_status_id'] = $this->request->post['payment_worldpay_chargeback_reversed_status_id']; + } else { + $data['payment_worldpay_chargeback_reversed_status_id'] = $this->config->get('payment_worldpay_chargeback_reversed_status_id'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/payment/worldpay', $data)); + } + + public function install() { + $this->load->model('extension/payment/worldpay'); + $this->model_extension_payment_worldpay->install(); + } + + public function uninstall() { + $this->load->model('extension/payment/worldpay'); + $this->model_extension_payment_worldpay->uninstall(); + } + + public function order() { + + if ($this->config->get('payment_worldpay_status')) { + + $this->load->model('extension/payment/worldpay'); + + $worldpay_order = $this->model_extension_payment_worldpay->getOrder($this->request->get['order_id']); + + if (!empty($worldpay_order)) { + $this->load->language('extension/payment/worldpay'); + + $worldpay_order['total_released'] = $this->model_extension_payment_worldpay->getTotalReleased($worldpay_order['worldpay_order_id']); + + $worldpay_order['total_formatted'] = $this->currency->format($worldpay_order['total'], $worldpay_order['currency_code'], false); + $worldpay_order['total_released_formatted'] = $this->currency->format($worldpay_order['total_released'], $worldpay_order['currency_code'], false); + + $data['worldpay_order'] = $worldpay_order; + + $data['order_id'] = $this->request->get['order_id']; + + $data['user_token'] = $this->request->get['user_token']; + + return $this->load->view('extension/payment/worldpay_order', $data); + } + } + } + + public function refund() { + $this->load->language('extension/payment/worldpay'); + $json = array(); + + if (isset($this->request->post['order_id']) && !empty($this->request->post['order_id'])) { + $this->load->model('extension/payment/worldpay'); + + $worldpay_order = $this->model_extension_payment_worldpay->getOrder($this->request->post['order_id']); + + $refund_response = $this->model_extension_payment_worldpay->refund($this->request->post['order_id'], $this->request->post['amount']); + + $this->model_extension_payment_worldpay->logger('Refund result: ' . print_r($refund_response, 1)); + + if ($refund_response['status'] == 'success') { + $this->model_extension_payment_worldpay->addTransaction($worldpay_order['worldpay_order_id'], 'refund', $this->request->post['amount'] * -1); + + $total_refunded = $this->model_extension_payment_worldpay->getTotalRefunded($worldpay_order['worldpay_order_id']); + $total_released = $this->model_extension_payment_worldpay->getTotalReleased($worldpay_order['worldpay_order_id']); + + $this->model_extension_payment_worldpay->updateRefundStatus($worldpay_order['worldpay_order_id'], 1); + + $json['msg'] = $this->language->get('text_refund_ok_order'); + $json['data'] = array(); + $json['data']['created'] = date("Y-m-d H:i:s"); + $json['data']['amount'] = $this->currency->format(($this->request->post['amount'] * -1), $worldpay_order['currency_code'], false); + $json['data']['total_released'] = $this->currency->format($total_released, $worldpay_order['currency_code'], false); + $json['data']['total_refund'] = $this->currency->format($total_refunded, $worldpay_order['currency_code'], false); + $json['data']['refund_status'] = 1; + $json['error'] = false; + } else { + $json['error'] = true; + $json['msg'] = isset($refund_response['message']) && !empty($refund_response['message']) ? (string)$refund_response['message'] : 'Unable to refund'; + } + } else { + $json['error'] = true; + $json['msg'] = 'Missing data'; + } + + $this->response->setOutput(json_encode($json)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/payment/worldpay')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['payment_worldpay_service_key']) { + $this->error['error_service_key'] = $this->language->get('error_service_key'); + } + + if (!$this->request->post['payment_worldpay_client_key']) { + $this->error['error_client_key'] = $this->language->get('error_client_key'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/report/customer_activity.php b/public/admin/controller/extension/report/customer_activity.php new file mode 100644 index 0000000..0d95a51 --- /dev/null +++ b/public/admin/controller/extension/report/customer_activity.php @@ -0,0 +1,179 @@ +<?php +class ControllerExtensionReportCustomerActivity extends Controller { + public function index() { + $this->load->language('extension/report/customer_activity'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_activity', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_activity', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_activity', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_activity_status'])) { + $data['report_customer_activity_status'] = $this->request->post['report_customer_activity_status']; + } else { + $data['report_customer_activity_status'] = $this->config->get('report_customer_activity_status'); + } + + if (isset($this->request->post['report_customer_activity_sort_order'])) { + $data['report_customer_activity_sort_order'] = $this->request->post['report_customer_activity_sort_order']; + } else { + $data['report_customer_activity_sort_order'] = $this->config->get('report_customer_activity_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_activity_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_activity')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_activity'); + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_ip'])) { + $filter_ip = $this->request->get['filter_ip']; + } else { + $filter_ip = ''; + } + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer'); + + $data['activities'] = array(); + + $filter_data = array( + 'filter_customer' => $filter_customer, + 'filter_ip' => $filter_ip, + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'start' => ($page - 1) * 20, + 'limit' => 20 + ); + + $activity_total = $this->model_extension_report_customer->getTotalCustomerActivities($filter_data); + + $results = $this->model_extension_report_customer->getCustomerActivities($filter_data); + + foreach ($results as $result) { + $comment = vsprintf($this->language->get('text_activity_' . $result['key']), json_decode($result['data'], true)); + + $find = array( + 'customer_id=', + 'order_id=' + ); + + $replace = array( + $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=', true), + $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=', true) + ); + + $data['activities'][] = array( + 'comment' => str_replace($find, $replace, $comment), + 'ip' => $result['ip'], + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + $pagination = new Pagination(); + $pagination->total = $activity_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_activity' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($activity_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($activity_total - $this->config->get('config_limit_admin'))) ? $activity_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $activity_total, ceil($activity_total / $this->config->get('config_limit_admin'))); + + $data['filter_customer'] = $filter_customer; + $data['filter_ip'] = $filter_ip; + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + + return $this->load->view('extension/report/customer_activity_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/customer_order.php b/public/admin/controller/extension/report/customer_order.php new file mode 100644 index 0000000..82f127b --- /dev/null +++ b/public/admin/controller/extension/report/customer_order.php @@ -0,0 +1,176 @@ +<?php +class ControllerExtensionReportCustomerOrder extends Controller { + public function index() { + $this->load->language('extension/report/customer_order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_order', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_order', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_order', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_order_status'])) { + $data['report_customer_order_status'] = $this->request->post['report_customer_order_status']; + } else { + $data['report_customer_order_status'] = $this->config->get('report_customer_order_status'); + } + + if (isset($this->request->post['report_customer_order_sort_order'])) { + $data['report_customer_order_sort_order'] = $this->request->post['report_customer_order_sort_order']; + } else { + $data['report_customer_order_sort_order'] = $this->config->get('report_customer_order_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_order_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_order')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_order'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $filter_order_status_id = $this->request->get['filter_order_status_id']; + } else { + $filter_order_status_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer'); + + $data['customers'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_customer' => $filter_customer, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_total = $this->model_extension_report_customer->getTotalOrders($filter_data); + + $results = $this->model_extension_report_customer->getOrders($filter_data); + + foreach ($results as $result) { + $data['customers'][] = array( + 'customer' => $result['customer'], + 'email' => $result['email'], + 'customer_group' => $result['customer_group'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'orders' => $result['orders'], + 'products' => $result['products'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $customer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_order' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_customer'] = $filter_customer; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/customer_order_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/customer_reward.php b/public/admin/controller/extension/report/customer_reward.php new file mode 100644 index 0000000..b7a67c9 --- /dev/null +++ b/public/admin/controller/extension/report/customer_reward.php @@ -0,0 +1,160 @@ +<?php +class ControllerExtensionReportCustomerReward extends Controller { + public function index() { + $this->load->language('extension/report/customer_reward'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_reward', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_reward', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_reward', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_reward_status'])) { + $data['report_customer_reward_status'] = $this->request->post['report_customer_reward_status']; + } else { + $data['report_customer_reward_status'] = $this->config->get('report_customer_reward_status'); + } + + if (isset($this->request->post['report_customer_reward_sort_order'])) { + $data['report_customer_reward_sort_order'] = $this->request->post['report_customer_reward_sort_order']; + } else { + $data['report_customer_reward_sort_order'] = $this->config->get('report_customer_reward_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_reward_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_reward')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_reward'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer'); + + $data['customers'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_customer' => $filter_customer, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_total = $this->model_extension_report_customer->getTotalRewardPoints($filter_data); + + $results = $this->model_extension_report_customer->getRewardPoints($filter_data); + + foreach ($results as $result) { + $data['customers'][] = array( + 'customer' => $result['customer'], + 'email' => $result['email'], + 'customer_group' => $result['customer_group'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'points' => $result['points'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + $pagination = new Pagination(); + $pagination->total = $customer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_reward' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_customer'] = $filter_customer; + + return $this->load->view('extension/report/customer_reward_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/customer_search.php b/public/admin/controller/extension/report/customer_search.php new file mode 100644 index 0000000..6a2aa63 --- /dev/null +++ b/public/admin/controller/extension/report/customer_search.php @@ -0,0 +1,201 @@ +<?php +class ControllerExtensionReportCustomerSearch extends Controller { + public function index() { + $this->load->language('extension/report/customer_search'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_search', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_search', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_search', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_search_status'])) { + $data['report_customer_search_status'] = $this->request->post['report_customer_search_status']; + } else { + $data['report_customer_search_status'] = $this->config->get('report_customer_search_status'); + } + + if (isset($this->request->post['report_customer_search_sort_order'])) { + $data['report_customer_search_sort_order'] = $this->request->post['report_customer_search_sort_order']; + } else { + $data['report_customer_search_sort_order'] = $this->config->get('report_customer_search_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_search_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_search')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_search'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_keyword'])) { + $filter_keyword = $this->request->get['filter_keyword']; + } else { + $filter_keyword = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['filter_ip'])) { + $filter_ip = $this->request->get['filter_ip']; + } else { + $filter_ip = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer'); + $this->load->model('catalog/category'); + + $data['searches'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_keyword' => $filter_keyword, + 'filter_customer' => $filter_customer, + 'filter_ip' => $filter_ip, + 'start' => ($page - 1) * 20, + 'limit' => 20 + ); + + $search_total = $this->model_extension_report_customer->getTotalCustomerSearches($filter_data); + + $results = $this->model_extension_report_customer->getCustomerSearches($filter_data); + + foreach ($results as $result) { + $category_info = $this->model_catalog_category->getCategory($result['category_id']); + + if ($category_info) { + $category = ($category_info['path']) ? $category_info['path'] . ' > ' . $category_info['name'] : $category_info['name']; + } else { + $category = ''; + } + + if ($result['customer_id'] > 0) { + $customer = sprintf($this->language->get('text_customer'), $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true), $result['customer']); + } else { + $customer = $this->language->get('text_guest'); + } + + $data['searches'][] = array( + 'keyword' => $result['keyword'], + 'products' => $result['products'], + 'category' => $category, + 'customer' => $customer, + 'ip' => $result['ip'], + 'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_keyword'])) { + $url .= '&filter_keyword=' . urlencode($this->request->get['filter_keyword']); + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + if (isset($this->request->get['filter_ip'])) { + $url .= '&filter_ip=' . $this->request->get['filter_ip']; + } + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $pagination = new Pagination(); + $pagination->total = $search_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_search' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($search_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($search_total - $this->config->get('config_limit_admin'))) ? $search_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $search_total, ceil($search_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_keyword'] = $filter_keyword; + $data['filter_customer'] = $filter_customer; + $data['filter_ip'] = $filter_ip; + + return $this->load->view('extension/report/customer_search_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/customer_transaction.php b/public/admin/controller/extension/report/customer_transaction.php new file mode 100644 index 0000000..1657d34 --- /dev/null +++ b/public/admin/controller/extension/report/customer_transaction.php @@ -0,0 +1,158 @@ +<?php +class ControllerExtensionReportCustomerTransaction extends Controller { + public function index() { + $this->load->language('extension/report/customer_transaction'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_customer_transaction', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/customer_transaction', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/customer_transaction', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_customer_transaction_status'])) { + $data['report_customer_transaction_status'] = $this->request->post['report_customer_transaction_status']; + } else { + $data['report_customer_transaction_status'] = $this->config->get('report_customer_transaction_status'); + } + + if (isset($this->request->post['report_customer_transaction_sort_order'])) { + $data['report_customer_transaction_sort_order'] = $this->request->post['report_customer_transaction_sort_order']; + } else { + $data['report_customer_transaction_sort_order'] = $this->config->get('report_customer_transaction_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/customer_transaction_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/customer_transaction')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/customer_transaction'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_customer'])) { + $filter_customer = $this->request->get['filter_customer']; + } else { + $filter_customer = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/customer_transaction'); + + $data['customers'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_customer' => $filter_customer, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $customer_total = $this->model_extension_report_customer_transaction->getTotalTransactions($filter_data); + + $results = $this->model_extension_report_customer_transaction->getTransactions($filter_data); + + foreach ($results as $result) { + $data['customers'][] = array( + 'customer' => $result['customer'], + 'email' => $result['email'], + 'customer_group' => $result['customer_group'], + 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_customer'])) { + $url .= '&filter_customer=' . urlencode($this->request->get['filter_customer']); + } + + $pagination = new Pagination(); + $pagination->total = $customer_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=customer_transaction' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_customer'] = $filter_customer; + + return $this->load->view('extension/report/customer_transaction_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/marketing.php b/public/admin/controller/extension/report/marketing.php new file mode 100644 index 0000000..1d8f465 --- /dev/null +++ b/public/admin/controller/extension/report/marketing.php @@ -0,0 +1,162 @@ +<?php +class ControllerExtensionReportMarketing extends Controller { + public function index() { + $this->load->language('extension/report/marketing'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_marketing', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/marketing', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/marketing', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_marketing_status'])) { + $data['report_marketing_status'] = $this->request->post['report_marketing_status']; + } else { + $data['report_marketing_status'] = $this->config->get('report_marketing_status'); + } + + if (isset($this->request->post['report_marketing_sort_order'])) { + $data['report_marketing_sort_order'] = $this->request->post['report_marketing_sort_order']; + } else { + $data['report_marketing_sort_order'] = $this->config->get('report_marketing_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/marketing_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/marketing')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/marketing'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $filter_order_status_id = $this->request->get['filter_order_status_id']; + } else { + $filter_order_status_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/marketing'); + + $data['marketings'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $marketing_total = $this->model_extension_report_marketing->getTotalMarketing($filter_data); + + $results = $this->model_extension_report_marketing->getMarketing($filter_data); + + foreach ($results as $result) { + $data['marketings'][] = array( + 'campaign' => $result['campaign'], + 'code' => $result['code'], + 'clicks' => $result['clicks'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'action' => $this->url->link('marketing/marketing/edit', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $result['marketing_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $marketing_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=marketing' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($marketing_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($marketing_total - $this->config->get('config_limit_admin'))) ? $marketing_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $marketing_total, ceil($marketing_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/marketing_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/product_purchased.php b/public/admin/controller/extension/report/product_purchased.php new file mode 100644 index 0000000..405da7d --- /dev/null +++ b/public/admin/controller/extension/report/product_purchased.php @@ -0,0 +1,160 @@ +<?php +class ControllerExtensionReportProductPurchased extends Controller { + public function index() { + $this->load->language('extension/report/product_purchased'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_product_purchased', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/product_purchased', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/product_purchased', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_product_purchased_status'])) { + $data['report_product_purchased_status'] = $this->request->post['report_product_purchased_status']; + } else { + $data['report_product_purchased_status'] = $this->config->get('report_product_purchased_status'); + } + + if (isset($this->request->post['report_product_purchased_sort_order'])) { + $data['report_product_purchased_sort_order'] = $this->request->post['report_product_purchased_sort_order']; + } else { + $data['report_product_purchased_sort_order'] = $this->config->get('report_product_purchased_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/product_purchased_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/product_purchased')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/product_purchased'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $filter_order_status_id = $this->request->get['filter_order_status_id']; + } else { + $filter_order_status_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/product'); + + $data['products'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $product_total = $this->model_extension_report_product->getTotalPurchased($filter_data); + + $results = $this->model_extension_report_product->getPurchased($filter_data); + + foreach ($results as $result) { + $data['products'][] = array( + 'name' => $result['name'], + 'model' => $result['model'], + 'quantity' => $result['quantity'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=product_purchased' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/product_purchased_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/product_viewed.php b/public/admin/controller/extension/report/product_viewed.php new file mode 100644 index 0000000..4afa4fe --- /dev/null +++ b/public/admin/controller/extension/report/product_viewed.php @@ -0,0 +1,149 @@ +<?php +class ControllerExtensionReportProductViewed extends Controller { + public function index() { + $this->load->language('extension/report/product_viewed'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_product_viewed', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/product_viewed', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/product_viewed', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_product_viewed_status'])) { + $data['report_product_viewed_status'] = $this->request->post['report_product_viewed_status']; + } else { + $data['report_product_viewed_status'] = $this->config->get('report_product_viewed_status'); + } + + if (isset($this->request->post['report_product_viewed_sort_order'])) { + $data['report_product_viewed_sort_order'] = $this->request->post['report_product_viewed_sort_order']; + } else { + $data['report_product_viewed_sort_order'] = $this->config->get('report_product_viewed_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/product_viewed_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/product_viewed')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/product_viewed'); + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $data['reset'] = $this->url->link('extension/report/product_viewed/reset', 'user_token=' . $this->session->data['user_token'] . '&page={page}', true); + + $this->load->model('extension/report/product'); + + $filter_data = array( + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $data['products'] = array(); + + $product_viewed_total = $this->model_extension_report_product->getTotalProductViews(); + + $product_total = $this->model_extension_report_product->getTotalProductsViewed(); + + $results = $this->model_extension_report_product->getProductsViewed($filter_data); + + foreach ($results as $result) { + if ($result['viewed']) { + $percent = round($result['viewed'] / $product_viewed_total * 100, 2); + } else { + $percent = 0; + } + + $data['products'][] = array( + 'name' => $result['name'], + 'model' => $result['model'], + 'viewed' => $result['viewed'], + 'percent' => $percent . '%' + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['page'])) { + $url .= '&page=' . $this->request->get['page']; + } + + $pagination = new Pagination(); + $pagination->total = $product_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=product_viewed&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); + + return $this->load->view('extension/report/product_viewed_info', $data); + } + + public function reset() { + $this->load->language('extension/report/product_viewed'); + + if (!$this->user->hasPermission('modify', 'extension/report/product_viewed')) { + $this->session->data['error'] = $this->language->get('error_permission'); + } else { + $this->load->model('extension/report/product'); + + $this->model_extension_report_product->reset(); + + $this->session->data['success'] = $this->language->get('text_success'); + } + + $this->response->redirect($this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=product_viewed' . $url, true)); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_coupon.php b/public/admin/controller/extension/report/sale_coupon.php new file mode 100644 index 0000000..aebab08 --- /dev/null +++ b/public/admin/controller/extension/report/sale_coupon.php @@ -0,0 +1,145 @@ +<?php +class ControllerExtensionReportSaleCoupon extends Controller { + public function index() { + $this->load->language('extension/report/sale_coupon'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_coupon', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_coupon', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_coupon', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_coupon_status'])) { + $data['report_sale_coupon_status'] = $this->request->post['report_sale_coupon_status']; + } else { + $data['report_sale_coupon_status'] = $this->config->get('report_sale_coupon_status'); + } + + if (isset($this->request->post['report_sale_coupon_sort_order'])) { + $data['report_sale_coupon_sort_order'] = $this->request->post['report_sale_coupon_sort_order']; + } else { + $data['report_sale_coupon_sort_order'] = $this->config->get('report_sale_coupon_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_coupon_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_coupon')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_coupon'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/coupon'); + + $data['coupons'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $coupon_total = $this->model_extension_report_coupon->getTotalCoupons($filter_data); + + $results = $this->model_extension_report_coupon->getCoupons($filter_data); + + foreach ($results as $result) { + $data['coupons'][] = array( + 'name' => $result['name'], + 'code' => $result['code'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')), + 'edit' => $this->url->link('marketing/coupon/edit', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $result['coupon_id'], true) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + $pagination = new Pagination(); + $pagination->total = $coupon_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_coupon' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($coupon_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($coupon_total - $this->config->get('config_limit_admin'))) ? $coupon_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $coupon_total, ceil($coupon_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + + return $this->load->view('extension/report/sale_coupon_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_order.php b/public/admin/controller/extension/report/sale_order.php new file mode 100644 index 0000000..e718ce8 --- /dev/null +++ b/public/admin/controller/extension/report/sale_order.php @@ -0,0 +1,196 @@ +<?php +class ControllerExtensionReportSaleOrder extends Controller { + public function index() { + $this->load->language('extension/report/sale_order'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_order', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_order', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_order', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_order_status'])) { + $data['report_sale_order_status'] = $this->request->post['report_sale_order_status']; + } else { + $data['report_sale_order_status'] = $this->config->get('report_sale_order_status'); + } + + if (isset($this->request->post['report_sale_order_sort_order'])) { + $data['report_sale_order_sort_order'] = $this->request->post['report_sale_order_sort_order']; + } else { + $data['report_sale_order_sort_order'] = $this->config->get('report_sale_order_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_order_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_order')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_order'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = date('Y-m-d', strtotime(date('Y') . '-' . date('m') . '-01')); + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = date('Y-m-d'); + } + + if (isset($this->request->get['filter_group'])) { + $filter_group = $this->request->get['filter_group']; + } else { + $filter_group = 'week'; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $filter_order_status_id = $this->request->get['filter_order_status_id']; + } else { + $filter_order_status_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/sale'); + + $data['orders'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_group' => $filter_group, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_total = $this->model_extension_report_sale->getTotalOrders($filter_data); + + $results = $this->model_extension_report_sale->getOrders($filter_data); + + foreach ($results as $result) { + $data['orders'][] = array( + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'orders' => $result['orders'], + 'products' => $result['products'], + 'tax' => $this->currency->format($result['tax'], $this->config->get('config_currency')), + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['groups'] = array(); + + $data['groups'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day', + ); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_group'])) { + $url .= '&filter_group=' . $this->request->get['filter_group']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $order_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_order' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($order_total - $this->config->get('config_limit_admin'))) ? $order_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $order_total, ceil($order_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_group'] = $filter_group; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/sale_order_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_return.php b/public/admin/controller/extension/report/sale_return.php new file mode 100644 index 0000000..85f5767 --- /dev/null +++ b/public/admin/controller/extension/report/sale_return.php @@ -0,0 +1,193 @@ +<?php +class ControllerExtensionReportSaleReturn extends Controller { + public function index() { + $this->load->language('extension/report/sale_return'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_return', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_return', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_return', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_return_status'])) { + $data['report_sale_return_status'] = $this->request->post['report_sale_return_status']; + } else { + $data['report_sale_return_status'] = $this->config->get('report_sale_return_status'); + } + + if (isset($this->request->post['report_sale_return_sort_order'])) { + $data['report_sale_return_sort_order'] = $this->request->post['report_sale_return_sort_order']; + } else { + $data['report_sale_return_sort_order'] = $this->config->get('report_sale_return_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_return_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_return')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_return'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_group'])) { + $filter_group = $this->request->get['filter_group']; + } else { + $filter_group = 'week'; + } + + if (isset($this->request->get['filter_return_status_id'])) { + $filter_return_status_id = $this->request->get['filter_return_status_id']; + } else { + $filter_return_status_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/return'); + + $data['returns'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_group' => $filter_group, + 'filter_return_status_id' => $filter_return_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $return_total = $this->model_extension_report_return->getTotalReturns($filter_data); + + $results = $this->model_extension_report_return->getReturns($filter_data); + + foreach ($results as $result) { + $data['returns'][] = array( + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'returns' => $result['returns'] + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/return_status'); + + $data['return_statuses'] = $this->model_localisation_return_status->getReturnStatuses(); + + $data['groups'] = array(); + + $data['groups'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day', + ); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_group'])) { + $url .= '&filter_group=' . $this->request->get['filter_group']; + } + + if (isset($this->request->get['filter_return_status_id'])) { + $url .= '&filter_return_status_id=' . $this->request->get['filter_return_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $return_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_return' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($return_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_total - $this->config->get('config_limit_admin'))) ? $return_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_total, ceil($return_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_group'] = $filter_group; + $data['filter_return_status_id'] = $filter_return_status_id; + + return $this->load->view('extension/report/sale_return_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_shipping.php b/public/admin/controller/extension/report/sale_shipping.php new file mode 100644 index 0000000..5f56fdc --- /dev/null +++ b/public/admin/controller/extension/report/sale_shipping.php @@ -0,0 +1,195 @@ +<?php +class ControllerExtensionReportSaleShipping extends Controller { + public function index() { + $this->load->language('extension/report/sale_shipping'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_shipping', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_shipping', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_shipping', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_shipping_status'])) { + $data['report_sale_shipping_status'] = $this->request->post['report_sale_shipping_status']; + } else { + $data['report_sale_shipping_status'] = $this->config->get('report_sale_shipping_status'); + } + + if (isset($this->request->post['report_sale_shipping_sort_order'])) { + $data['report_sale_shipping_sort_order'] = $this->request->post['report_sale_shipping_sort_order']; + } else { + $data['report_sale_shipping_sort_order'] = $this->config->get('report_sale_shipping_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_shipping_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_shipping')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_shipping'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_group'])) { + $filter_group = $this->request->get['filter_group']; + } else { + $filter_group = 'week'; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $filter_order_status_id = $this->request->get['filter_order_status_id']; + } else { + $filter_order_status_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/sale'); + + $data['orders'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_group' => $filter_group, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_total = $this->model_extension_report_sale->getTotalShipping($filter_data); + + $results = $this->model_extension_report_sale->getShipping($filter_data); + + foreach ($results as $result) { + $data['orders'][] = array( + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'title' => $result['title'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['groups'] = array(); + + $data['groups'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day', + ); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_group'])) { + $url .= '&filter_group=' . $this->request->get['filter_group']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $order_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_shipping' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($order_total - $this->config->get('config_limit_admin'))) ? $order_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $order_total, ceil($order_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_group'] = $filter_group; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/sale_shipping_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/report/sale_tax.php b/public/admin/controller/extension/report/sale_tax.php new file mode 100644 index 0000000..d16cdc6 --- /dev/null +++ b/public/admin/controller/extension/report/sale_tax.php @@ -0,0 +1,197 @@ +<?php +class ControllerExtensionReportSaleTax extends Controller { + public function index() { + $this->load->language('extension/report/sale_tax'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('report_sale_tax', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/report/sale_tax', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/report/sale_tax', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=report', true); + + if (isset($this->request->post['report_sale_tax_status'])) { + $data['report_sale_tax_status'] = $this->request->post['report_sale_tax_status']; + } else { + $data['report_sale_tax_status'] = $this->config->get('report_sale_tax_status'); + } + + if (isset($this->request->post['report_sale_tax_sort_order'])) { + $data['report_sale_tax_sort_order'] = $this->request->post['report_sale_tax_sort_order']; + } else { + $data['report_sale_tax_sort_order'] = $this->config->get('report_sale_tax_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/report/sale_tax_form', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/report/sale_tax')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function report() { + $this->load->language('extension/report/sale_tax'); + + if (isset($this->request->get['filter_date_start'])) { + $filter_date_start = $this->request->get['filter_date_start']; + } else { + $filter_date_start = ''; + } + + if (isset($this->request->get['filter_date_end'])) { + $filter_date_end = $this->request->get['filter_date_end']; + } else { + $filter_date_end = ''; + } + + if (isset($this->request->get['filter_group'])) { + $filter_group = $this->request->get['filter_group']; + } else { + $filter_group = 'week'; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $filter_order_status_id = $this->request->get['filter_order_status_id']; + } else { + $filter_order_status_id = 0; + } + + if (isset($this->request->get['page'])) { + $page = $this->request->get['page']; + } else { + $page = 1; + } + + $this->load->model('extension/report/sale'); + + $data['orders'] = array(); + + $filter_data = array( + 'filter_date_start' => $filter_date_start, + 'filter_date_end' => $filter_date_end, + 'filter_group' => $filter_group, + 'filter_order_status_id' => $filter_order_status_id, + 'start' => ($page - 1) * $this->config->get('config_limit_admin'), + 'limit' => $this->config->get('config_limit_admin') + ); + + $order_total = $this->model_extension_report_sale->getTotalTaxes($filter_data); + + $data['orders'] = array(); + + $results = $this->model_extension_report_sale->getTaxes($filter_data); + + foreach ($results as $result) { + $data['orders'][] = array( + 'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])), + 'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])), + 'title' => $result['title'], + 'orders' => $result['orders'], + 'total' => $this->currency->format($result['total'], $this->config->get('config_currency')) + ); + } + + $data['user_token'] = $this->session->data['user_token']; + + $this->load->model('localisation/order_status'); + + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); + + $data['groups'] = array(); + + $data['groups'][] = array( + 'text' => $this->language->get('text_year'), + 'value' => 'year', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_month'), + 'value' => 'month', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_week'), + 'value' => 'week', + ); + + $data['groups'][] = array( + 'text' => $this->language->get('text_day'), + 'value' => 'day', + ); + + $url = ''; + + if (isset($this->request->get['filter_date_start'])) { + $url .= '&filter_date_start=' . $this->request->get['filter_date_start']; + } + + if (isset($this->request->get['filter_date_end'])) { + $url .= '&filter_date_end=' . $this->request->get['filter_date_end']; + } + + if (isset($this->request->get['filter_group'])) { + $url .= '&filter_group=' . $this->request->get['filter_group']; + } + + if (isset($this->request->get['filter_order_status_id'])) { + $url .= '&filter_order_status_id=' . $this->request->get['filter_order_status_id']; + } + + $pagination = new Pagination(); + $pagination->total = $order_total; + $pagination->page = $page; + $pagination->limit = $this->config->get('config_limit_admin'); + $pagination->url = $this->url->link('report/report', 'user_token=' . $this->session->data['user_token'] . '&code=sale_tax' . $url . '&page={page}', true); + + $data['pagination'] = $pagination->render(); + + $data['results'] = sprintf($this->language->get('text_pagination'), ($order_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($order_total - $this->config->get('config_limit_admin'))) ? $order_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $order_total, ceil($order_total / $this->config->get('config_limit_admin'))); + + $data['filter_date_start'] = $filter_date_start; + $data['filter_date_end'] = $filter_date_end; + $data['filter_group'] = $filter_group; + $data['filter_order_status_id'] = $filter_order_status_id; + + return $this->load->view('extension/report/sale_tax_info', $data); + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/auspost.php b/public/admin/controller/extension/shipping/auspost.php new file mode 100644 index 0000000..8f4f036 --- /dev/null +++ b/public/admin/controller/extension/shipping/auspost.php @@ -0,0 +1,135 @@ +<?php +class ControllerExtensionShippingAusPost extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/auspost'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_auspost', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['api'])) { + $data['error_api'] = $this->error['api']; + } else { + $data['error_api'] = ''; + } + + if (isset($this->error['postcode'])) { + $data['error_postcode'] = $this->error['postcode']; + } else { + $data['error_postcode'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/auspost', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/auspost', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_auspost_postcode'])) { + $data['shipping_auspost_postcode'] = $this->request->post['shipping_auspost_postcode']; + } else { + $data['shipping_auspost_postcode'] = $this->config->get('shipping_auspost_postcode'); + } + + if (isset($this->request->post['shipping_auspost_api'])) { + $data['shipping_auspost_api'] = $this->request->post['shipping_auspost_api']; + } else { + $data['shipping_auspost_api'] = $this->config->get('shipping_auspost_api'); + } + + if (isset($this->request->post['shipping_auspost_weight_class_id'])) { + $data['shipping_auspost_weight_class_id'] = $this->request->post['shipping_auspost_weight_class_id']; + } else { + $data['shipping_auspost_weight_class_id'] = $this->config->get('shipping_auspost_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_auspost_tax_class_id'])) { + $data['shipping_auspost_tax_class_id'] = $this->request->post['shipping_auspost_tax_class_id']; + } else { + $data['shipping_auspost_tax_class_id'] = $this->config->get('shipping_auspost_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_auspost_geo_zone_id'])) { + $data['shipping_auspost_geo_zone_id'] = $this->request->post['shipping_auspost_geo_zone_id']; + } else { + $data['shipping_auspost_geo_zone_id'] = $this->config->get('shipping_auspost_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_auspost_status'])) { + $data['shipping_auspost_status'] = $this->request->post['shipping_auspost_status']; + } else { + $data['shipping_auspost_status'] = $this->config->get('shipping_auspost_status'); + } + + if (isset($this->request->post['shipping_auspost_sort_order'])) { + $data['shipping_auspost_sort_order'] = $this->request->post['shipping_auspost_sort_order']; + } else { + $data['shipping_auspost_sort_order'] = $this->config->get('shipping_auspost_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/auspost', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/auspost')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (empty($this->request->post['shipping_auspost_api'])) { + $this->error['api'] = $this->language->get('error_api'); + } + + if (!preg_match('/^[0-9]{4}$/', $this->request->post['shipping_auspost_postcode'])) { + $this->error['postcode'] = $this->language->get('error_postcode'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/ec_ship.php b/public/admin/controller/extension/shipping/ec_ship.php new file mode 100644 index 0000000..b743c6c --- /dev/null +++ b/public/admin/controller/extension/shipping/ec_ship.php @@ -0,0 +1,229 @@ +<?php +class ControllerExtensionShippingECShip extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/ec_ship'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_ec_ship', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['api_username'])) { + $data['error_api_username'] = $this->error['entry_api_username']; + } else { + $data['error_api_username'] = ''; + } + + if (isset($this->error['api_key'])) { + $data['error_api_key'] = $this->error['api_key']; + } else { + $data['error_api_key'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/ec_ship', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/ec_ship', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_ec_ship_api_key'])) { + $data['shipping_ec_ship_api_key'] = $this->request->post['shipping_ec_ship_api_key']; + } else { + $data['shipping_ec_ship_api_key'] = $this->config->get('shipping_ec_ship_api_key'); + } + + if (isset($this->request->post['shipping_ec_ship_username'])) { + $data['shipping_ec_ship_username'] = $this->request->post['shipping_ec_ship_username']; + } else { + $data['shipping_ec_ship_username'] = $this->config->get('shipping_ec_ship_username'); + } + + if (isset($this->request->post['shipping_ec_ship_api_username'])) { + $data['shipping_ec_ship_api_username'] = $this->request->post['shipping_ec_ship_api_username']; + } else { + $data['shipping_ec_ship_api_username'] = $this->config->get('shipping_ec_ship_api_username'); + } + + if (isset($this->request->post['shipping_ec_ship_test'])) { + $data['shipping_ec_ship_test'] = $this->request->post['shipping_ec_ship_test']; + } else { + $data['shipping_ec_ship_test'] = $this->config->get('shipping_ec_ship_test'); + } + + if (isset($this->request->post['shipping_ec_ship_air_registered_mail'])) { + $data['shipping_ec_ship_air_registered_mail'] = $this->request->post['shipping_ec_ship_air_registered_mail']; + } else { + $data['shipping_ec_ship_air_registered_mail'] = $this->config->get('shipping_ec_ship_air_registered_mail'); + } + + if (isset($this->request->post['shipping_ec_ship_air_parcel'])) { + $data['shipping_ec_ship_air_parcel'] = $this->request->post['shipping_ec_ship_air_parcel']; + } else { + $data['shipping_ec_ship_air_parcel'] = $this->config->get('shipping_ec_ship_air_parcel'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_to_us'])) { + $data['shipping_ec_ship_e_express_service_to_us'] = $this->request->post['shipping_ec_ship_e_express_service_to_us']; + } else { + $data['shipping_ec_ship_e_express_service_to_us'] = $this->config->get('shipping_ec_ship_e_express_service_to_us'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_to_canada'])) { + $data['shipping_ec_ship_e_express_service_to_canada'] = $this->request->post['shipping_ec_ship_e_express_service_to_canada']; + } else { + $data['shipping_ec_ship_e_express_service_to_canada'] = $this->config->get('shipping_ec_ship_e_express_service_to_canada'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_to_united_kingdom'])) { + $data['shipping_ec_ship_e_express_service_to_united_kingdom'] = $this->request->post['shipping_ec_ship_e_express_service_to_united_kingdom']; + } else { + $data['shipping_ec_ship_e_express_service_to_united_kingdom'] = $this->config->get('shipping_ec_ship_e_express_service_to_united_kingdom'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_to_russia'])) { + $data['shipping_ec_ship_e_express_service_to_russia'] = $this->request->post['shipping_ec_ship_e_express_service_to_russia']; + } else { + $data['shipping_ec_ship_e_express_service_to_russia'] = $this->config->get('shipping_ec_ship_e_express_service_to_russia'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_one'])) { + $data['shipping_ec_ship_e_express_service_one'] = $this->request->post['shipping_ec_ship_e_express_service_one']; + } else { + $data['shipping_ec_ship_e_express_service_one'] = $this->config->get('shipping_ec_ship_e_express_service_one'); + } + + if (isset($this->request->post['shipping_ec_ship_e_express_service_two'])) { + $data['shipping_ec_ship_e_express_service_two'] = $this->request->post['shipping_ec_ship_e_express_service_two']; + } else { + $data['shipping_ec_ship_e_express_service_two'] = $this->config->get('shipping_ec_ship_e_express_service_two'); + } + + if (isset($this->request->post['shipping_ec_ship_speed_post'])) { + $data['shipping_ec_ship_speed_post'] = $this->request->post['shipping_ec_ship_speed_post']; + } else { + $data['shipping_ec_ship_speed_post'] = $this->config->get('shipping_ec_ship_speed_post'); + } + + if (isset($this->request->post['shipping_ec_ship_smart_post'])) { + $data['shipping_ec_ship_smart_post'] = $this->request->post['shipping_ec_ship_smart_post']; + } else { + $data['shipping_ec_ship_smart_post'] = $this->config->get('shipping_ec_ship_smart_post'); + } + + if (isset($this->request->post['shipping_ec_ship_local_courier_post'])) { + $data['shipping_ec_ship_local_courier_post'] = $this->request->post['shipping_ec_ship_local_courier_post']; + } else { + $data['shipping_ec_ship_local_courier_post'] = $this->config->get('shipping_ec_ship_local_courier_post'); + } + + if (isset($this->request->post['shipping_ec_ship_local_parcel'])) { + $data['shipping_ec_ship_local_parcel'] = $this->request->post['shipping_ec_ship_local_parcel']; + } else { + $data['shipping_ec_ship_local_parcel'] = $this->config->get('shipping_ec_ship_local_parcel'); + } + + if (isset($this->request->post['shipping_ec_ship_weight_class_id'])) { + $data['shipping_ec_ship_weight_class_id'] = $this->request->post['shipping_ec_ship_weight_class_id']; + } else { + $data['shipping_ec_ship_weight_class_id'] = $this->config->get('shipping_ec_ship_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_ec_ship_tax_class_id'])) { + $data['shipping_ec_ship_tax_class_id'] = $this->request->post['shipping_ec_ship_tax_class_id']; + } else { + $data['shipping_ec_ship_tax_class_id'] = $this->config->get('shipping_ec_ship_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_ec_ship_geo_zone_id'])) { + $data['shipping_ec_ship_geo_zone_id'] = $this->request->post['shipping_ec_ship_geo_zone_id']; + } else { + $data['shipping_ec_ship_geo_zone_id'] = $this->config->get('shipping_ec_ship_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_ec_ship_status'])) { + $data['shipping_ec_ship_status'] = $this->request->post['shipping_ec_ship_status']; + } else { + $data['shipping_ec_ship_status'] = $this->config->get('shipping_ec_ship_status'); + } + + if (isset($this->request->post['shipping_ec_ship_sort_order'])) { + $data['shipping_ec_ship_sort_order'] = $this->request->post['shipping_ec_ship_sort_order']; + } else { + $data['shipping_ec_ship_sort_order'] = $this->config->get('shipping_ec_ship_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/ec_ship', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/ec_ship')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['shipping_ec_ship_api_key']) { + $this->error['api_key'] = $this->language->get('error_api_key'); + } + + if (!$this->request->post['shipping_ec_ship_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['shipping_ec_ship_api_username']) { + $this->error['api_username'] = $this->language->get('error_api_username'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/shipping/fedex.php b/public/admin/controller/extension/shipping/fedex.php new file mode 100644 index 0000000..37a3f8e --- /dev/null +++ b/public/admin/controller/extension/shipping/fedex.php @@ -0,0 +1,378 @@ +<?php +class ControllerExtensionShippingFedex extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/fedex'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_fedex', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['account'])) { + $data['error_account'] = $this->error['account']; + } else { + $data['error_account'] = ''; + } + + if (isset($this->error['meter'])) { + $data['error_meter'] = $this->error['meter']; + } else { + $data['error_meter'] = ''; + } + + if (isset($this->error['postcode'])) { + $data['error_postcode'] = $this->error['postcode']; + } else { + $data['error_postcode'] = ''; + } + + if (isset($this->error['dimension'])) { + $data['error_dimension'] = $this->error['dimension']; + } else { + $data['error_dimension'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/fedex', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/fedex', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_fedex_key'])) { + $data['shipping_fedex_key'] = $this->request->post['shipping_fedex_key']; + } else { + $data['shipping_fedex_key'] = $this->config->get('shipping_fedex_key'); + } + + if (isset($this->request->post['shipping_fedex_password'])) { + $data['shipping_fedex_password'] = $this->request->post['shipping_fedex_password']; + } else { + $data['shipping_fedex_password'] = $this->config->get('shipping_fedex_password'); + } + + if (isset($this->request->post['shipping_fedex_account'])) { + $data['shipping_fedex_account'] = $this->request->post['shipping_fedex_account']; + } else { + $data['shipping_fedex_account'] = $this->config->get('shipping_fedex_account'); + } + + if (isset($this->request->post['shipping_fedex_meter'])) { + $data['shipping_fedex_meter'] = $this->request->post['shipping_fedex_meter']; + } else { + $data['shipping_fedex_meter'] = $this->config->get('shipping_fedex_meter'); + } + + if (isset($this->request->post['shipping_fedex_postcode'])) { + $data['shipping_fedex_postcode'] = $this->request->post['shipping_fedex_postcode']; + } else { + $data['shipping_fedex_postcode'] = $this->config->get('shipping_fedex_postcode'); + } + + if (isset($this->request->post['shipping_fedex_test'])) { + $data['shipping_fedex_test'] = $this->request->post['shipping_fedex_test']; + } else { + $data['shipping_fedex_test'] = $this->config->get('shipping_fedex_test'); + } + + if (isset($this->request->post['shipping_fedex_service'])) { + $data['shipping_fedex_service'] = $this->request->post['shipping_fedex_service']; + } elseif ($this->config->has('shipping_fedex_service')) { + $data['shipping_fedex_service'] = $this->config->get('shipping_fedex_service'); + } else { + $data['shipping_fedex_service'] = array(); + } + + $data['services'] = array(); + + $data['services'][] = array( + 'text' => $this->language->get('text_europe_first_international_priority'), + 'value' => 'EUROPE_FIRST_INTERNATIONAL_PRIORITY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_1_day_freight'), + 'value' => 'FEDEX_1_DAY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_2_day'), + 'value' => 'FEDEX_2_DAY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_2_day_am'), + 'value' => 'FEDEX_2_DAY_AM' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_2_day_freight'), + 'value' => 'FEDEX_2_DAY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_3_day_freight'), + 'value' => 'FEDEX_3_DAY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_express_saver'), + 'value' => 'FEDEX_EXPRESS_SAVER' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_first_freight'), + 'value' => 'FEDEX_FIRST_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_freight_economy'), + 'value' => 'FEDEX_FREIGHT_ECONOMY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_freight_priority'), + 'value' => 'FEDEX_FREIGHT_PRIORITY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_fedex_ground'), + 'value' => 'FEDEX_GROUND' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_first_overnight'), + 'value' => 'FIRST_OVERNIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_ground_home_delivery'), + 'value' => 'GROUND_HOME_DELIVERY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_economy'), + 'value' => 'INTERNATIONAL_ECONOMY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_economy_freight'), + 'value' => 'INTERNATIONAL_ECONOMY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_first'), + 'value' => 'INTERNATIONAL_FIRST' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_priority'), + 'value' => 'INTERNATIONAL_PRIORITY' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_international_priority_freight'), + 'value' => 'INTERNATIONAL_PRIORITY_FREIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_priority_overnight'), + 'value' => 'PRIORITY_OVERNIGHT' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_smart_post'), + 'value' => 'SMART_POST' + ); + + $data['services'][] = array( + 'text' => $this->language->get('text_standard_overnight'), + 'value' => 'STANDARD_OVERNIGHT' + ); + + if (isset($this->request->post['shipping_fedex_length'])) { + $data['shipping_fedex_length'] = $this->request->post['shipping_fedex_length']; + } else { + $data['shipping_fedex_length'] = $this->config->get('shipping_fedex_length'); + } + + if (isset($this->request->post['shipping_fedex_width'])) { + $data['shipping_fedex_width'] = $this->request->post['shipping_fedex_width']; + } else { + $data['shipping_fedex_width'] = $this->config->get('shipping_fedex_width'); + } + + if (isset($this->request->post['shipping_fedex_height'])) { + $data['shipping_fedex_height'] = $this->request->post['shipping_fedex_height']; + } else { + $data['shipping_fedex_height'] = $this->config->get('shipping_fedex_height'); + } + + if (isset($this->request->post['shipping_fedex_length_class_id'])) { + $data['shipping_fedex_length_class_id'] = $this->request->post['shipping_fedex_length_class_id']; + } else { + $data['shipping_fedex_length_class_id'] = $this->config->get('shipping_fedex_length_class_id'); + } + + $this->load->model('localisation/length_class'); + + $data['length_classes'] = $this->model_localisation_length_class->getLengthClasses(); + + if (isset($this->request->post['shipping_fedex_dropoff_type'])) { + $data['shipping_fedex_dropoff_type'] = $this->request->post['shipping_fedex_dropoff_type']; + } else { + $data['shipping_fedex_dropoff_type'] = $this->config->get('shipping_fedex_dropoff_type'); + } + + if (isset($this->request->post['shipping_fedex_packaging_type'])) { + $data['shipping_fedex_packaging_type'] = $this->request->post['shipping_fedex_packaging_type']; + } else { + $data['shipping_fedex_packaging_type'] = $this->config->get('shipping_fedex_packaging_type'); + } + + if (isset($this->request->post['shipping_fedex_rate_type'])) { + $data['shipping_fedex_rate_type'] = $this->request->post['shipping_fedex_rate_type']; + } else { + $data['shipping_fedex_rate_type'] = $this->config->get('shipping_fedex_rate_type'); + } + + if (isset($this->request->post['shipping_fedex_destination_type'])) { + $data['shipping_fedex_destination_type'] = $this->request->post['shipping_fedex_destination_type']; + } else { + $data['shipping_fedex_destination_type'] = $this->config->get('shipping_fedex_destination_type'); + } + + if (isset($this->request->post['shipping_fedex_display_time'])) { + $data['shipping_fedex_display_time'] = $this->request->post['shipping_fedex_display_time']; + } else { + $data['shipping_fedex_display_time'] = $this->config->get('shipping_fedex_display_time'); + } + + if (isset($this->request->post['shipping_fedex_display_weight'])) { + $data['shipping_fedex_display_weight'] = $this->request->post['shipping_fedex_display_weight']; + } else { + $data['shipping_fedex_display_weight'] = $this->config->get('shipping_fedex_display_weight'); + } + + if (isset($this->request->post['shipping_fedex_weight_class_id'])) { + $data['shipping_fedex_weight_class_id'] = $this->request->post['shipping_fedex_weight_class_id']; + } else { + $data['shipping_fedex_weight_class_id'] = $this->config->get('shipping_fedex_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_fedex_tax_class_id'])) { + $data['shipping_fedex_tax_class_id'] = $this->request->post['shipping_fedex_tax_class_id']; + } else { + $data['shipping_fedex_tax_class_id'] = $this->config->get('shipping_fedex_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_fedex_geo_zone_id'])) { + $data['shipping_fedex_geo_zone_id'] = $this->request->post['shipping_fedex_geo_zone_id']; + } else { + $data['shipping_fedex_geo_zone_id'] = $this->config->get('shipping_fedex_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_fedex_status'])) { + $data['shipping_fedex_status'] = $this->request->post['shipping_fedex_status']; + } else { + $data['shipping_fedex_status'] = $this->config->get('shipping_fedex_status'); + } + + if (isset($this->request->post['shipping_fedex_sort_order'])) { + $data['shipping_fedex_sort_order'] = $this->request->post['shipping_fedex_sort_order']; + } else { + $data['shipping_fedex_sort_order'] = $this->config->get('shipping_fedex_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/fedex', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/fedex')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['shipping_fedex_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + if (!$this->request->post['shipping_fedex_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['shipping_fedex_account']) { + $this->error['account'] = $this->language->get('error_account'); + } + + if (!$this->request->post['shipping_fedex_meter']) { + $this->error['meter'] = $this->language->get('error_meter'); + } + + if (!$this->request->post['shipping_fedex_postcode']) { + $this->error['postcode'] = $this->language->get('error_postcode'); + } + + if (!$this->request->post['shipping_fedex_length'] || !$this->request->post['shipping_fedex_width'] || !$this->request->post['shipping_fedex_height']) { + $this->error['dimension'] = $this->language->get('error_dimension'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/shipping/flat.php b/public/admin/controller/extension/shipping/flat.php new file mode 100644 index 0000000..1d4e161 --- /dev/null +++ b/public/admin/controller/extension/shipping/flat.php @@ -0,0 +1,99 @@ +<?php +class ControllerExtensionShippingFlat extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/flat'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_flat', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/flat', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/flat', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_flat_cost'])) { + $data['shipping_flat_cost'] = $this->request->post['shipping_flat_cost']; + } else { + $data['shipping_flat_cost'] = $this->config->get('shipping_flat_cost'); + } + + if (isset($this->request->post['shipping_flat_tax_class_id'])) { + $data['shipping_flat_tax_class_id'] = $this->request->post['shipping_flat_tax_class_id']; + } else { + $data['shipping_flat_tax_class_id'] = $this->config->get('shipping_flat_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_flat_geo_zone_id'])) { + $data['shipping_flat_geo_zone_id'] = $this->request->post['shipping_flat_geo_zone_id']; + } else { + $data['shipping_flat_geo_zone_id'] = $this->config->get('shipping_flat_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_flat_status'])) { + $data['shipping_flat_status'] = $this->request->post['shipping_flat_status']; + } else { + $data['shipping_flat_status'] = $this->config->get('shipping_flat_status'); + } + + if (isset($this->request->post['shipping_flat_sort_order'])) { + $data['shipping_flat_sort_order'] = $this->request->post['shipping_flat_sort_order']; + } else { + $data['shipping_flat_sort_order'] = $this->config->get('shipping_flat_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/flat', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/flat')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/free.php b/public/admin/controller/extension/shipping/free.php new file mode 100644 index 0000000..c7828a6 --- /dev/null +++ b/public/admin/controller/extension/shipping/free.php @@ -0,0 +1,89 @@ +<?php +class ControllerExtensionShippingFree extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/free'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_free', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/free', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/free', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_free_total'])) { + $data['shipping_free_total'] = $this->request->post['shipping_free_total']; + } else { + $data['shipping_free_total'] = $this->config->get('shipping_free_total'); + } + + if (isset($this->request->post['shipping_free_geo_zone_id'])) { + $data['shipping_free_geo_zone_id'] = $this->request->post['shipping_free_geo_zone_id']; + } else { + $data['shipping_free_geo_zone_id'] = $this->config->get('shipping_free_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_free_status'])) { + $data['shipping_free_status'] = $this->request->post['shipping_free_status']; + } else { + $data['shipping_free_status'] = $this->config->get('shipping_free_status'); + } + + if (isset($this->request->post['shipping_free_sort_order'])) { + $data['shipping_free_sort_order'] = $this->request->post['shipping_free_sort_order']; + } else { + $data['shipping_free_sort_order'] = $this->config->get('shipping_free_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/free', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/free')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/item.php b/public/admin/controller/extension/shipping/item.php new file mode 100644 index 0000000..0e4bfc7 --- /dev/null +++ b/public/admin/controller/extension/shipping/item.php @@ -0,0 +1,99 @@ +<?php +class ControllerExtensionShippingItem extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/item'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_item', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/item', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/item', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_item_cost'])) { + $data['shipping_item_cost'] = $this->request->post['shipping_item_cost']; + } else { + $data['shipping_item_cost'] = $this->config->get('shipping_item_cost'); + } + + if (isset($this->request->post['shipping_item_tax_class_id'])) { + $data['shipping_item_tax_class_id'] = $this->request->post['shipping_item_tax_class_id']; + } else { + $data['shipping_item_tax_class_id'] = $this->config->get('shipping_item_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_item_geo_zone_id'])) { + $data['shipping_item_geo_zone_id'] = $this->request->post['shipping_item_geo_zone_id']; + } else { + $data['shipping_item_geo_zone_id'] = $this->config->get('shipping_item_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_item_status'])) { + $data['shipping_item_status'] = $this->request->post['shipping_item_status']; + } else { + $data['shipping_item_status'] = $this->config->get('shipping_item_status'); + } + + if (isset($this->request->post['shipping_item_sort_order'])) { + $data['shipping_item_sort_order'] = $this->request->post['shipping_item_sort_order']; + } else { + $data['shipping_item_sort_order'] = $this->config->get('shipping_item_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/item', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/item')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/parcelforce_48.php b/public/admin/controller/extension/shipping/parcelforce_48.php new file mode 100644 index 0000000..6e6d49e --- /dev/null +++ b/public/admin/controller/extension/shipping/parcelforce_48.php @@ -0,0 +1,127 @@ +<?php +class ControllerExtensionShippingParcelforce48 extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/parcelforce_48'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_parcelforce_48', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/parcelforce_48', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/parcelforce_48', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_parcelforce_48_rate'])) { + $data['shipping_parcelforce_48_rate'] = $this->request->post['shipping_parcelforce_48_rate']; + } elseif ($this->config->get('shipping_parcelforce_48_rate')) { + $data['shipping_parcelforce_48_rate'] = $this->config->get('shipping_parcelforce_48_rate'); + } else { + $data['shipping_parcelforce_48_rate'] = '10:15.99,12:19.99,14:20.99,16:21.99,18:21.99,20:21.99,22:26.99,24:30.99,26:34.99,28:38.99,30:42.99,35:52.99,40:62.99,45:72.99,50:82.99,55:92.99,60:102.99,65:112.99,70:122.99,75:132.99,80:142.99,85:152.99,90:162.99,95:172.99,100:182.99'; + } + + if (isset($this->request->post['shipping_parcelforce_48_insurance'])) { + $data['shipping_parcelforce_48_insurance'] = $this->request->post['shipping_parcelforce_48_insurance']; + } elseif ($this->config->get('shipping_parcelforce_48_insurance')) { + $data['shipping_parcelforce_48_insurance'] = $this->config->get('shipping_parcelforce_48_insurance'); + } else { + $data['shipping_parcelforce_48_insurance'] = '150:0,500:12,1000:24,1500:36,2000:48,2500:60'; + } + + if (isset($this->request->post['shipping_parcelforce_48_display_weight'])) { + $data['shipping_parcelforce_48_display_weight'] = $this->request->post['shipping_parcelforce_48_display_weight']; + } else { + $data['shipping_parcelforce_48_display_weight'] = $this->config->get('shipping_parcelforce_48_display_weight'); + } + + if (isset($this->request->post['shipping_parcelforce_48_display_insurance'])) { + $data['shipping_parcelforce_48_display_insurance'] = $this->request->post['shipping_parcelforce_48_display_insurance']; + } else { + $data['shipping_parcelforce_48_display_insurance'] = $this->config->get('shipping_parcelforce_48_display_insurance'); + } + + if (isset($this->request->post['shipping_parcelforce_48_display_time'])) { + $data['shipping_parcelforce_48_display_time'] = $this->request->post['shipping_parcelforce_48_display_time']; + } else { + $data['shipping_parcelforce_48_display_time'] = $this->config->get('shipping_parcelforce_48_display_time'); + } + + if (isset($this->request->post['shipping_parcelforce_48_tax_class_id'])) { + $data['shipping_parcelforce_48_tax_class_id'] = $this->request->post['shipping_parcelforce_48_tax_class_id']; + } else { + $data['shipping_parcelforce_48_tax_class_id'] = $this->config->get('shipping_parcelforce_48_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_parcelforce_48_geo_zone_id'])) { + $data['shipping_parcelforce_48_geo_zone_id'] = $this->request->post['shipping_parcelforce_48_geo_zone_id']; + } else { + $data['shipping_parcelforce_48_geo_zone_id'] = $this->config->get('shipping_parcelforce_48_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_parcelforce_48_status'])) { + $data['shipping_parcelforce_48_status'] = $this->request->post['shipping_parcelforce_48_status']; + } else { + $data['shipping_parcelforce_48_status'] = $this->config->get('shipping_parcelforce_48_status'); + } + + if (isset($this->request->post['shipping_parcelforce_48_sort_order'])) { + $data['shipping_parcelforce_48_sort_order'] = $this->request->post['shipping_parcelforce_48_sort_order']; + } else { + $data['shipping_parcelforce_48_sort_order'] = $this->config->get('shipping_parcelforce_48_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/parcelforce_48', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/parcelforce_48')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/pickup.php b/public/admin/controller/extension/shipping/pickup.php new file mode 100644 index 0000000..7347148 --- /dev/null +++ b/public/admin/controller/extension/shipping/pickup.php @@ -0,0 +1,83 @@ +<?php +class ControllerExtensionShippingPickup extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/pickup'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_pickup', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/pickup', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/pickup', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_pickup_geo_zone_id'])) { + $data['shipping_pickup_geo_zone_id'] = $this->request->post['shipping_pickup_geo_zone_id']; + } else { + $data['shipping_pickup_geo_zone_id'] = $this->config->get('shipping_pickup_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_pickup_status'])) { + $data['shipping_pickup_status'] = $this->request->post['shipping_pickup_status']; + } else { + $data['shipping_pickup_status'] = $this->config->get('shipping_pickup_status'); + } + + if (isset($this->request->post['shipping_pickup_sort_order'])) { + $data['shipping_pickup_sort_order'] = $this->request->post['shipping_pickup_sort_order']; + } else { + $data['shipping_pickup_sort_order'] = $this->config->get('shipping_pickup_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/pickup', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/pickup')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/royal_mail.php b/public/admin/controller/extension/shipping/royal_mail.php new file mode 100644 index 0000000..34f446b --- /dev/null +++ b/public/admin/controller/extension/shipping/royal_mail.php @@ -0,0 +1,403 @@ +<?php +class ControllerExtensionShippingRoyalMail extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/royal_mail'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_royal_mail', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/royal_mail', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/royal_mail', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + // Special Delivery < 500 + if (isset($this->request->post['shipping_royal_mail_special_delivery_500_rate'])) { + $data['shipping_royal_mail_special_delivery_500_rate'] = $this->request->post['shipping_royal_mail_special_delivery_500_rate']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_500_rate')) { + $data['shipping_royal_mail_special_delivery_500_rate'] = $this->config->get('shipping_royal_mail_special_delivery_500_rate'); + } else { + $data['shipping_royal_mail_special_delivery_500_rate'] = '0.1:6.40,0.5:7.15,1:8.45,2:11.00,10:26.60,20:41.20'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_500_insurance'])) { + $data['shipping_royal_mail_special_delivery_500_insurance'] = $this->request->post['shipping_royal_mail_special_delivery_500_insurance']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_500_insurance')) { + $data['shipping_royal_mail_special_delivery_500_insurance'] = $this->config->get('shipping_royal_mail_special_delivery_500_insurance'); + } else { + $data['shipping_royal_mail_special_delivery_500_insurance'] = '0:500'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_500_status'])) { + $data['shipping_royal_mail_special_delivery_500_status'] = $this->request->post['shipping_royal_mail_special_delivery_500_status']; + } else { + $data['shipping_royal_mail_special_delivery_500_status'] = $this->config->get('shipping_royal_mail_special_delivery_500_status'); + } + + // Special Delivery < 1000 + if (isset($this->request->post['shipping_royal_mail_special_delivery_1000_rate'])) { + $data['shipping_royal_mail_special_delivery_1000_rate'] = $this->request->post['shipping_royal_mail_special_delivery_1000_rate']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_1000_rate')) { + $data['shipping_royal_mail_special_delivery_1000_rate'] = $this->config->get('shipping_royal_mail_special_delivery_1000_rate'); + } else { + $data['shipping_royal_mail_special_delivery_1000_rate'] = '0.1:7.40,0.5:8.15,1:9.45,2:12.00,10:27.60,20:42.20'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_1000_insurance'])) { + $data['shipping_royal_mail_special_delivery_1000_insurance'] = $this->request->post['shipping_royal_mail_special_delivery_1000_insurance']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_1000_insurance')) { + $data['shipping_royal_mail_special_delivery_1000_insurance'] = $this->config->get('shipping_royal_mail_special_delivery_1000_insurance'); + } else { + $data['shipping_royal_mail_special_delivery_1000_insurance'] = '0:1000'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_1000_status'])) { + $data['shipping_royal_mail_special_delivery_1000_status'] = $this->request->post['shipping_royal_mail_special_delivery_1000_status']; + } else { + $data['shipping_royal_mail_special_delivery_1000_status'] = $this->config->get('shipping_royal_mail_special_delivery_1000_status'); + } + + // Special Delivery < 2500 + if (isset($this->request->post['shipping_royal_mail_special_delivery_2500_rate'])) { + $data['shipping_royal_mail_special_delivery_2500_rate'] = $this->request->post['shipping_royal_mail_special_delivery_2500_rate']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_2500_rate')) { + $data['shipping_royal_mail_special_delivery_2500_rate'] = $this->config->get('shipping_royal_mail_special_delivery_2500_rate'); + } else { + $data['shipping_royal_mail_special_delivery_2500_rate'] = '0.1:9.40,0.5:10.15,1:11.45,2:14.00,10:29.60,20:44.20'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_2500_insurance'])) { + $data['shipping_royal_mail_special_delivery_2500_insurance'] = $this->request->post['shipping_royal_mail_special_delivery_2500_insurance']; + } elseif ($this->config->has('shipping_royal_mail_special_delivery_2500_insurance')) { + $data['shipping_royal_mail_special_delivery_2500_insurance'] = $this->config->get('shipping_royal_mail_special_delivery_2500_insurance'); + } else { + $data['shipping_royal_mail_special_delivery_2500_insurance'] = '0:2500'; + } + + if (isset($this->request->post['shipping_royal_mail_special_delivery_2500_status'])) { + $data['shipping_royal_mail_special_delivery_2500_status'] = $this->request->post['shipping_royal_mail_special_delivery_2500_status']; + } else { + $data['shipping_royal_mail_special_delivery_2500_status'] = $this->config->get('shipping_royal_mail_special_delivery_2500_status'); + } + + // 1st Class Signed + if (isset($this->request->post['shipping_royal_mail_1st_class_signed_rate'])) { + $data['shipping_royal_mail_1st_class_signed_rate'] = $this->request->post['shipping_royal_mail_1st_class_signed_rate']; + } elseif ($this->config->has('shipping_royal_mail_1st_class_signed_rate')) { + $data['shipping_royal_mail_1st_class_signed_rate'] = $this->config->get('shipping_royal_mail_1st_class_signed_rate'); + } else { + $data['shipping_royal_mail_1st_class_signed_rate'] = '0.1:2.03,0.25:2.34,0.5:2.75,0.75:3.48,1:6.75,2:10.00,5:16.95,10:23.00,20:34.50'; + } + + if (isset($this->request->post['shipping_royal_mail_1st_class_signed_status'])) { + $data['shipping_royal_mail_1st_class_signed_status'] = $this->request->post['shipping_royal_mail_1st_class_signed_status']; + } else { + $data['shipping_royal_mail_1st_class_signed_status'] = $this->config->get('shipping_royal_mail_1st_class_signed_status'); + } + + // 2nd Class Signed + if (isset($this->request->post['shipping_royal_mail_2nd_class_signed_rate'])) { + $data['shipping_royal_mail_2nd_class_signed_rate'] = $this->request->post['shipping_royal_mail_2nd_class_signed_rate']; + } elseif ($this->config->has('shipping_royal_mail_2nd_class_signed_rate')) { + $data['shipping_royal_mail_2nd_class_signed_rate'] = $this->config->get('shipping_royal_mail_2nd_class_signed_rate'); + } else { + $data['shipping_royal_mail_2nd_class_signed_rate'] = '0.1:1.83,0.25:2.27,0.5:2.58,0.75:3.11,1:6.30,2:9.10,5:14.85,10:21.35,20:29.65'; + } + + if (isset($this->request->post['shipping_royal_mail_2nd_class_signed_status'])) { + $data['shipping_royal_mail_2nd_class_signed_status'] = $this->request->post['shipping_royal_mail_2nd_class_signed_status']; + } else { + $data['shipping_royal_mail_2nd_class_signed_status'] = $this->config->get('shipping_royal_mail_2nd_class_signed_status'); + } + + // 1st Class Standard + if (isset($this->request->post['shipping_royal_mail_1st_class_standard_rate'])) { + $data['shipping_royal_mail_1st_class_standard_rate'] = $this->request->post['shipping_royal_mail_1st_class_standard_rate']; + } elseif ($this->config->has('shipping_royal_mail_1st_class_standard_rate')) { + $data['shipping_royal_mail_1st_class_standard_rate'] = $this->config->get('shipping_royal_mail_1st_class_standard_rate'); + } else { + $data['shipping_royal_mail_1st_class_standard_rate'] = '0.1:0.93,0.25:1.24,0.5:1.65,0.75:2.38,1:5.65,2:8.90,5:15.85,10:21.90,20:33.40'; + } + + if (isset($this->request->post['shipping_royal_mail_1st_class_standard_status'])) { + $data['shipping_royal_mail_1st_class_standard_status'] = $this->request->post['shipping_royal_mail_1st_class_standard_status']; + } else { + $data['shipping_royal_mail_1st_class_standard_status'] = $this->config->get('shipping_royal_mail_1st_class_standard_status'); + } + + // 2nd Class Standard + if (isset($this->request->post['shipping_royal_mail_2nd_class_standard_rate'])) { + $data['shipping_royal_mail_2nd_class_standard_rate'] = $this->request->post['shipping_royal_mail_2nd_class_standard_rate']; + } elseif ($this->config->has('shipping_royal_mail_2nd_class_standard_rate')) { + $data['shipping_royal_mail_2nd_class_standard_rate'] = $this->config->get('shipping_royal_mail_2nd_class_standard_rate'); + } else { + $data['shipping_royal_mail_2nd_class_standard_rate'] = '0.1:0.73,.25:1.17,.5:1.48,.75:2.01,1:5.20,2:8.00,5:13.75,10:20.25,20:28.55'; + } + + if (isset($this->request->post['shipping_royal_mail_2nd_class_standard_status'])) { + $data['shipping_royal_mail_2nd_class_standard_status'] = $this->request->post['shipping_royal_mail_2nd_class_standard_status']; + } else { + $data['shipping_royal_mail_2nd_class_standard_status'] = $this->config->get('shipping_royal_mail_2nd_class_standard_status'); + } + + // International Standard + if (isset($this->request->post['shipping_royal_mail_international_standard_eu_rate'])) { + $data['shipping_royal_mail_international_standard_eu_rate'] = $this->request->post['shipping_royal_mail_international_standard_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_standard_eu_rate')) { + $data['shipping_royal_mail_international_standard_eu_rate'] = $this->config->get('shipping_royal_mail_international_standard_eu_rate'); + } else { + $data['shipping_royal_mail_international_standard_eu_rate'] = '0.01:0.97,0.02:0.97,0.06:1.47,0.1:3.20,0.25:3.70,0.5:5.15,0.75:6.60,1.25:9.50,1.5:10.95,1.75:12.40,2:13.85'; + } + + if (isset($this->request->post['shipping_royal_mail_international_standard_zone_1_rate'])) { + $data['shipping_royal_mail_international_standard_zone_1_rate'] = $this->request->post['shipping_royal_mail_international_standard_zone_1_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_standard_zone_1_rate')) { + $data['shipping_royal_mail_international_standard_zone_1_rate'] = $this->config->get('shipping_royal_mail_international_standard_zone_1_rate'); + } else { + $data['shipping_royal_mail_international_standard_zone_1_rate'] = '0.01:0.97,0.02:1.28,0.06:2.15,0.1:3.80,0.25:4.75,0.5:7.45,0.75:10.15,1:12.85,1.25:15.55,1.5:18.25,1.75:20.95,2:23.65'; + } + + if (isset($this->request->post['shipping_royal_mail_international_standard_zone_2_rate'])) { + $data['shipping_royal_mail_international_standard_zone_2_rate'] = $this->request->post['shipping_royal_mail_international_standard_zone_2_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_standard_zone_2_rate')) { + $data['shipping_royal_mail_international_standard_zone_2_rate'] = $this->config->get('shipping_royal_mail_international_standard_zone_2_rate'); + } else { + $data['shipping_royal_mail_international_standard_zone_2_rate'] = '0.01:0.97,0.02:1.28,0.06:2.15,0.1:4.00,0.25:5.05,0.5:7.90,0.75:10.75,1:13.60,1.25:16.45,1.5:19.30,1.75:22.15,2:25.00'; + } + + if (isset($this->request->post['shipping_royal_mail_international_standard_status'])) { + $data['shipping_royal_mail_international_standard_status'] = $this->request->post['shipping_royal_mail_international_standard_status']; + } else { + $data['shipping_royal_mail_international_standard_status'] = $this->config->get('shipping_royal_mail_international_standard_status'); + } + + // International Tracked & Signed + if (isset($this->request->post['shipping_royal_mail_international_tracked_signed_eu_rate'])) { + $data['shipping_royal_mail_international_tracked_signed_eu_rate'] = $this->request->post['shipping_royal_mail_international_tracked_signed_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_signed_eu_rate')) { + $data['shipping_royal_mail_international_tracked_signed_eu_rate'] = $this->config->get('shipping_royal_mail_international_tracked_signed_eu_rate'); + } else { + $data['shipping_royal_mail_international_tracked_signed_eu_rate'] = '0.02:5.97,0.06:6.47,0.1:8.20,0.25:8.70,0.50:10.15,0.75:11.60,1:13.05,1.25:14.50,1.5:15.95,1.75:17.40,2:18.85'; + } + + if (isset($this->request->post['shipping_royal_mail_international_tracked_signed_zone_1_rate'])) { + $data['shipping_royal_mail_international_tracked_signed_zone_1_rate'] = $this->request->post['shipping_royal_mail_international_tracked_signed_zone_1_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_signed_zone_1_rate')) { + $data['shipping_royal_mail_international_tracked_signed_zone_1_rate'] = $this->config->get('shipping_royal_mail_international_tracked_signed_zone_1_rate'); + } else { + $data['shipping_royal_mail_international_tracked_signed_zone_1_rate'] = '0.02:6.28,0.06:7.15,0.1:8.80,0.25:9.75,0.5:12.45,0.75:15.15,1:17.85,1.25:20.55,1.5:23.25,1.75:25.95,2:28.65'; + } + + if (isset($this->request->post['shipping_royal_mail_international_tracked_signed_zone_2_rate'])) { + $data['shipping_royal_mail_international_tracked_signed_zone_2_rate'] = $this->request->post['shipping_royal_mail_international_tracked_signed_zone_2_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_signed_zone_2_rate')) { + $data['shipping_royal_mail_international_tracked_signed_zone_2_rate'] = $this->config->get('shipping_royal_mail_international_tracked_signed_zone_2_rate'); + } else { + $data['shipping_royal_mail_international_tracked_signed_zone_2_rate'] = '0.02:6.28,0.06:7.15,0.1:9.00,0.25:10.05,0.5:12.90,0.75:15.75,1:18.60,1.25:21.45,1.5:24.30,1.75:27.15,2:30.00'; + } + + if (isset($this->request->post['shipping_royal_mail_international_tracked_signed_status'])) { + $data['shipping_royal_mail_international_tracked_signed_status'] = $this->request->post['shipping_royal_mail_international_tracked_signed_status']; + } else { + $data['shipping_royal_mail_international_tracked_signed_status'] = $this->config->get('shipping_royal_mail_international_tracked_signed_status'); + } + + // International Tracked + // Europe + if (isset($this->request->post['shipping_royal_mail_international_tracked_eu_rate'])) { + $data['shipping_royal_mail_international_tracked_eu_rate'] = $this->request->post['shipping_royal_mail_international_tracked_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_eu_rate')) { + $data['shipping_royal_mail_international_tracked_eu_rate'] = $this->config->get('shipping_royal_mail_international_tracked_eu_rate'); + } else { + $data['shipping_royal_mail_international_tracked_eu_rate'] = '0.02:7.16,0.06:7.76,0.1:9.84,0.25:10.44,0.5:12.18,0.75:13.92,1:15.66,1.25:17.40,1.5:19.14,1.75:20.88,2:22.62'; + } + + // International Tracked + // Non Europe + if (isset($this->request->post['shipping_royal_mail_international_tracked_non_eu_rate'])) { + $data['shipping_royal_mail_international_tracked_non_eu_rate'] = $this->request->post['shipping_royal_mail_international_tracked_non_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_non_eu_rate')) { + $data['shipping_royal_mail_international_tracked_non_eu_rate'] = $this->config->get('shipping_royal_mail_international_tracked_non_eu_rate'); + } else { + $data['shipping_royal_mail_international_tracked_non_eu_rate'] = '0.02:5.97,0.06:6.47,0.1:8.20,0.25:8.70,0.5:10.15,0.75:11.60,1:13.05,1.25:14.50,1.5:15.95,1.75:17.40,2:18.85'; + } + + // International Tracked + // World Zones 1 + if (isset($this->request->post['shipping_royal_mail_international_tracked_zone_1_rate'])) { + $data['shipping_royal_mail_international_tracked_zone_1_rate'] = $this->request->post['shipping_royal_mail_international_tracked_zone_1_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_zone_1_rate')) { + $data['shipping_royal_mail_international_tracked_zone_1_rate'] = $this->config->get('shipping_royal_mail_international_tracked_zone_1_rate'); + } else { + $data['shipping_royal_mail_international_tracked_zone_1_rate'] = '0.02:5.97,0.06:6.47,0.1:8.80,0.25:9.75,0.5:12.45,0.75:15.15,1:17.85,1.25:20.55,1.5:23.25,1.75:25.95,2:28.65'; + } + + // International Tracked + // World Zones 2 + if (isset($this->request->post['shipping_royal_mail_international_tracked_zone_2_rate'])) { + $data['shipping_royal_mail_international_tracked_zone_2_rate'] = $this->request->post['shipping_royal_mail_international_tracked_zone_2_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_tracked_zone_2_rate')) { + $data['shipping_royal_mail_international_tracked_zone_2_rate'] = $this->config->get('shipping_royal_mail_international_tracked_zone_2_rate'); + } else { + $data['shipping_royal_mail_international_tracked_zone_2_rate'] = '0.02:6.28,0.06:7.15,0.1:9.00,0.25:10.05,0.5:12.90,0.75:15.75,1:18.60,1.25:21.45,1.5:24.30,1.75:27.15,2:30.00'; + } + + if (isset($this->request->post['shipping_royal_mail_international_tracked_status'])) { + $data['shipping_royal_mail_international_tracked_status'] = $this->request->post['shipping_royal_mail_international_tracked_status']; + } else { + $data['shipping_royal_mail_international_tracked_status'] = $this->config->get('shipping_royal_mail_international_tracked_status'); + } + + // International Signed + // Europe + if (isset($this->request->post['shipping_royal_mail_international_signed_eu_rate'])) { + $data['shipping_royal_mail_international_signed_eu_rate'] = $this->request->post['shipping_royal_mail_international_signed_eu_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_signed_eu_rate')) { + $data['shipping_royal_mail_international_signed_eu_rate'] = $this->config->get('shipping_royal_mail_international_signed_eu_rate'); + } else { + $data['shipping_royal_mail_international_signed_eu_rate'] = '0.02:5.97,0.06:6.47,0.1:8.20,0.25:8.70,0.5:10.15,0.75:11.60,1:13.05,1.25:14.50,1.5:15.95,1.75:17.40,2:18.85'; + } + + // International Signed + // World Zones 1 + if (isset($this->request->post['shipping_royal_mail_international_signed_zone_1_rate'])) { + $data['shipping_royal_mail_international_signed_zone_1_rate'] = $this->request->post['shipping_royal_mail_international_signed_zone_1_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_signed_zone_1_rate')) { + $data['shipping_royal_mail_international_signed_zone_1_rate'] = $this->config->get('shipping_royal_mail_international_signed_zone_1_rate'); + } else { + $data['shipping_royal_mail_international_signed_zone_1_rate'] = '0.02:6.28,0.06:7.15,0.1:8.80,0.25:9.75,0.5:12.45,0.75:15.15,1:17.85,1.25:20.55,1.5:23.25,1.75:25.95,2:28.65'; + } + + // International Signed + // World Zones 2 + if (isset($this->request->post['shipping_royal_mail_international_signed_zone_2_rate'])) { + $data['shipping_royal_mail_international_signed_zone_2_rate'] = $this->request->post['shipping_royal_mail_international_signed_zone_2_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_signed_zone_2_rate')) { + $data['shipping_royal_mail_international_signed_zone_2_rate'] = $this->config->get('shipping_royal_mail_international_signed_zone_2_rate'); + } else { + $data['shipping_royal_mail_international_signed_zone_2_rate'] = '0.02:6.28,0.06:7.15,0.1:9.00,0.25:10.05,0.5:12.90,0.75:15.75,1:18.60,1.25:21.45,1.5:24.30,1.75:27.15,2:30.00'; + } + + if (isset($this->request->post['shipping_royal_mail_international_signed_status'])) { + $data['shipping_royal_mail_international_signed_status'] = $this->request->post['shipping_royal_mail_international_signed_status']; + } else { + $data['shipping_royal_mail_international_signed_status'] = $this->config->get('shipping_royal_mail_international_signed_status'); + } + + // International Economy + if (isset($this->request->post['shipping_royal_mail_international_economy_rate'])) { + $data['shipping_royal_mail_international_economy_rate'] = $this->request->post['shipping_royal_mail_international_economy_rate']; + } elseif ($this->config->has('shipping_royal_mail_international_economy_rate')) { + $data['shipping_royal_mail_international_economy_rate'] = $this->config->get('shipping_royal_mail_international_economy_rate'); + } else { + $data['shipping_royal_mail_international_economy_rate'] = '0.02:0.81,0.06:1.43,0.1:2.80,0.25:3.65,0.5:5.10,0.75:6.55,1:8.00,1.25:9.45,1.5:10.90,1.75:12.35,2:13.80'; + } + + if (isset($this->request->post['shipping_royal_mail_international_economy_status'])) { + $data['shipping_royal_mail_international_economy_status'] = $this->request->post['shipping_royal_mail_international_economy_status']; + } else { + $data['shipping_royal_mail_international_economy_status'] = $this->config->get('shipping_royal_mail_international_economy_status'); + } + + if (isset($this->request->post['shipping_royal_mail_display_weight'])) { + $data['shipping_royal_mail_display_weight'] = $this->request->post['shipping_royal_mail_display_weight']; + } else { + $data['shipping_royal_mail_display_weight'] = $this->config->get('shipping_royal_mail_display_weight'); + } + + if (isset($this->request->post['shipping_royal_mail_display_insurance'])) { + $data['shipping_royal_mail_display_insurance'] = $this->request->post['shipping_royal_mail_display_insurance']; + } else { + $data['shipping_royal_mail_display_insurance'] = $this->config->get('shipping_royal_mail_display_insurance'); + } + + if (isset($this->request->post['shipping_royal_mail_weight_class_id'])) { + $data['shipping_royal_mail_weight_class_id'] = $this->request->post['shipping_royal_mail_weight_class_id']; + } else { + $data['shipping_royal_mail_weight_class_id'] = $this->config->get('shipping_royal_mail_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_royal_mail_tax_class_id'])) { + $data['shipping_royal_mail_tax_class_id'] = $this->request->post['shipping_royal_mail_tax_class_id']; + } else { + $data['shipping_royal_mail_tax_class_id'] = $this->config->get('shipping_royal_mail_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_royal_mail_geo_zone_id'])) { + $data['shipping_royal_mail_geo_zone_id'] = $this->request->post['shipping_royal_mail_geo_zone_id']; + } else { + $data['shipping_royal_mail_geo_zone_id'] = $this->config->get('shipping_royal_mail_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_royal_mail_status'])) { + $data['shipping_royal_mail_status'] = $this->request->post['shipping_royal_mail_status']; + } else { + $data['shipping_royal_mail_status'] = $this->config->get('shipping_royal_mail_status'); + } + + if (isset($this->request->post['shipping_royal_mail_sort_order'])) { + $data['shipping_royal_mail_sort_order'] = $this->request->post['shipping_royal_mail_sort_order']; + } else { + $data['shipping_royal_mail_sort_order'] = $this->config->get('shipping_royal_mail_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/royal_mail', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/royal_mail')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/ups.php b/public/admin/controller/extension/shipping/ups.php new file mode 100644 index 0000000..dfb0e4a --- /dev/null +++ b/public/admin/controller/extension/shipping/ups.php @@ -0,0 +1,744 @@ +<?php +class ControllerExtensionShippingUPS extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/ups'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_ups', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['key'])) { + $data['error_key'] = $this->error['key']; + } else { + $data['error_key'] = ''; + } + + if (isset($this->error['username'])) { + $data['error_username'] = $this->error['username']; + } else { + $data['error_username'] = ''; + } + + if (isset($this->error['password'])) { + $data['error_password'] = $this->error['password']; + } else { + $data['error_password'] = ''; + } + + if (isset($this->error['city'])) { + $data['error_city'] = $this->error['city']; + } else { + $data['error_city'] = ''; + } + + if (isset($this->error['state'])) { + $data['error_state'] = $this->error['state']; + } else { + $data['error_state'] = ''; + } + + if (isset($this->error['country'])) { + $data['error_country'] = $this->error['country']; + } else { + $data['error_country'] = ''; + } + + if (isset($this->error['dimension'])) { + $data['error_dimension'] = $this->error['dimension']; + } else { + $data['error_dimension'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/ups', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/ups', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_ups_key'])) { + $data['shipping_ups_key'] = $this->request->post['shipping_ups_key']; + } else { + $data['shipping_ups_key'] = $this->config->get('shipping_ups_key'); + } + + if (isset($this->request->post['shipping_ups_username'])) { + $data['shipping_ups_username'] = $this->request->post['shipping_ups_username']; + } else { + $data['shipping_ups_username'] = $this->config->get('shipping_ups_username'); + } + + if (isset($this->request->post['shipping_ups_password'])) { + $data['shipping_ups_password'] = $this->request->post['shipping_ups_password']; + } else { + $data['shipping_ups_password'] = $this->config->get('shipping_ups_password'); + } + + if (isset($this->request->post['shipping_ups_pickup'])) { + $data['shipping_ups_pickup'] = $this->request->post['shipping_ups_pickup']; + } else { + $data['shipping_ups_pickup'] = $this->config->get('shipping_ups_pickup'); + } + + $data['pickups'] = array(); + + $data['pickups'][] = array( + 'value' => '01', + 'text' => $this->language->get('text_daily_pickup') + ); + + $data['pickups'][] = array( + 'value' => '03', + 'text' => $this->language->get('text_customer_counter') + ); + + $data['pickups'][] = array( + 'value' => '06', + 'text' => $this->language->get('text_one_time_pickup') + ); + + $data['pickups'][] = array( + 'value' => '07', + 'text' => $this->language->get('text_on_call_air_pickup') + ); + + $data['pickups'][] = array( + 'value' => '19', + 'text' => $this->language->get('text_letter_center') + ); + + $data['pickups'][] = array( + 'value' => '20', + 'text' => $this->language->get('text_air_service_center') + ); + + $data['pickups'][] = array( + 'value' => '11', + 'text' => $this->language->get('text_suggested_retail_rates') + ); + + if (isset($this->request->post['shipping_ups_packaging'])) { + $data['shipping_ups_packaging'] = $this->request->post['shipping_ups_packaging']; + } else { + $data['shipping_ups_packaging'] = $this->config->get('shipping_ups_packaging'); + } + + $data['packages'] = array(); + + $data['packages'][] = array( + 'value' => '02', + 'text' => $this->language->get('text_package') + ); + + $data['packages'][] = array( + 'value' => '01', + 'text' => $this->language->get('text_ups_letter') + ); + + $data['packages'][] = array( + 'value' => '03', + 'text' => $this->language->get('text_ups_tube') + ); + + $data['packages'][] = array( + 'value' => '04', + 'text' => $this->language->get('text_ups_pak') + ); + + $data['packages'][] = array( + 'value' => '21', + 'text' => $this->language->get('text_ups_express_box') + ); + + $data['packages'][] = array( + 'value' => '24', + 'text' => $this->language->get('text_ups_25kg_box') + ); + + $data['packages'][] = array( + 'value' => '25', + 'text' => $this->language->get('text_ups_10kg_box') + ); + + if (isset($this->request->post['shipping_ups_classification'])) { + $data['shipping_ups_classification'] = $this->request->post['shipping_ups_classification']; + } else { + $data['shipping_ups_classification'] = $this->config->get('shipping_ups_classification'); + } + + $data['classifications'][] = array( + 'value' => '01', + 'text' => '01' + ); + + $data['classifications'][] = array( + 'value' => '03', + 'text' => '03' + ); + + $data['classifications'][] = array( + 'value' => '04', + 'text' => '04' + ); + + if (isset($this->request->post['shipping_ups_origin'])) { + $data['shipping_ups_origin'] = $this->request->post['shipping_ups_origin']; + } else { + $data['shipping_ups_origin'] = $this->config->get('shipping_ups_origin'); + } + + $data['origins'] = array(); + + $data['origins'][] = array( + 'value' => 'US', + 'text' => $this->language->get('text_us') + ); + + $data['origins'][] = array( + 'value' => 'CA', + 'text' => $this->language->get('text_ca') + ); + + $data['origins'][] = array( + 'value' => 'EU', + 'text' => $this->language->get('text_eu') + ); + + $data['origins'][] = array( + 'value' => 'PR', + 'text' => $this->language->get('text_pr') + ); + + $data['origins'][] = array( + 'value' => 'MX', + 'text' => $this->language->get('text_mx') + ); + + $data['origins'][] = array( + 'value' => 'other', + 'text' => $this->language->get('text_other') + ); + + if (isset($this->request->post['shipping_ups_city'])) { + $data['shipping_ups_city'] = $this->request->post['shipping_ups_city']; + } else { + $data['shipping_ups_city'] = $this->config->get('shipping_ups_city'); + } + + if (isset($this->request->post['shipping_ups_state'])) { + $data['shipping_ups_state'] = $this->request->post['shipping_ups_state']; + } else { + $data['shipping_ups_state'] = $this->config->get('shipping_ups_state'); + } + + if (isset($this->request->post['shipping_ups_country'])) { + $data['shipping_ups_country'] = $this->request->post['shipping_ups_country']; + } else { + $data['shipping_ups_country'] = $this->config->get('shipping_ups_country'); + } + + if (isset($this->request->post['shipping_ups_postcode'])) { + $data['shipping_ups_postcode'] = $this->request->post['shipping_ups_postcode']; + } else { + $data['shipping_ups_postcode'] = $this->config->get('shipping_ups_postcode'); + } + + if (isset($this->request->post['shipping_ups_test'])) { + $data['shipping_ups_test'] = $this->request->post['shipping_ups_test']; + } else { + $data['shipping_ups_test'] = $this->config->get('shipping_ups_test'); + } + + if (isset($this->request->post['shipping_ups_quote_type'])) { + $data['shipping_ups_quote_type'] = $this->request->post['shipping_ups_quote_type']; + } else { + $data['shipping_ups_quote_type'] = $this->config->get('shipping_ups_quote_type'); + } + + $data['quote_types'] = array(); + + $data['quote_types'][] = array( + 'value' => 'residential', + 'text' => $this->language->get('text_residential') + ); + + $data['quote_types'][] = array( + 'value' => 'commercial', + 'text' => $this->language->get('text_commercial') + ); + + // US + if (isset($this->request->post['shipping_ups_us_01'])) { + $data['shipping_ups_us_01'] = $this->request->post['shipping_ups_us_01']; + } else { + $data['shipping_ups_us_01'] = $this->config->get('shipping_ups_us_01'); + } + + if (isset($this->request->post['shipping_ups_us_02'])) { + $data['shipping_ups_us_02'] = $this->request->post['shipping_ups_us_02']; + } else { + $data['shipping_ups_us_02'] = $this->config->get('shipping_ups_us_02'); + } + + if (isset($this->request->post['shipping_ups_us_03'])) { + $data['shipping_ups_us_03'] = $this->request->post['shipping_ups_us_03']; + } else { + $data['shipping_ups_us_03'] = $this->config->get('shipping_ups_us_03'); + } + + if (isset($this->request->post['shipping_ups_us_07'])) { + $data['shipping_ups_us_07'] = $this->request->post['shipping_ups_us_07']; + } else { + $data['shipping_ups_us_07'] = $this->config->get('shipping_ups_us_07'); + } + + if (isset($this->request->post['shipping_ups_us_08'])) { + $data['shipping_ups_us_08'] = $this->request->post['shipping_ups_us_08']; + } else { + $data['shipping_ups_us_08'] = $this->config->get('shipping_ups_us_08'); + } + + if (isset($this->request->post['shipping_ups_us_11'])) { + $data['shipping_ups_us_11'] = $this->request->post['shipping_ups_us_11']; + } else { + $data['shipping_ups_us_11'] = $this->config->get('shipping_ups_us_11'); + } + + if (isset($this->request->post['shipping_ups_us_12'])) { + $data['shipping_ups_us_12'] = $this->request->post['shipping_ups_us_12']; + } else { + $data['shipping_ups_us_12'] = $this->config->get('shipping_ups_us_12'); + } + + if (isset($this->request->post['shipping_ups_us_13'])) { + $data['shipping_ups_us_13'] = $this->request->post['shipping_ups_us_13']; + } else { + $data['shipping_ups_us_13'] = $this->config->get('shipping_ups_us_13'); + } + + if (isset($this->request->post['shipping_ups_us_14'])) { + $data['shipping_ups_us_14'] = $this->request->post['shipping_ups_us_14']; + } else { + $data['shipping_ups_us_14'] = $this->config->get('shipping_ups_us_14'); + } + + if (isset($this->request->post['shipping_ups_us_54'])) { + $data['shipping_ups_us_54'] = $this->request->post['shipping_ups_us_54']; + } else { + $data['shipping_ups_us_54'] = $this->config->get('shipping_ups_us_54'); + } + + if (isset($this->request->post['shipping_ups_us_59'])) { + $data['shipping_ups_us_59'] = $this->request->post['shipping_ups_us_59']; + } else { + $data['shipping_ups_us_59'] = $this->config->get('shipping_ups_us_59'); + } + + if (isset($this->request->post['shipping_ups_us_65'])) { + $data['shipping_ups_us_65'] = $this->request->post['shipping_ups_us_65']; + } else { + $data['shipping_ups_us_65'] = $this->config->get('shipping_ups_us_65'); + } + + // Puerto Rico + if (isset($this->request->post['shipping_ups_pr_01'])) { + $data['shipping_ups_pr_01'] = $this->request->post['shipping_ups_pr_01']; + } else { + $data['shipping_ups_pr_01'] = $this->config->get('shipping_ups_pr_01'); + } + + if (isset($this->request->post['shipping_ups_pr_02'])) { + $data['shipping_ups_pr_02'] = $this->request->post['shipping_ups_pr_02']; + } else { + $data['shipping_ups_pr_02'] = $this->config->get('shipping_ups_pr_02'); + } + + if (isset($this->request->post['shipping_ups_pr_03'])) { + $data['shipping_ups_pr_03'] = $this->request->post['shipping_ups_pr_03']; + } else { + $data['shipping_ups_pr_03'] = $this->config->get('shipping_ups_pr_03'); + } + + if (isset($this->request->post['shipping_ups_pr_07'])) { + $data['shipping_ups_pr_07'] = $this->request->post['shipping_ups_pr_07']; + } else { + $data['shipping_ups_pr_07'] = $this->config->get('shipping_ups_pr_07'); + } + + if (isset($this->request->post['shipping_ups_pr_08'])) { + $data['shipping_ups_pr_08'] = $this->request->post['shipping_ups_pr_08']; + } else { + $data['shipping_ups_pr_08'] = $this->config->get('shipping_ups_pr_08'); + } + + if (isset($this->request->post['shipping_ups_pr_14'])) { + $data['shipping_ups_pr_14'] = $this->request->post['shipping_ups_pr_14']; + } else { + $data['shipping_ups_pr_14'] = $this->config->get('shipping_ups_pr_14'); + } + + if (isset($this->request->post['shipping_ups_pr_54'])) { + $data['shipping_ups_pr_54'] = $this->request->post['shipping_ups_pr_54']; + } else { + $data['shipping_ups_pr_54'] = $this->config->get('shipping_ups_pr_54'); + } + + if (isset($this->request->post['shipping_ups_pr_65'])) { + $data['shipping_ups_pr_65'] = $this->request->post['shipping_ups_pr_65']; + } else { + $data['shipping_ups_pr_65'] = $this->config->get('shipping_ups_pr_65'); + } + + // Canada + if (isset($this->request->post['shipping_ups_ca_01'])) { + $data['shipping_ups_ca_01'] = $this->request->post['shipping_ups_ca_01']; + } else { + $data['shipping_ups_ca_01'] = $this->config->get('shipping_ups_ca_01'); + } + + if (isset($this->request->post['shipping_ups_ca_02'])) { + $data['shipping_ups_ca_02'] = $this->request->post['shipping_ups_ca_02']; + } else { + $data['shipping_ups_ca_02'] = $this->config->get('shipping_ups_ca_02'); + } + + if (isset($this->request->post['shipping_ups_ca_07'])) { + $data['shipping_ups_ca_07'] = $this->request->post['shipping_ups_ca_07']; + } else { + $data['shipping_ups_ca_07'] = $this->config->get('shipping_ups_ca_07'); + } + + if (isset($this->request->post['shipping_ups_ca_08'])) { + $data['shipping_ups_ca_08'] = $this->request->post['shipping_ups_ca_08']; + } else { + $data['shipping_ups_ca_08'] = $this->config->get('shipping_ups_ca_08'); + } + + if (isset($this->request->post['shipping_ups_ca_11'])) { + $data['shipping_ups_ca_11'] = $this->request->post['shipping_ups_ca_11']; + } else { + $data['shipping_ups_ca_11'] = $this->config->get('shipping_ups_ca_11'); + } + + if (isset($this->request->post['shipping_ups_ca_12'])) { + $data['shipping_ups_ca_12'] = $this->request->post['shipping_ups_ca_12']; + } else { + $data['shipping_ups_ca_12'] = $this->config->get('shipping_ups_ca_12'); + } + + if (isset($this->request->post['shipping_ups_ca_13'])) { + $data['shipping_ups_ca_13'] = $this->request->post['shipping_ups_ca_13']; + } else { + $data['shipping_ups_ca_13'] = $this->config->get('shipping_ups_ca_13'); + } + + if (isset($this->request->post['shipping_ups_ca_14'])) { + $data['shipping_ups_ca_14'] = $this->request->post['shipping_ups_ca_14']; + } else { + $data['shipping_ups_ca_14'] = $this->config->get('shipping_ups_ca_14'); + } + + if (isset($this->request->post['shipping_ups_ca_54'])) { + $data['shipping_ups_ca_54'] = $this->request->post['shipping_ups_ca_54']; + } else { + $data['shipping_ups_ca_54'] = $this->config->get('shipping_ups_ca_54'); + } + + if (isset($this->request->post['shipping_ups_ca_65'])) { + $data['shipping_ups_ca_65'] = $this->request->post['shipping_ups_ca_65']; + } else { + $data['shipping_ups_ca_65'] = $this->config->get('shipping_ups_ca_65'); + } + + // Mexico + if (isset($this->request->post['shipping_ups_mx_07'])) { + $data['shipping_ups_mx_07'] = $this->request->post['shipping_ups_mx_07']; + } else { + $data['shipping_ups_mx_07'] = $this->config->get('shipping_ups_mx_07'); + } + + if (isset($this->request->post['shipping_ups_mx_08'])) { + $data['shipping_ups_mx_08'] = $this->request->post['shipping_ups_mx_08']; + } else { + $data['shipping_ups_mx_08'] = $this->config->get('shipping_ups_mx_08'); + } + + if (isset($this->request->post['shipping_ups_mx_54'])) { + $data['shipping_ups_mx_54'] = $this->request->post['shipping_ups_mx_54']; + } else { + $data['shipping_ups_mx_54'] = $this->config->get('shipping_ups_mx_54'); + } + + if (isset($this->request->post['shipping_ups_mx_65'])) { + $data['shipping_ups_mx_65'] = $this->request->post['shipping_ups_mx_65']; + } else { + $data['shipping_ups_mx_65'] = $this->config->get('shipping_ups_mx_65'); + } + + // EU + if (isset($this->request->post['shipping_ups_eu_07'])) { + $data['shipping_ups_eu_07'] = $this->request->post['shipping_ups_eu_07']; + } else { + $data['shipping_ups_eu_07'] = $this->config->get('shipping_ups_eu_07'); + } + + if (isset($this->request->post['shipping_ups_eu_08'])) { + $data['shipping_ups_eu_08'] = $this->request->post['shipping_ups_eu_08']; + } else { + $data['shipping_ups_eu_08'] = $this->config->get('shipping_ups_eu_08'); + } + + if (isset($this->request->post['shipping_ups_eu_11'])) { + $data['shipping_ups_eu_11'] = $this->request->post['shipping_ups_eu_11']; + } else { + $data['shipping_ups_eu_11'] = $this->config->get('shipping_ups_eu_11'); + } + + if (isset($this->request->post['shipping_ups_eu_54'])) { + $data['shipping_ups_eu_54'] = $this->request->post['shipping_ups_eu_54']; + } else { + $data['shipping_ups_eu_54'] = $this->config->get('shipping_ups_eu_54'); + } + + if (isset($this->request->post['shipping_ups_eu_65'])) { + $data['shipping_ups_eu_65'] = $this->request->post['shipping_ups_eu_65']; + } else { + $data['shipping_ups_eu_65'] = $this->config->get('shipping_ups_eu_65'); + } + + if (isset($this->request->post['shipping_ups_eu_82'])) { + $data['shipping_ups_eu_82'] = $this->request->post['shipping_ups_eu_82']; + } else { + $data['shipping_ups_eu_82'] = $this->config->get('shipping_ups_eu_82'); + } + + if (isset($this->request->post['shipping_ups_eu_83'])) { + $data['shipping_ups_eu_83'] = $this->request->post['shipping_ups_eu_83']; + } else { + $data['shipping_ups_eu_83'] = $this->config->get('shipping_ups_eu_83'); + } + + if (isset($this->request->post['shipping_ups_eu_84'])) { + $data['shipping_ups_eu_84'] = $this->request->post['shipping_ups_eu_84']; + } else { + $data['shipping_ups_eu_84'] = $this->config->get('shipping_ups_eu_84'); + } + + if (isset($this->request->post['shipping_ups_eu_85'])) { + $data['shipping_ups_eu_85'] = $this->request->post['shipping_ups_eu_85']; + } else { + $data['shipping_ups_eu_85'] = $this->config->get('shipping_ups_eu_85'); + } + + if (isset($this->request->post['shipping_ups_eu_86'])) { + $data['shipping_ups_eu_86'] = $this->request->post['shipping_ups_eu_86']; + } else { + $data['shipping_ups_eu_86'] = $this->config->get('shipping_ups_eu_86'); + } + + // Other + if (isset($this->request->post['shipping_ups_other_07'])) { + $data['shipping_ups_other_07'] = $this->request->post['shipping_ups_other_07']; + } else { + $data['shipping_ups_other_07'] = $this->config->get('shipping_ups_other_07'); + } + + if (isset($this->request->post['shipping_ups_other_08'])) { + $data['shipping_ups_other_08'] = $this->request->post['shipping_ups_other_08']; + } else { + $data['shipping_ups_other_08'] = $this->config->get('shipping_ups_other_08'); + } + + if (isset($this->request->post['shipping_ups_other_11'])) { + $data['shipping_ups_other_11'] = $this->request->post['shipping_ups_other_11']; + } else { + $data['shipping_ups_other_11'] = $this->config->get('shipping_ups_other_11'); + } + + if (isset($this->request->post['shipping_ups_other_54'])) { + $data['shipping_ups_other_54'] = $this->request->post['shipping_ups_other_54']; + } else { + $data['shipping_ups_other_54'] = $this->config->get('shipping_ups_other_54'); + } + + if (isset($this->request->post['shipping_ups_other_65'])) { + $data['shipping_ups_other_65'] = $this->request->post['shipping_ups_other_65']; + } else { + $data['shipping_ups_other_65'] = $this->config->get('shipping_ups_other_65'); + } + + if (isset($this->request->post['shipping_ups_display_weight'])) { + $data['shipping_ups_display_weight'] = $this->request->post['shipping_ups_display_weight']; + } else { + $data['shipping_ups_display_weight'] = $this->config->get('shipping_ups_display_weight'); + } + + if (isset($this->request->post['shipping_ups_insurance'])) { + $data['shipping_ups_insurance'] = $this->request->post['shipping_ups_insurance']; + } else { + $data['shipping_ups_insurance'] = $this->config->get('shipping_ups_insurance'); + } + + if (isset($this->request->post['shipping_ups_weight_class_id'])) { + $data['shipping_ups_weight_class_id'] = $this->request->post['shipping_ups_weight_class_id']; + } else { + $data['shipping_ups_weight_class_id'] = $this->config->get('shipping_ups_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_ups_length_code'])) { + $data['shipping_ups_length_code'] = $this->request->post['shipping_ups_length_code']; + } else { + $data['shipping_ups_length_code'] = $this->config->get('shipping_ups_length_code'); + } + + if (isset($this->request->post['shipping_ups_length_class_id'])) { + $data['shipping_ups_length_class_id'] = $this->request->post['shipping_ups_length_class_id']; + } else { + $data['shipping_ups_length_class_id'] = $this->config->get('shipping_ups_length_class_id'); + } + + $this->load->model('localisation/length_class'); + + $data['length_classes'] = $this->model_localisation_length_class->getLengthClasses(); + + if (isset($this->request->post['shipping_ups_length'])) { + $data['shipping_ups_length'] = $this->request->post['shipping_ups_length']; + } else { + $data['shipping_ups_length'] = $this->config->get('shipping_ups_length'); + } + + if (isset($this->request->post['shipping_ups_width'])) { + $data['shipping_ups_width'] = $this->request->post['shipping_ups_width']; + } else { + $data['shipping_ups_width'] = $this->config->get('shipping_ups_width'); + } + + if (isset($this->request->post['shipping_ups_height'])) { + $data['shipping_ups_height'] = $this->request->post['shipping_ups_height']; + } else { + $data['shipping_ups_height'] = $this->config->get('shipping_ups_height'); + } + + if (isset($this->request->post['shipping_ups_tax_class_id'])) { + $data['shipping_ups_tax_class_id'] = $this->request->post['shipping_ups_tax_class_id']; + } else { + $data['shipping_ups_tax_class_id'] = $this->config->get('shipping_ups_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_ups_geo_zone_id'])) { + $data['shipping_ups_geo_zone_id'] = $this->request->post['shipping_ups_geo_zone_id']; + } else { + $data['shipping_ups_geo_zone_id'] = $this->config->get('shipping_ups_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_ups_status'])) { + $data['shipping_ups_status'] = $this->request->post['shipping_ups_status']; + } else { + $data['shipping_ups_status'] = $this->config->get('shipping_ups_status'); + } + + if (isset($this->request->post['shipping_ups_sort_order'])) { + $data['shipping_ups_sort_order'] = $this->request->post['shipping_ups_sort_order']; + } else { + $data['shipping_ups_sort_order'] = $this->config->get('shipping_ups_sort_order'); + } + + if (isset($this->request->post['shipping_ups_debug'])) { + $data['shipping_ups_debug'] = $this->request->post['shipping_ups_debug']; + } else { + $data['shipping_ups_debug'] = $this->config->get('shipping_ups_debug'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/ups', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/ups')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['shipping_ups_key']) { + $this->error['key'] = $this->language->get('error_key'); + } + + if (!$this->request->post['shipping_ups_username']) { + $this->error['username'] = $this->language->get('error_username'); + } + + if (!$this->request->post['shipping_ups_password']) { + $this->error['password'] = $this->language->get('error_password'); + } + + if (!$this->request->post['shipping_ups_city']) { + $this->error['city'] = $this->language->get('error_city'); + } + + if (!$this->request->post['shipping_ups_state']) { + $this->error['state'] = $this->language->get('error_state'); + } + + if (!$this->request->post['shipping_ups_country']) { + $this->error['country'] = $this->language->get('error_country'); + } + + if (empty($this->request->post['shipping_ups_length'])) { + $this->error['dimension'] = $this->language->get('error_dimension'); + } + + if (empty($this->request->post['shipping_ups_width'])) { + $this->error['dimension'] = $this->language->get('error_dimension'); + } + + if (empty($this->request->post['shipping_ups_height'])) { + $this->error['dimension'] = $this->language->get('error_dimension'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/shipping/usps.php b/public/admin/controller/extension/shipping/usps.php new file mode 100644 index 0000000..503e35a --- /dev/null +++ b/public/admin/controller/extension/shipping/usps.php @@ -0,0 +1,464 @@ +<?php +class ControllerExtensionShippingUsps extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/usps'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_usps', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['user_id'])) { + $data['error_user_id'] = $this->error['user_id']; + } else { + $data['error_user_id'] = ''; + } + + if (isset($this->error['postcode'])) { + $data['error_postcode'] = $this->error['postcode']; + } else { + $data['error_postcode'] = ''; + } + + if (isset($this->error['dimension'])) { + $data['error_dimension'] = $this->error['dimension']; + } else { + $data['error_dimension'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/usps', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/usps', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + if (isset($this->request->post['shipping_usps_user_id'])) { + $data['shipping_usps_user_id'] = $this->request->post['shipping_usps_user_id']; + } else { + $data['shipping_usps_user_id'] = $this->config->get('shipping_usps_user_id'); + } + + if (isset($this->request->post['shipping_usps_postcode'])) { + $data['shipping_usps_postcode'] = $this->request->post['shipping_usps_postcode']; + } else { + $data['shipping_usps_postcode'] = $this->config->get('shipping_usps_postcode'); + } + + if (isset($this->request->post['shipping_usps_domestic_00'])) { + $data['shipping_usps_domestic_00'] = $this->request->post['shipping_usps_domestic_00']; + } else { + $data['shipping_usps_domestic_00'] = $this->config->get('shipping_usps_domestic_00'); + } + + if (isset($this->request->post['shipping_usps_domestic_01'])) { + $data['shipping_usps_domestic_01'] = $this->request->post['shipping_usps_domestic_01']; + } else { + $data['shipping_usps_domestic_01'] = $this->config->get('shipping_usps_domestic_01'); + } + + if (isset($this->request->post['shipping_usps_domestic_02'])) { + $data['shipping_usps_domestic_02'] = $this->request->post['shipping_usps_domestic_02']; + } else { + $data['shipping_usps_domestic_02'] = $this->config->get('shipping_usps_domestic_02'); + } + + if (isset($this->request->post['shipping_usps_domestic_03'])) { + $data['shipping_usps_domestic_03'] = $this->request->post['shipping_usps_domestic_03']; + } else { + $data['shipping_usps_domestic_03'] = $this->config->get('shipping_usps_domestic_03'); + } + + if (isset($this->request->post['shipping_usps_domestic_1'])) { + $data['shipping_usps_domestic_1'] = $this->request->post['shipping_usps_domestic_1']; + } else { + $data['shipping_usps_domestic_1'] = $this->config->get('shipping_usps_domestic_1'); + } + + if (isset($this->request->post['shipping_usps_domestic_2'])) { + $data['shipping_usps_domestic_2'] = $this->request->post['shipping_usps_domestic_2']; + } else { + $data['shipping_usps_domestic_2'] = $this->config->get('shipping_usps_domestic_2'); + } + + if (isset($this->request->post['shipping_usps_domestic_3'])) { + $data['shipping_usps_domestic_3'] = $this->request->post['shipping_usps_domestic_3']; + } else { + $data['shipping_usps_domestic_3'] = $this->config->get('shipping_usps_domestic_3'); + } + + if (isset($this->request->post['shipping_usps_domestic_4'])) { + $data['shipping_usps_domestic_4'] = $this->request->post['shipping_usps_domestic_4']; + } else { + $data['shipping_usps_domestic_4'] = $this->config->get('shipping_usps_domestic_4'); + } + + if (isset($this->request->post['shipping_usps_domestic_5'])) { + $data['shipping_usps_domestic_5'] = $this->request->post['shipping_usps_domestic_5']; + } else { + $data['shipping_usps_domestic_5'] = $this->config->get('shipping_usps_domestic_5'); + } + + if (isset($this->request->post['shipping_usps_domestic_6'])) { + $data['shipping_usps_domestic_6'] = $this->request->post['shipping_usps_domestic_6']; + } else { + $data['shipping_usps_domestic_6'] = $this->config->get('shipping_usps_domestic_6'); + } + + if (isset($this->request->post['shipping_usps_domestic_7'])) { + $data['shipping_usps_domestic_7'] = $this->request->post['shipping_usps_domestic_7']; + } else { + $data['shipping_usps_domestic_7'] = $this->config->get('shipping_usps_domestic_7'); + } + + if (isset($this->request->post['shipping_usps_domestic_12'])) { + $data['shipping_usps_domestic_12'] = $this->request->post['shipping_usps_domestic_12']; + } else { + $data['shipping_usps_domestic_12'] = $this->config->get('shipping_usps_domestic_12'); + } + + if (isset($this->request->post['shipping_usps_domestic_13'])) { + $data['shipping_usps_domestic_13'] = $this->request->post['shipping_usps_domestic_13']; + } else { + $data['shipping_usps_domestic_13'] = $this->config->get('shipping_usps_domestic_13'); + } + + if (isset($this->request->post['shipping_usps_domestic_16'])) { + $data['shipping_usps_domestic_16'] = $this->request->post['shipping_usps_domestic_16']; + } else { + $data['shipping_usps_domestic_16'] = $this->config->get('shipping_usps_domestic_16'); + } + + if (isset($this->request->post['shipping_usps_domestic_17'])) { + $data['shipping_usps_domestic_17'] = $this->request->post['shipping_usps_domestic_17']; + } else { + $data['shipping_usps_domestic_17'] = $this->config->get('shipping_usps_domestic_17'); + } + + if (isset($this->request->post['shipping_usps_domestic_18'])) { + $data['shipping_usps_domestic_18'] = $this->request->post['shipping_usps_domestic_18']; + } else { + $data['shipping_usps_domestic_18'] = $this->config->get('shipping_usps_domestic_18'); + } + + if (isset($this->request->post['shipping_usps_domestic_19'])) { + $data['shipping_usps_domestic_19'] = $this->request->post['shipping_usps_domestic_19']; + } else { + $data['shipping_usps_domestic_19'] = $this->config->get('shipping_usps_domestic_19'); + } + + if (isset($this->request->post['shipping_usps_domestic_22'])) { + $data['shipping_usps_domestic_22'] = $this->request->post['shipping_usps_domestic_22']; + } else { + $data['shipping_usps_domestic_22'] = $this->config->get('shipping_usps_domestic_22'); + } + + if (isset($this->request->post['shipping_usps_domestic_23'])) { + $data['shipping_usps_domestic_23'] = $this->request->post['shipping_usps_domestic_23']; + } else { + $data['shipping_usps_domestic_23'] = $this->config->get('shipping_usps_domestic_23'); + } + + if (isset($this->request->post['shipping_usps_domestic_25'])) { + $data['shipping_usps_domestic_25'] = $this->request->post['shipping_usps_domestic_25']; + } else { + $data['shipping_usps_domestic_25'] = $this->config->get('shipping_usps_domestic_25'); + } + + if (isset($this->request->post['shipping_usps_domestic_27'])) { + $data['shipping_usps_domestic_27'] = $this->request->post['shipping_usps_domestic_27']; + } else { + $data['shipping_usps_domestic_27'] = $this->config->get('shipping_usps_domestic_27'); + } + + if (isset($this->request->post['shipping_usps_domestic_28'])) { + $data['shipping_usps_domestic_28'] = $this->request->post['shipping_usps_domestic_28']; + } else { + $data['shipping_usps_domestic_28'] = $this->config->get('shipping_usps_domestic_28'); + } + + if (isset($this->request->post['shipping_usps_international_1'])) { + $data['shipping_usps_international_1'] = $this->request->post['shipping_usps_international_1']; + } else { + $data['shipping_usps_international_1'] = $this->config->get('shipping_usps_international_1'); + } + + if (isset($this->request->post['shipping_usps_international_2'])) { + $data['shipping_usps_international_2'] = $this->request->post['shipping_usps_international_2']; + } else { + $data['shipping_usps_international_2'] = $this->config->get('shipping_usps_international_2'); + } + + if (isset($this->request->post['shipping_usps_international_4'])) { + $data['shipping_usps_international_4'] = $this->request->post['shipping_usps_international_4']; + } else { + $data['shipping_usps_international_4'] = $this->config->get('shipping_usps_international_4'); + } + + if (isset($this->request->post['shipping_usps_international_5'])) { + $data['shipping_usps_international_5'] = $this->request->post['shipping_usps_international_5']; + } else { + $data['shipping_usps_international_5'] = $this->config->get('shipping_usps_international_5'); + } + + if (isset($this->request->post['shipping_usps_international_6'])) { + $data['shipping_usps_international_6'] = $this->request->post['shipping_usps_international_6']; + } else { + $data['shipping_usps_international_6'] = $this->config->get('shipping_usps_international_6'); + } + + if (isset($this->request->post['shipping_usps_international_7'])) { + $data['shipping_usps_international_7'] = $this->request->post['shipping_usps_international_7']; + } else { + $data['shipping_usps_international_7'] = $this->config->get('shipping_usps_international_7'); + } + + if (isset($this->request->post['shipping_usps_international_8'])) { + $data['shipping_usps_international_8'] = $this->request->post['shipping_usps_international_8']; + } else { + $data['shipping_usps_international_8'] = $this->config->get('shipping_usps_international_8'); + } + + if (isset($this->request->post['shipping_usps_international_9'])) { + $data['shipping_usps_international_9'] = $this->request->post['shipping_usps_international_9']; + } else { + $data['shipping_usps_international_9'] = $this->config->get('shipping_usps_international_9'); + } + + if (isset($this->request->post['shipping_usps_international_10'])) { + $data['shipping_usps_international_10'] = $this->request->post['shipping_usps_international_10']; + } else { + $data['shipping_usps_international_10'] = $this->config->get('shipping_usps_international_10'); + } + + if (isset($this->request->post['shipping_usps_international_11'])) { + $data['shipping_usps_international_11'] = $this->request->post['shipping_usps_international_11']; + } else { + $data['shipping_usps_international_11'] = $this->config->get('shipping_usps_international_11'); + } + + if (isset($this->request->post['shipping_usps_international_12'])) { + $data['shipping_usps_international_12'] = $this->request->post['shipping_usps_international_12']; + } else { + $data['shipping_usps_international_12'] = $this->config->get('shipping_usps_international_12'); + } + + if (isset($this->request->post['shipping_usps_international_13'])) { + $data['shipping_usps_international_13'] = $this->request->post['shipping_usps_international_13']; + } else { + $data['shipping_usps_international_13'] = $this->config->get('shipping_usps_international_13'); + } + + if (isset($this->request->post['shipping_usps_international_14'])) { + $data['shipping_usps_international_14'] = $this->request->post['shipping_usps_international_14']; + } else { + $data['shipping_usps_international_14'] = $this->config->get('shipping_usps_international_14'); + } + + if (isset($this->request->post['shipping_usps_international_15'])) { + $data['shipping_usps_international_15'] = $this->request->post['shipping_usps_international_15']; + } else { + $data['shipping_usps_international_15'] = $this->config->get('shipping_usps_international_15'); + } + + if (isset($this->request->post['shipping_usps_international_16'])) { + $data['shipping_usps_international_16'] = $this->request->post['shipping_usps_international_16']; + } else { + $data['shipping_usps_international_16'] = $this->config->get('shipping_usps_international_16'); + } + + if (isset($this->request->post['shipping_usps_international_21'])) { + $data['shipping_usps_international_21'] = $this->request->post['shipping_usps_international_21']; + } else { + $data['shipping_usps_international_21'] = $this->config->get('shipping_usps_international_21'); + } + + if (isset($this->request->post['shipping_usps_size'])) { + $data['shipping_usps_size'] = $this->request->post['shipping_usps_size']; + } else { + $data['shipping_usps_size'] = $this->config->get('shipping_usps_size'); + } + + $data['sizes'] = array(); + + $data['sizes'][] = array( + 'text' => $this->language->get('text_regular'), + 'value' => 'REGULAR' + ); + + $data['sizes'][] = array( + 'text' => $this->language->get('text_large'), + 'value' => 'LARGE' + ); + + if (isset($this->request->post['shipping_usps_container'])) { + $data['shipping_usps_container'] = $this->request->post['shipping_usps_container']; + } else { + $data['shipping_usps_container'] = $this->config->get('shipping_usps_container'); + } + + $data['containers'] = array(); + + $data['containers'][] = array( + 'text' => $this->language->get('text_rectangular'), + 'value' => 'RECTANGULAR' + ); + + $data['containers'][] = array( + 'text' => $this->language->get('text_non_rectangular'), + 'value' => 'NONRECTANGULAR' + ); + + $data['containers'][] = array( + 'text' => $this->language->get('text_variable'), + 'value' => 'VARIABLE' + ); + + if (isset($this->request->post['shipping_usps_machinable'])) { + $data['shipping_usps_machinable'] = $this->request->post['shipping_usps_machinable']; + } else { + $data['shipping_usps_machinable'] = $this->config->get('shipping_usps_machinable'); + } + + if (isset($this->request->post['shipping_usps_length'])) { + $data['shipping_usps_length'] = $this->request->post['shipping_usps_length']; + } else { + $data['shipping_usps_length'] = $this->config->get('shipping_usps_length'); + } + + if (isset($this->request->post['shipping_usps_width'])) { + $data['shipping_usps_width'] = $this->request->post['shipping_usps_width']; + } else { + $data['shipping_usps_width'] = $this->config->get('shipping_usps_width'); + } + + if (isset($this->request->post['shipping_usps_height'])) { + $data['shipping_usps_height'] = $this->request->post['shipping_usps_height']; + } else { + $data['shipping_usps_height'] = $this->config->get('shipping_usps_height'); + } + + if (isset($this->request->post['shipping_usps_display_time'])) { + $data['shipping_usps_display_time'] = $this->request->post['shipping_usps_display_time']; + } else { + $data['shipping_usps_display_time'] = $this->config->get('shipping_usps_display_time'); + } + + if (isset($this->request->post['shipping_usps_display_weight'])) { + $data['shipping_usps_display_weight'] = $this->request->post['shipping_usps_display_weight']; + } else { + $data['shipping_usps_display_weight'] = $this->config->get('shipping_usps_display_weight'); + } + + if (isset($this->request->post['shipping_usps_weight_class_id'])) { + $data['shipping_usps_weight_class_id'] = $this->request->post['shipping_usps_weight_class_id']; + } else { + $data['shipping_usps_weight_class_id'] = $this->config->get('shipping_usps_weight_class_id'); + } + + $this->load->model('localisation/weight_class'); + + $data['weight_classes'] = $this->model_localisation_weight_class->getWeightClasses(); + + if (isset($this->request->post['shipping_usps_tax_class_id'])) { + $data['shipping_usps_tax_class_id'] = $this->request->post['shipping_usps_tax_class_id']; + } else { + $data['shipping_usps_tax_class_id'] = $this->config->get('shipping_usps_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_usps_geo_zone_id'])) { + $data['shipping_usps_geo_zone_id'] = $this->request->post['shipping_usps_geo_zone_id']; + } else { + $data['shipping_usps_geo_zone_id'] = $this->config->get('shipping_usps_geo_zone_id'); + } + + $this->load->model('localisation/geo_zone'); + + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + + if (isset($this->request->post['shipping_usps_debug'])) { + $data['shipping_usps_debug'] = $this->request->post['shipping_usps_debug']; + } else { + $data['shipping_usps_debug'] = $this->config->get('shipping_usps_debug'); + } + + if (isset($this->request->post['shipping_usps_status'])) { + $data['shipping_usps_status'] = $this->request->post['shipping_usps_status']; + } else { + $data['shipping_usps_status'] = $this->config->get('shipping_usps_status'); + } + + if (isset($this->request->post['shipping_usps_sort_order'])) { + $data['shipping_usps_sort_order'] = $this->request->post['shipping_usps_sort_order']; + } else { + $data['shipping_usps_sort_order'] = $this->config->get('shipping_usps_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/usps', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/usps')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['shipping_usps_user_id']) { + $this->error['user_id'] = $this->language->get('error_user_id'); + } + + if (!$this->request->post['shipping_usps_postcode']) { + $this->error['postcode'] = $this->language->get('error_postcode'); + } + + if (!$this->request->post['shipping_usps_width']) { + $this->error['dimension'] = $this->language->get('error_width'); + } + + if (!$this->request->post['shipping_usps_height']) { + $this->error['dimension'] = $this->language->get('error_height'); + } + + if (!$this->request->post['shipping_usps_length']) { + $this->error['dimension'] = $this->language->get('error_length'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/shipping/weight.php b/public/admin/controller/extension/shipping/weight.php new file mode 100644 index 0000000..2fbda41 --- /dev/null +++ b/public/admin/controller/extension/shipping/weight.php @@ -0,0 +1,103 @@ +<?php +class ControllerExtensionShippingWeight extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/shipping/weight'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('shipping_weight', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/shipping/weight', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/shipping/weight', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=shipping', true); + + $this->load->model('localisation/geo_zone'); + + $geo_zones = $this->model_localisation_geo_zone->getGeoZones(); + + foreach ($geo_zones as $geo_zone) { + if (isset($this->request->post['shipping_weight_' . $geo_zone['geo_zone_id'] . '_rate'])) { + $data['shipping_weight_geo_zone_rate'][$geo_zone['geo_zone_id']] = $this->request->post['shipping_weight_' . $geo_zone['geo_zone_id'] . '_rate']; + } else { + $data['shipping_weight_geo_zone_rate'][$geo_zone['geo_zone_id']] = $this->config->get('shipping_weight_' . $geo_zone['geo_zone_id'] . '_rate'); + } + + if (isset($this->request->post['shipping_weight_' . $geo_zone['geo_zone_id'] . '_status'])) { + $data['shipping_weight_geo_zone_status'][$geo_zone['geo_zone_id']] = $this->request->post['shipping_weight_' . $geo_zone['geo_zone_id'] . '_status']; + } else { + $data['shipping_weight_geo_zone_status'][$geo_zone['geo_zone_id']] = $this->config->get('shipping_weight_' . $geo_zone['geo_zone_id'] . '_status'); + } + } + + $data['geo_zones'] = $geo_zones; + + if (isset($this->request->post['shipping_weight_tax_class_id'])) { + $data['shipping_weight_tax_class_id'] = $this->request->post['shipping_weight_tax_class_id']; + } else { + $data['shipping_weight_tax_class_id'] = $this->config->get('shipping_weight_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['shipping_weight_status'])) { + $data['shipping_weight_status'] = $this->request->post['shipping_weight_status']; + } else { + $data['shipping_weight_status'] = $this->config->get('shipping_weight_status'); + } + + if (isset($this->request->post['shipping_weight_sort_order'])) { + $data['shipping_weight_sort_order'] = $this->request->post['shipping_weight_sort_order']; + } else { + $data['shipping_weight_sort_order'] = $this->config->get('shipping_weight_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/shipping/weight', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/shipping/weight')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/theme/default.php b/public/admin/controller/extension/theme/default.php new file mode 100644 index 0000000..89558e2 --- /dev/null +++ b/public/admin/controller/extension/theme/default.php @@ -0,0 +1,385 @@ +<?php +class ControllerExtensionThemeDefault extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/theme/default'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('theme_default', $this->request->post, $this->request->get['store_id']); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=theme', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + if (isset($this->error['product_limit'])) { + $data['error_product_limit'] = $this->error['product_limit']; + } else { + $data['error_product_limit'] = ''; + } + + if (isset($this->error['product_description_length'])) { + $data['error_product_description_length'] = $this->error['product_description_length']; + } else { + $data['error_product_description_length'] = ''; + } + + if (isset($this->error['image_category'])) { + $data['error_image_category'] = $this->error['image_category']; + } else { + $data['error_image_category'] = ''; + } + + if (isset($this->error['image_thumb'])) { + $data['error_image_thumb'] = $this->error['image_thumb']; + } else { + $data['error_image_thumb'] = ''; + } + + if (isset($this->error['image_popup'])) { + $data['error_image_popup'] = $this->error['image_popup']; + } else { + $data['error_image_popup'] = ''; + } + + if (isset($this->error['image_product'])) { + $data['error_image_product'] = $this->error['image_product']; + } else { + $data['error_image_product'] = ''; + } + + if (isset($this->error['image_additional'])) { + $data['error_image_additional'] = $this->error['image_additional']; + } else { + $data['error_image_additional'] = ''; + } + + if (isset($this->error['image_related'])) { + $data['error_image_related'] = $this->error['image_related']; + } else { + $data['error_image_related'] = ''; + } + + if (isset($this->error['image_compare'])) { + $data['error_image_compare'] = $this->error['image_compare']; + } else { + $data['error_image_compare'] = ''; + } + + if (isset($this->error['image_wishlist'])) { + $data['error_image_wishlist'] = $this->error['image_wishlist']; + } else { + $data['error_image_wishlist'] = ''; + } + + if (isset($this->error['image_cart'])) { + $data['error_image_cart'] = $this->error['image_cart']; + } else { + $data['error_image_cart'] = ''; + } + + if (isset($this->error['image_location'])) { + $data['error_image_location'] = $this->error['image_location']; + } else { + $data['error_image_location'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=theme', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/theme/default', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true) + ); + + $data['action'] = $this->url->link('extension/theme/default', 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $this->request->get['store_id'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=theme', true); + + if (isset($this->request->get['store_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { + $setting_info = $this->model_setting_setting->getSetting('theme_default', $this->request->get['store_id']); + } + + if (isset($this->request->post['theme_default_directory'])) { + $data['theme_default_directory'] = $this->request->post['theme_default_directory']; + } elseif (isset($setting_info['theme_default_directory'])) { + $data['theme_default_directory'] = $setting_info['theme_default_directory']; + } else { + $data['theme_default_directory'] = 'default'; + } + + $data['directories'] = array(); + + $directories = glob(DIR_CATALOG . 'view/theme/*', GLOB_ONLYDIR); + + foreach ($directories as $directory) { + $data['directories'][] = basename($directory); + } + + if (isset($this->request->post['theme_default_product_limit'])) { + $data['theme_default_product_limit'] = $this->request->post['theme_default_product_limit']; + } elseif (isset($setting_info['theme_default_product_limit'])) { + $data['theme_default_product_limit'] = $setting_info['theme_default_product_limit']; + } else { + $data['theme_default_product_limit'] = 15; + } + + if (isset($this->request->post['theme_default_status'])) { + $data['theme_default_status'] = $this->request->post['theme_default_status']; + } elseif (isset($setting_info['theme_default_status'])) { + $data['theme_default_status'] = $setting_info['theme_default_status']; + } else { + $data['theme_default_status'] = ''; + } + + if (isset($this->request->post['theme_default_product_description_length'])) { + $data['theme_default_product_description_length'] = $this->request->post['theme_default_product_description_length']; + } elseif (isset($setting_info['theme_default_product_description_length'])) { + $data['theme_default_product_description_length'] = $setting_info['theme_default_product_description_length']; + } else { + $data['theme_default_product_description_length'] = 100; + } + + if (isset($this->request->post['theme_default_image_category_width'])) { + $data['theme_default_image_category_width'] = $this->request->post['theme_default_image_category_width']; + } elseif (isset($setting_info['theme_default_image_category_width'])) { + $data['theme_default_image_category_width'] = $setting_info['theme_default_image_category_width']; + } else { + $data['theme_default_image_category_width'] = 80; + } + + if (isset($this->request->post['theme_default_image_category_height'])) { + $data['theme_default_image_category_height'] = $this->request->post['theme_default_image_category_height']; + } elseif (isset($setting_info['theme_default_image_category_height'])) { + $data['theme_default_image_category_height'] = $setting_info['theme_default_image_category_height']; + } else { + $data['theme_default_image_category_height'] = 80; + } + + if (isset($this->request->post['theme_default_image_thumb_width'])) { + $data['theme_default_image_thumb_width'] = $this->request->post['theme_default_image_thumb_width']; + } elseif (isset($setting_info['theme_default_image_thumb_width'])) { + $data['theme_default_image_thumb_width'] = $setting_info['theme_default_image_thumb_width']; + } else { + $data['theme_default_image_thumb_width'] = 228; + } + + if (isset($this->request->post['theme_default_image_thumb_height'])) { + $data['theme_default_image_thumb_height'] = $this->request->post['theme_default_image_thumb_height']; + } elseif (isset($setting_info['theme_default_image_thumb_height'])) { + $data['theme_default_image_thumb_height'] = $setting_info['theme_default_image_thumb_height']; + } else { + $data['theme_default_image_thumb_height'] = 228; + } + + if (isset($this->request->post['theme_default_image_popup_width'])) { + $data['theme_default_image_popup_width'] = $this->request->post['theme_default_image_popup_width']; + } elseif (isset($setting_info['theme_default_image_popup_width'])) { + $data['theme_default_image_popup_width'] = $setting_info['theme_default_image_popup_width']; + } else { + $data['theme_default_image_popup_width'] = 500; + } + + if (isset($this->request->post['theme_default_image_popup_height'])) { + $data['theme_default_image_popup_height'] = $this->request->post['theme_default_image_popup_height']; + } elseif (isset($setting_info['theme_default_image_popup_height'])) { + $data['theme_default_image_popup_height'] = $setting_info['theme_default_image_popup_height']; + } else { + $data['theme_default_image_popup_height'] = 500; + } + + if (isset($this->request->post['theme_default_image_product_width'])) { + $data['theme_default_image_product_width'] = $this->request->post['theme_default_image_product_width']; + } elseif (isset($setting_info['theme_default_image_product_width'])) { + $data['theme_default_image_product_width'] = $setting_info['theme_default_image_product_width']; + } else { + $data['theme_default_image_product_width'] = 228; + } + + if (isset($this->request->post['theme_default_image_product_height'])) { + $data['theme_default_image_product_height'] = $this->request->post['theme_default_image_product_height']; + } elseif (isset($setting_info['theme_default_image_product_height'])) { + $data['theme_default_image_product_height'] = $setting_info['theme_default_image_product_height']; + } else { + $data['theme_default_image_product_height'] = 228; + } + + if (isset($this->request->post['theme_default_image_additional_width'])) { + $data['theme_default_image_additional_width'] = $this->request->post['theme_default_image_additional_width']; + } elseif (isset($setting_info['theme_default_image_additional_width'])) { + $data['theme_default_image_additional_width'] = $setting_info['theme_default_image_additional_width']; + } else { + $data['theme_default_image_additional_width'] = 74; + } + + if (isset($this->request->post['theme_default_image_additional_height'])) { + $data['theme_default_image_additional_height'] = $this->request->post['theme_default_image_additional_height']; + } elseif (isset($setting_info['theme_default_image_additional_height'])) { + $data['theme_default_image_additional_height'] = $setting_info['theme_default_image_additional_height']; + } else { + $data['theme_default_image_additional_height'] = 74; + } + + if (isset($this->request->post['theme_default_image_related_width'])) { + $data['theme_default_image_related_width'] = $this->request->post['theme_default_image_related_width']; + } elseif (isset($setting_info['theme_default_image_related_width'])) { + $data['theme_default_image_related_width'] = $setting_info['theme_default_image_related_width']; + } else { + $data['theme_default_image_related_width'] = 80; + } + + if (isset($this->request->post['theme_default_image_related_height'])) { + $data['theme_default_image_related_height'] = $this->request->post['theme_default_image_related_height']; + } elseif (isset($setting_info['theme_default_image_related_height'])) { + $data['theme_default_image_related_height'] = $setting_info['theme_default_image_related_height']; + } else { + $data['theme_default_image_related_height'] = 80; + } + + if (isset($this->request->post['theme_default_image_compare_width'])) { + $data['theme_default_image_compare_width'] = $this->request->post['theme_default_image_compare_width']; + } elseif (isset($setting_info['theme_default_image_compare_width'])) { + $data['theme_default_image_compare_width'] = $setting_info['theme_default_image_compare_width']; + } else { + $data['theme_default_image_compare_width'] = 90; + } + + if (isset($this->request->post['theme_default_image_compare_height'])) { + $data['theme_default_image_compare_height'] = $this->request->post['theme_default_image_compare_height']; + } elseif (isset($setting_info['theme_default_image_compare_height'])) { + $data['theme_default_image_compare_height'] = $setting_info['theme_default_image_compare_height']; + } else { + $data['theme_default_image_compare_height'] = 90; + } + + if (isset($this->request->post['theme_default_image_wishlist_width'])) { + $data['theme_default_image_wishlist_width'] = $this->request->post['theme_default_image_wishlist_width']; + } elseif (isset($setting_info['theme_default_image_wishlist_width'])) { + $data['theme_default_image_wishlist_width'] = $setting_info['theme_default_image_wishlist_width']; + } else { + $data['theme_default_image_wishlist_width'] = 47; + } + + if (isset($this->request->post['theme_default_image_wishlist_height'])) { + $data['theme_default_image_wishlist_height'] = $this->request->post['theme_default_image_wishlist_height']; + } elseif (isset($setting_info['theme_default_image_wishlist_height'])) { + $data['theme_default_image_wishlist_height'] = $setting_info['theme_default_image_wishlist_height']; + } else { + $data['theme_default_image_wishlist_height'] = 47; + } + + if (isset($this->request->post['theme_default_image_cart_width'])) { + $data['theme_default_image_cart_width'] = $this->request->post['theme_default_image_cart_width']; + } elseif (isset($setting_info['theme_default_image_cart_width'])) { + $data['theme_default_image_cart_width'] = $setting_info['theme_default_image_cart_width']; + } else { + $data['theme_default_image_cart_width'] = 47; + } + + if (isset($this->request->post['theme_default_image_cart_height'])) { + $data['theme_default_image_cart_height'] = $this->request->post['theme_default_image_cart_height']; + } elseif (isset($setting_info['theme_default_image_cart_height'])) { + $data['theme_default_image_cart_height'] = $setting_info['theme_default_image_cart_height']; + } else { + $data['theme_default_image_cart_height'] = 47; + } + + if (isset($this->request->post['theme_default_image_location_width'])) { + $data['theme_default_image_location_width'] = $this->request->post['theme_default_image_location_width']; + } elseif (isset($setting_info['theme_default_image_location_width'])) { + $data['theme_default_image_location_width'] = $setting_info['theme_default_image_location_width']; + } else { + $data['theme_default_image_location_width'] = 268; + } + + if (isset($this->request->post['theme_default_image_location_height'])) { + $data['theme_default_image_location_height'] = $this->request->post['theme_default_image_location_height']; + } elseif (isset($setting_info['theme_default_image_location_height'])) { + $data['theme_default_image_location_height'] = $setting_info['theme_default_image_location_height']; + } else { + $data['theme_default_image_location_height'] = 50; + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/theme/default', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/theme/default')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + if (!$this->request->post['theme_default_product_limit']) { + $this->error['product_limit'] = $this->language->get('error_limit'); + } + + if (!$this->request->post['theme_default_product_description_length']) { + $this->error['product_description_length'] = $this->language->get('error_limit'); + } + + if (!$this->request->post['theme_default_image_category_width'] || !$this->request->post['theme_default_image_category_height']) { + $this->error['image_category'] = $this->language->get('error_image_category'); + } + + if (!$this->request->post['theme_default_image_thumb_width'] || !$this->request->post['theme_default_image_thumb_height']) { + $this->error['image_thumb'] = $this->language->get('error_image_thumb'); + } + + if (!$this->request->post['theme_default_image_popup_width'] || !$this->request->post['theme_default_image_popup_height']) { + $this->error['image_popup'] = $this->language->get('error_image_popup'); + } + + if (!$this->request->post['theme_default_image_product_width'] || !$this->request->post['theme_default_image_product_height']) { + $this->error['image_product'] = $this->language->get('error_image_product'); + } + + if (!$this->request->post['theme_default_image_additional_width'] || !$this->request->post['theme_default_image_additional_height']) { + $this->error['image_additional'] = $this->language->get('error_image_additional'); + } + + if (!$this->request->post['theme_default_image_related_width'] || !$this->request->post['theme_default_image_related_height']) { + $this->error['image_related'] = $this->language->get('error_image_related'); + } + + if (!$this->request->post['theme_default_image_compare_width'] || !$this->request->post['theme_default_image_compare_height']) { + $this->error['image_compare'] = $this->language->get('error_image_compare'); + } + + if (!$this->request->post['theme_default_image_wishlist_width'] || !$this->request->post['theme_default_image_wishlist_height']) { + $this->error['image_wishlist'] = $this->language->get('error_image_wishlist'); + } + + if (!$this->request->post['theme_default_image_cart_width'] || !$this->request->post['theme_default_image_cart_height']) { + $this->error['image_cart'] = $this->language->get('error_image_cart'); + } + + if (!$this->request->post['theme_default_image_location_width'] || !$this->request->post['theme_default_image_location_height']) { + $this->error['image_location'] = $this->language->get('error_image_location'); + } + + return !$this->error; + } +} diff --git a/public/admin/controller/extension/total/coupon.php b/public/admin/controller/extension/total/coupon.php new file mode 100644 index 0000000..397e6cc --- /dev/null +++ b/public/admin/controller/extension/total/coupon.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalCoupon extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/coupon'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_coupon', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/coupon', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/coupon', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_coupon_status'])) { + $data['total_coupon_status'] = $this->request->post['total_coupon_status']; + } else { + $data['total_coupon_status'] = $this->config->get('total_coupon_status'); + } + + if (isset($this->request->post['total_coupon_sort_order'])) { + $data['total_coupon_sort_order'] = $this->request->post['total_coupon_sort_order']; + } else { + $data['total_coupon_sort_order'] = $this->config->get('total_coupon_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/coupon', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/coupon')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/credit.php b/public/admin/controller/extension/total/credit.php new file mode 100644 index 0000000..930d3cd --- /dev/null +++ b/public/admin/controller/extension/total/credit.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalCredit extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/credit'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_credit', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/credit', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/credit', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_credit_status'])) { + $data['total_credit_status'] = $this->request->post['total_credit_status']; + } else { + $data['total_credit_status'] = $this->config->get('total_credit_status'); + } + + if (isset($this->request->post['total_credit_sort_order'])) { + $data['total_credit_sort_order'] = $this->request->post['total_credit_sort_order']; + } else { + $data['total_credit_sort_order'] = $this->config->get('total_credit_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/credit', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/credit')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/handling.php b/public/admin/controller/extension/total/handling.php new file mode 100644 index 0000000..123906c --- /dev/null +++ b/public/admin/controller/extension/total/handling.php @@ -0,0 +1,95 @@ +<?php +class ControllerExtensionTotalHandling extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/handling'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_handling', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/handling', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/handling', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_handling_total'])) { + $data['total_handling_total'] = $this->request->post['total_handling_total']; + } else { + $data['total_handling_total'] = $this->config->get('total_handling_total'); + } + + if (isset($this->request->post['total_handling_fee'])) { + $data['total_handling_fee'] = $this->request->post['total_handling_fee']; + } else { + $data['total_handling_fee'] = $this->config->get('total_handling_fee'); + } + + if (isset($this->request->post['total_handling_tax_class_id'])) { + $data['total_handling_tax_class_id'] = $this->request->post['total_handling_tax_class_id']; + } else { + $data['total_handling_tax_class_id'] = $this->config->get('total_handling_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['total_handling_status'])) { + $data['total_handling_status'] = $this->request->post['total_handling_status']; + } else { + $data['total_handling_status'] = $this->config->get('total_handling_status'); + } + + if (isset($this->request->post['total_handling_sort_order'])) { + $data['total_handling_sort_order'] = $this->request->post['total_handling_sort_order']; + } else { + $data['total_handling_sort_order'] = $this->config->get('total_handling_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/handling', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/handling')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/klarna_fee.php b/public/admin/controller/extension/total/klarna_fee.php new file mode 100644 index 0000000..95e9851 --- /dev/null +++ b/public/admin/controller/extension/total/klarna_fee.php @@ -0,0 +1,113 @@ +<?php +class ControllerExtensionTotalKlarnaFee extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/klarna_fee'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $status = false; + + foreach ($this->request->post['klarna_fee'] as $klarna_account) { + if ($klarna_account['status']) { + $status = true; + + break; + } + } + + $this->model_setting_setting->editSetting('total_klarna_fee', array_merge($this->request->post, array('klarna_fee_status' => $status))); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/klarna_fee', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/klarna_fee', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + $data['countries'] = array(); + + $data['countries'][] = array( + 'name' => $this->language->get('text_germany'), + 'code' => 'DEU' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_netherlands'), + 'code' => 'NLD' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_denmark'), + 'code' => 'DNK' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_sweden'), + 'code' => 'SWE' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_norway'), + 'code' => 'NOR' + ); + + $data['countries'][] = array( + 'name' => $this->language->get('text_finland'), + 'code' => 'FIN' + ); + + if (isset($this->request->post['total_klarna_fee'])) { + $data['total_klarna_fee'] = $this->request->post['total_klarna_fee']; + } else { + $data['total_klarna_fee'] = $this->config->get('total_klarna_fee'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/klarna_fee', $data)); + } + + private function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/klarna_fee')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/low_order_fee.php b/public/admin/controller/extension/total/low_order_fee.php new file mode 100644 index 0000000..5defd89 --- /dev/null +++ b/public/admin/controller/extension/total/low_order_fee.php @@ -0,0 +1,95 @@ +<?php +class ControllerExtensionTotalLowOrderFee extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/low_order_fee'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_low_order_fee', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/low_order_fee', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/low_order_fee', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_low_order_fee_total'])) { + $data['total_low_order_fee_total'] = $this->request->post['total_low_order_fee_total']; + } else { + $data['total_low_order_fee_total'] = $this->config->get('total_low_order_fee_total'); + } + + if (isset($this->request->post['total_low_order_fee_fee'])) { + $data['total_low_order_fee_fee'] = $this->request->post['total_low_order_fee_fee']; + } else { + $data['total_low_order_fee_fee'] = $this->config->get('total_low_order_fee_fee'); + } + + if (isset($this->request->post['total_low_order_fee_tax_class_id'])) { + $data['total_low_order_fee_tax_class_id'] = $this->request->post['total_low_order_fee_tax_class_id']; + } else { + $data['total_low_order_fee_tax_class_id'] = $this->config->get('total_low_order_fee_tax_class_id'); + } + + $this->load->model('localisation/tax_class'); + + $data['tax_classes'] = $this->model_localisation_tax_class->getTaxClasses(); + + if (isset($this->request->post['total_low_order_fee_status'])) { + $data['total_low_order_fee_status'] = $this->request->post['total_low_order_fee_status']; + } else { + $data['total_low_order_fee_status'] = $this->config->get('total_low_order_fee_status'); + } + + if (isset($this->request->post['total_low_order_fee_sort_order'])) { + $data['total_low_order_fee_sort_order'] = $this->request->post['total_low_order_fee_sort_order']; + } else { + $data['total_low_order_fee_sort_order'] = $this->config->get('total_low_order_fee_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/low_order_fee', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/low_order_fee')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/reward.php b/public/admin/controller/extension/total/reward.php new file mode 100644 index 0000000..eac07db --- /dev/null +++ b/public/admin/controller/extension/total/reward.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalReward extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/reward'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_reward', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/reward', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/reward', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_reward_status'])) { + $data['total_reward_status'] = $this->request->post['total_reward_status']; + } else { + $data['total_reward_status'] = $this->config->get('total_reward_status'); + } + + if (isset($this->request->post['total_reward_sort_order'])) { + $data['total_reward_sort_order'] = $this->request->post['total_reward_sort_order']; + } else { + $data['total_reward_sort_order'] = $this->config->get('total_reward_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/reward', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/reward')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/shipping.php b/public/admin/controller/extension/total/shipping.php new file mode 100644 index 0000000..ef7251d --- /dev/null +++ b/public/admin/controller/extension/total/shipping.php @@ -0,0 +1,79 @@ +<?php +class ControllerExtensionTotalShipping extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/shipping'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_shipping', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/shipping', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/shipping', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_shipping_estimator'])) { + $data['total_shipping_estimator'] = $this->request->post['total_shipping_estimator']; + } else { + $data['total_shipping_estimator'] = $this->config->get('total_shipping_estimator'); + } + + if (isset($this->request->post['total_shipping_status'])) { + $data['total_shipping_status'] = $this->request->post['total_shipping_status']; + } else { + $data['total_shipping_status'] = $this->config->get('total_shipping_status'); + } + + if (isset($this->request->post['total_shipping_sort_order'])) { + $data['total_shipping_sort_order'] = $this->request->post['total_shipping_sort_order']; + } else { + $data['total_shipping_sort_order'] = $this->config->get('total_shipping_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/shipping', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/shipping')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/sub_total.php b/public/admin/controller/extension/total/sub_total.php new file mode 100644 index 0000000..0bff1f8 --- /dev/null +++ b/public/admin/controller/extension/total/sub_total.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalSubTotal extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/sub_total'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_sub_total', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/sub_total', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/sub_total', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_sub_total_status'])) { + $data['total_sub_total_status'] = $this->request->post['total_sub_total_status']; + } else { + $data['total_sub_total_status'] = $this->config->get('total_sub_total_status'); + } + + if (isset($this->request->post['sub_total_sort_order'])) { + $data['sub_total_sort_order'] = $this->request->post['sub_total_sort_order']; + } else { + $data['sub_total_sort_order'] = $this->config->get('sub_total_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/sub_total', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/sub_total')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/tax.php b/public/admin/controller/extension/total/tax.php new file mode 100644 index 0000000..89d3060 --- /dev/null +++ b/public/admin/controller/extension/total/tax.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalTax extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/tax'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_tax', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/tax', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/tax', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_tax_status'])) { + $data['total_tax_status'] = $this->request->post['total_tax_status']; + } else { + $data['total_tax_status'] = $this->config->get('total_tax_status'); + } + + if (isset($this->request->post['total_tax_sort_order'])) { + $data['total_tax_sort_order'] = $this->request->post['total_tax_sort_order']; + } else { + $data['total_tax_sort_order'] = $this->config->get('total_tax_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/tax', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/tax')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/total.php b/public/admin/controller/extension/total/total.php new file mode 100644 index 0000000..3a24787 --- /dev/null +++ b/public/admin/controller/extension/total/total.php @@ -0,0 +1,73 @@ +<?php +class ControllerExtensionTotalTotal extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/total'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_total', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/total', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/total', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_total_status'])) { + $data['total_total_status'] = $this->request->post['total_total_status']; + } else { + $data['total_total_status'] = $this->config->get('total_total_status'); + } + + if (isset($this->request->post['total_total_sort_order'])) { + $data['total_total_sort_order'] = $this->request->post['total_total_sort_order']; + } else { + $data['total_total_sort_order'] = $this->config->get('total_total_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/total', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/total')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } +}
\ No newline at end of file diff --git a/public/admin/controller/extension/total/voucher.php b/public/admin/controller/extension/total/voucher.php new file mode 100644 index 0000000..0d7820b --- /dev/null +++ b/public/admin/controller/extension/total/voucher.php @@ -0,0 +1,87 @@ +<?php +class ControllerExtensionTotalVoucher extends Controller { + private $error = array(); + + public function index() { + $this->load->language('extension/total/voucher'); + + $this->document->setTitle($this->language->get('heading_title')); + + $this->load->model('setting/setting'); + + if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) { + $this->model_setting_setting->editSetting('total_voucher', $this->request->post); + + $this->session->data['success'] = $this->language->get('text_success'); + + $this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true)); + } + + if (isset($this->error['warning'])) { + $data['error_warning'] = $this->error['warning']; + } else { + $data['error_warning'] = ''; + } + + $data['breadcrumbs'] = array(); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_extension'), + 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true) + ); + + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('extension/total/voucher', 'user_token=' . $this->session->data['user_token'], true) + ); + + $data['action'] = $this->url->link('extension/total/voucher', 'user_token=' . $this->session->data['user_token'], true); + + $data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=total', true); + + if (isset($this->request->post['total_voucher_status'])) { + $data['total_voucher_status'] = $this->request->post['total_voucher_status']; + } else { + $data['total_voucher_status'] = $this->config->get('total_voucher_status'); + } + + if (isset($this->request->post['total_voucher_sort_order'])) { + $data['total_voucher_sort_order'] = $this->request->post['total_voucher_sort_order']; + } else { + $data['total_voucher_sort_order'] = $this->config->get('total_voucher_sort_order'); + } + + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); + + $this->response->setOutput($this->load->view('extension/total/voucher', $data)); + } + + protected function validate() { + if (!$this->user->hasPermission('modify', 'extension/total/voucher')) { + $this->error['warning'] = $this->language->get('error_permission'); + } + + return !$this->error; + } + + public function install() { + // Register the event triggers + $this->load->model('setting/event'); + + $this->model_setting_event->addEvent('voucher', 'catalog/model/checkout/order/addOrderHistory/after', 'extension/total/voucher/send'); + } + + public function uninstall() { + // delete the event triggers + $this->load->model('setting/event'); + + $this->model_setting_event->deleteEventByCode('voucher'); + } +} |