first commit
This commit is contained in:
commit
a2fa49071a
89
.htaccess.txt
Normal file
89
.htaccess.txt
Normal file
@ -0,0 +1,89 @@
|
||||
##
|
||||
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
|
||||
#
|
||||
# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.
|
||||
# 2. In your opencart directory rename .htaccess.txt (this file) to .htaccess
|
||||
#
|
||||
# For any support issues please visit: https://www.opencart.com
|
||||
#
|
||||
# The line 'Options +FollowSymLinks' may cause problems with some server configurations.
|
||||
# It is required for the use of Apache mod_rewrite, but it may have already been set by
|
||||
# your server administrator in a way that disallows changing it in this .htaccess file.
|
||||
# If you encounter problems (e.g. site is not loading), comment out this line by adding a # in front
|
||||
# FLOC is a feature suggested by Google, if this header shall not be set, disable the line
|
||||
# having 'interest-cohort' by adding a # in front
|
||||
##
|
||||
|
||||
## No directory listings
|
||||
<IfModule mod_autoindex.c>
|
||||
IndexIgnore *
|
||||
</IfModule>
|
||||
|
||||
## No-Referrer-Header
|
||||
<IfModule mod_headers.c>
|
||||
Header set Referrer-Policy "no-referrer"
|
||||
</IfModule>
|
||||
|
||||
## Suppress mime type detection in browsers for unknown types and prevent FLOC
|
||||
<IfModule mod_headers.c>
|
||||
Header always set X-Content-Type-Options "nosniff"
|
||||
Header always set Permissions-Policy "interest-cohort=()"
|
||||
</IfModule>
|
||||
|
||||
## Can be commented out if causes errors, see notes above.
|
||||
Options +FollowSymlinks
|
||||
|
||||
## Prevent Directory listing
|
||||
Options -Indexes
|
||||
|
||||
## Prevent Direct Access to files
|
||||
<FilesMatch "(?i)((\.tpl|\.twig|\.ini|\.log|(?<!robots)\.txt))">
|
||||
Require all denied
|
||||
## For apache 2.2 and older, replace "Require all denied" with these two lines :
|
||||
# Order deny,allow
|
||||
# Deny from all
|
||||
</FilesMatch>
|
||||
|
||||
## SEO URL Settings
|
||||
RewriteEngine On
|
||||
## If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
|
||||
RewriteBase /
|
||||
## Rewrite Rules
|
||||
RewriteRule ^system/storage/(.*) index.php?route=error/not_found [L]
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|webp|js|css|svg)
|
||||
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
|
||||
|
||||
## Optional error documents
|
||||
#ErrorDocument 400 /index.php?route=error/not_found
|
||||
#ErrorDocument 401 /index.php?route=error/permission
|
||||
#ErrorDocument 403 /index.php?route=error/not_found
|
||||
#ErrorDocument 404 /index.php?route=error/not_found
|
||||
#ErrorDocument 500 /index.php?route=error/not_found
|
||||
#ErrorDocument 503 /index.php?route=error/not_found
|
||||
|
||||
## Additional Settings that may need to be enabled for some servers
|
||||
## Uncomment the commands by removing the # sign in front of it.
|
||||
## If you get an "Internal Server Error 500" after enabling any of the following settings, restore the # as this means your host doesn't allow that.
|
||||
|
||||
# 1. If your cart only allows you to add one item at a time, it is possible register_globals is on. This may work to disable it:
|
||||
# php_flag register_globals off
|
||||
|
||||
# 2. If your cart has magic quotes enabled, This may work to disable it:
|
||||
# php_flag magic_quotes_gpc Off
|
||||
|
||||
# 3. Set max upload file size. Most hosts will limit this and not allow it to be overridden but you can try
|
||||
# php_value upload_max_filesize 999M
|
||||
|
||||
# 4. set max post size. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
|
||||
# php_value post_max_size 999M
|
||||
|
||||
# 5. set max time script can take. uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
|
||||
# php_value max_execution_time 200
|
||||
|
||||
# 6. set max time for input to be recieved. Uncomment this line if you have a lot of product options or are getting errors where forms are not saving all fields
|
||||
# php_value max_input_time 200
|
||||
|
||||
# 7. disable open_basedir limitations
|
||||
# php_admin_value open_basedir none
|
36
admininistrator/config.php
Normal file
36
admininistrator/config.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// APPLICATION
|
||||
define('APPLICATION', 'Admin');
|
||||
|
||||
// HTTP
|
||||
define('HTTP_SERVER', 'http://localhost/opencart/admininistrator/');
|
||||
define('HTTP_CATALOG', 'http://localhost/opencart/');
|
||||
|
||||
// DIR
|
||||
define('DIR_OPENCART', 'D:/xampp/htdocs/opencart/');
|
||||
define('DIR_APPLICATION', DIR_OPENCART . 'admininistrator/');
|
||||
define('DIR_EXTENSION', DIR_OPENCART . 'extension/');
|
||||
define('DIR_IMAGE', DIR_OPENCART . 'image/');
|
||||
define('DIR_SYSTEM', DIR_OPENCART . 'system/');
|
||||
define('DIR_CATALOG', DIR_OPENCART . 'catalog/');
|
||||
define('DIR_STORAGE', 'D:/xampp/storage/');
|
||||
define('DIR_LANGUAGE', DIR_APPLICATION . 'language/');
|
||||
define('DIR_TEMPLATE', DIR_APPLICATION . 'view/template/');
|
||||
define('DIR_CONFIG', DIR_SYSTEM . 'config/');
|
||||
define('DIR_CACHE', DIR_STORAGE . 'cache/');
|
||||
define('DIR_DOWNLOAD', DIR_STORAGE . 'download/');
|
||||
define('DIR_LOGS', DIR_STORAGE . 'logs/');
|
||||
define('DIR_SESSION', DIR_STORAGE . 'session/');
|
||||
define('DIR_UPLOAD', DIR_STORAGE . 'upload/');
|
||||
|
||||
// DB
|
||||
define('DB_DRIVER', 'mysqli');
|
||||
define('DB_HOSTNAME', 'localhost');
|
||||
define('DB_USERNAME', 'root');
|
||||
define('DB_PASSWORD', '');
|
||||
define('DB_DATABASE', 'opencart');
|
||||
define('DB_PORT', '3306');
|
||||
define('DB_PREFIX', 'oc_');
|
||||
|
||||
// OpenCart API
|
||||
define('OPENCART_SERVER', 'https://www.opencart.com/');
|
373
admininistrator/controller/catalog/attribute.php
Normal file
373
admininistrator/controller/catalog/attribute.php
Normal file
@ -0,0 +1,373 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Attribute
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class Attribute extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . (string)$this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . (string)$this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . (int)$this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/attribute.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/attribute.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('catalog/attribute', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'ad.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/attribute.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['attributes'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
$attribute_total = $this->model_catalog_attribute->getTotalAttributes();
|
||||
|
||||
$results = $this->model_catalog_attribute->getAttributes($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['attributes'][] = [
|
||||
'attribute_id' => $result['attribute_id'],
|
||||
'name' => $result['name'],
|
||||
'attribute_group' => $result['attribute_group'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/attribute.form', 'user_token=' . $this->session->data['user_token'] . '&attribute_id=' . $result['attribute_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/attribute.list', 'user_token=' . $this->session->data['user_token'] . '&sort=ad.name' . $url);
|
||||
$data['sort_attribute_group'] = $this->url->link('catalog/attribute.list', 'user_token=' . $this->session->data['user_token'] . '&sort=attribute_group' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/attribute.list', 'user_token=' . $this->session->data['user_token'] . '&sort=a.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $attribute_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/attribute.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($attribute_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($attribute_total - $this->config->get('config_pagination_admin'))) ? $attribute_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $attribute_total, ceil($attribute_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/attribute_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['attribute_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/attribute.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['attribute_id'])) {
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
$attribute_info = $this->model_catalog_attribute->getAttribute($this->request->get['attribute_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['attribute_id'])) {
|
||||
$data['attribute_id'] = (int)$this->request->get['attribute_id'];
|
||||
} else {
|
||||
$data['attribute_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['attribute_id'])) {
|
||||
$data['attribute_description'] = $this->model_catalog_attribute->getDescriptions($this->request->get['attribute_id']);
|
||||
} else {
|
||||
$data['attribute_description'] = [];
|
||||
}
|
||||
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
$data['attribute_groups'] = $this->model_catalog_attribute_group->getAttributeGroups();
|
||||
|
||||
if (!empty($attribute_info)) {
|
||||
$data['attribute_group_id'] = $attribute_info['attribute_group_id'];
|
||||
} else {
|
||||
$data['attribute_group_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($attribute_info)) {
|
||||
$data['sort_order'] = $attribute_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = 0;
|
||||
}
|
||||
|
||||
$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('catalog/attribute_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/attribute')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$this->request->post['attribute_group_id']) {
|
||||
$json['error']['attribute_group'] = $this->language->get('error_attribute_group');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['attribute_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 1) || (oc_strlen($value['name']) > 64)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
if (!$this->request->post['attribute_id']) {
|
||||
$json['attribute_id'] = $this->model_catalog_attribute->addAttribute($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_attribute->editAttribute($this->request->post['attribute_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/attribute')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $attribute_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByAttributeId($attribute_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
foreach ($selected as $attribute_id) {
|
||||
$this->model_catalog_attribute->deleteAttribute($attribute_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function autocomplete(): void {
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => 5
|
||||
];
|
||||
|
||||
$results = $this->model_catalog_attribute->getAttributes($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$json[] = [
|
||||
'attribute_id' => $result['attribute_id'],
|
||||
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
|
||||
'attribute_group' => $result['attribute_group']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
319
admininistrator/controller/catalog/attribute_group.php
Normal file
319
admininistrator/controller/catalog/attribute_group.php
Normal file
@ -0,0 +1,319 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Attribute Group
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class AttributeGroup extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/attribute_group.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/attribute_group.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('catalog/attribute_group', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'agd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/attribute_group.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['attribute_groups'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
$attribute_group_total = $this->model_catalog_attribute_group->getTotalAttributeGroups();
|
||||
|
||||
$results = $this->model_catalog_attribute_group->getAttributeGroups($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['attribute_groups'][] = [
|
||||
'attribute_group_id' => $result['attribute_group_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/attribute_group.form', 'user_token=' . $this->session->data['user_token'] . '&attribute_group_id=' . $result['attribute_group_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/attribute_group.list', 'user_token=' . $this->session->data['user_token'] . '&sort=agd.name' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/attribute_group.list', 'user_token=' . $this->session->data['user_token'] . '&sort=ag.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $attribute_group_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/attribute_group.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($attribute_group_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($attribute_group_total - $this->config->get('config_pagination_admin'))) ? $attribute_group_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $attribute_group_total, ceil($attribute_group_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/attribute_group_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['attribute_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/attribute_group.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['attribute_group_id'])) {
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
$attribute_group_info = $this->model_catalog_attribute_group->getAttributeGroup($this->request->get['attribute_group_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['attribute_group_id'])) {
|
||||
$data['attribute_group_id'] = (int)$this->request->get['attribute_group_id'];
|
||||
} else {
|
||||
$data['attribute_group_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['attribute_group_id'])) {
|
||||
$data['attribute_group_description'] = $this->model_catalog_attribute_group->getDescriptions($this->request->get['attribute_group_id']);
|
||||
} else {
|
||||
$data['attribute_group_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($attribute_group_info)) {
|
||||
$data['sort_order'] = $attribute_group_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
$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('catalog/attribute_group_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['attribute_group_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 1) || (oc_strlen($value['name']) > 64)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
if (!$this->request->post['attribute_group_id']) {
|
||||
$json['attribute_group_id'] = $this->model_catalog_attribute_group->addAttributeGroup($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_attribute_group->editAttributeGroup($this->request->post['attribute_group_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
foreach ($selected as $attribute_group_id) {
|
||||
$attribute_total = $this->model_catalog_attribute->getTotalAttributesByAttributeGroupId($attribute_group_id);
|
||||
|
||||
if ($attribute_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_attribute'), $attribute_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
foreach ($selected as $attribute_group_id) {
|
||||
$this->model_catalog_attribute_group->deleteAttributeGroup($attribute_group_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
536
admininistrator/controller/catalog/category.php
Normal file
536
admininistrator/controller/catalog/category.php
Normal file
@ -0,0 +1,536 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Category
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalo
|
||||
*/
|
||||
class Category extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['repair'] = $this->url->link('catalog/category.repair', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['add'] = $this->url->link('catalog/category.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/category.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('catalog/category', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/category.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['categories'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$category_total = $this->model_catalog_category->getTotalCategories();
|
||||
|
||||
$results = $this->model_catalog_category->getCategories($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['categories'][] = [
|
||||
'category_id' => $result['category_id'],
|
||||
'name' => $result['name'],
|
||||
'status' => $result['status'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/category.form', 'user_token=' . $this->session->data['user_token'] . '&category_id=' . $result['category_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/category.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/category.list', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $category_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/category.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($category_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($category_total - $this->config->get('config_pagination_admin'))) ? $category_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $category_total, ceil($category_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/category_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->document->addScript('view/javascript/ckeditor/ckeditor.js');
|
||||
$this->document->addScript('view/javascript/ckeditor/adapters/jquery.js');
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['category_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/category.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$category_info = $this->model_catalog_category->getCategory($this->request->get['category_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$data['category_id'] = (int)$this->request->get['category_id'];
|
||||
} else {
|
||||
$data['category_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$data['category_description'] = $this->model_catalog_category->getDescriptions($this->request->get['category_id']);
|
||||
} else {
|
||||
$data['category_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($category_info)) {
|
||||
$data['path'] = $category_info['path'];
|
||||
} else {
|
||||
$data['path'] = '';
|
||||
}
|
||||
|
||||
if (!empty($category_info)) {
|
||||
$data['parent_id'] = $category_info['parent_id'];
|
||||
} else {
|
||||
$data['parent_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$filters = $this->model_catalog_category->getFilters($this->request->get['category_id']);
|
||||
} else {
|
||||
$filters = [];
|
||||
}
|
||||
|
||||
$data['category_filters'] = [];
|
||||
|
||||
foreach ($filters as $filter_id) {
|
||||
$filter_info = $this->model_catalog_filter->getFilter($filter_id);
|
||||
|
||||
if ($filter_info) {
|
||||
$data['category_filters'][] = [
|
||||
'filter_id' => $filter_info['filter_id'],
|
||||
'name' => $filter_info['group'] . ' > ' . $filter_info['name']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = [
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$data['category_store'] = $this->model_catalog_category->getStores($this->request->get['category_id']);
|
||||
} else {
|
||||
$data['category_store'] = [0];
|
||||
}
|
||||
|
||||
if (!empty($category_info)) {
|
||||
$data['image'] = $category_info['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'), 100, 100);
|
||||
} else {
|
||||
$data['thumb'] = $data['placeholder'];
|
||||
}
|
||||
|
||||
if (!empty($category_info)) {
|
||||
$data['top'] = $category_info['top'];
|
||||
} else {
|
||||
$data['top'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($category_info)) {
|
||||
$data['column'] = $category_info['column'];
|
||||
} else {
|
||||
$data['column'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($category_info)) {
|
||||
$data['sort_order'] = $category_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($category_info)) {
|
||||
$data['status'] = $category_info['status'];
|
||||
} else {
|
||||
$data['status'] = true;
|
||||
}
|
||||
|
||||
$data['category_seo_url'] = [];
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$results = $this->model_catalog_category->getSeoUrls($this->request->get['category_id']);
|
||||
|
||||
foreach ($results as $store_id => $languages) {
|
||||
foreach ($languages as $language_id => $keyword) {
|
||||
$pos = strrpos($keyword, '/');
|
||||
|
||||
if ($pos !== false) {
|
||||
$keyword = substr($keyword, $pos + 1);
|
||||
} else {
|
||||
$keyword = $keyword;
|
||||
}
|
||||
|
||||
$data['category_seo_url'][$store_id][$language_id] = $keyword;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
if (isset($this->request->get['category_id'])) {
|
||||
$data['category_layout'] = $this->model_catalog_category->getLayouts($this->request->get['category_id']);
|
||||
} else {
|
||||
$data['category_layout'] = [];
|
||||
}
|
||||
|
||||
$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('catalog/category_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/category')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['category_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 1) || (oc_strlen($value['name']) > 255)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen(trim($value['meta_title'])) < 1) || (oc_strlen($value['meta_title']) > 255)) {
|
||||
$json['error']['meta_title_' . $language_id] = $this->language->get('error_meta_title');
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
if (isset($this->request->post['category_id']) && $this->request->post['parent_id']) {
|
||||
$results = $this->model_catalog_category->getPaths($this->request->post['parent_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($result['path_id'] == $this->request->post['category_id']) {
|
||||
$json['error']['parent'] = $this->language->get('error_parent');
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->post['category_seo_url']) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($this->request->post['category_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if ((oc_strlen(trim($keyword)) < 1) || (oc_strlen($keyword) > 64)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword');
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/_-]|[\p{Cyrillic}]+/u', $keyword)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_character');
|
||||
}
|
||||
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($keyword, $store_id);
|
||||
|
||||
if ($seo_url_info && (!isset($this->request->post['category_id']) || $seo_url_info['key'] != 'path' || $seo_url_info['value'] != $this->model_catalog_category->getPath($this->request->post['category_id']))) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_exists');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if (!$this->request->post['category_id']) {
|
||||
$json['category_id'] = $this->model_catalog_category->addCategory($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_category->editCategory($this->request->post['category_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function repair(): void {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/category')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$this->model_catalog_category->repairCategories();
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/category')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
foreach ($selected as $category_id) {
|
||||
$this->model_catalog_category->deleteCategory($category_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function autocomplete(): void {
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => '%' . $this->request->get['filter_name'] . '%',
|
||||
'sort' => 'name',
|
||||
'order' => 'ASC',
|
||||
'start' => 0,
|
||||
'limit' => 5
|
||||
];
|
||||
|
||||
$results = $this->model_catalog_category->getCategories($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$json[] = [
|
||||
'category_id' => $result['category_id'],
|
||||
'name' => $result['name']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
596
admininistrator/controller/catalog/download.php
Normal file
596
admininistrator/controller/catalog/download.php
Normal file
@ -0,0 +1,596 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Download
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class Download extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/download.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/download.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/download', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'dd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/download.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['downloads'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
$download_total = $this->model_catalog_download->getTotalDownloads();
|
||||
|
||||
$results = $this->model_catalog_download->getDownloads($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['downloads'][] = [
|
||||
'download_id' => $result['download_id'],
|
||||
'name' => $result['name'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'edit' => $this->url->link('catalog/download.form', 'user_token=' . $this->session->data['user_token'] . '&download_id=' . $result['download_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/download.list', 'user_token=' . $this->session->data['user_token'] . '&sort=dd.name' . $url);
|
||||
$data['sort_date_added'] = $this->url->link('catalog/download.list', 'user_token=' . $this->session->data['user_token'] . '&sort=d.date_added' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $download_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/download.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($download_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($download_total - $this->config->get('config_pagination_admin'))) ? $download_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $download_total, ceil($download_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/download_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['download_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
// Use the ini_get('upload_max_filesize') for the max file size
|
||||
$data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), ini_get('upload_max_filesize'));
|
||||
|
||||
$data['config_file_max_size'] = ((int)preg_filter('/[^0-9]/', '', ini_get('upload_max_filesize')) * 1024 * 1024);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/download.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['upload'] = $this->url->link('catalog/download.upload', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
if (isset($this->request->get['download_id'])) {
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
$download_info = $this->model_catalog_download->getDownload($this->request->get['download_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['download_id'])) {
|
||||
$data['download_id'] = (int)$this->request->get['download_id'];
|
||||
} else {
|
||||
$data['download_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['download_id'])) {
|
||||
$data['download_description'] = $this->model_catalog_download->getDescriptions($this->request->get['download_id']);
|
||||
} else {
|
||||
$data['download_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($download_info)) {
|
||||
$data['filename'] = $download_info['filename'];
|
||||
} else {
|
||||
$data['filename'] = '';
|
||||
}
|
||||
|
||||
if (!empty($download_info)) {
|
||||
$data['mask'] = $download_info['mask'];
|
||||
} else {
|
||||
$data['mask'] = '';
|
||||
}
|
||||
|
||||
$data['report'] = $this->getReport();
|
||||
|
||||
$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('catalog/download_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/download')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['download_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 3) || (oc_strlen($value['name']) > 64)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['filename']) < 3) || (oc_strlen($this->request->post['filename']) > 128)) {
|
||||
$json['error']['filename'] = $this->language->get('error_filename');
|
||||
}
|
||||
|
||||
if (substr(str_replace('\\', '/', realpath(DIR_DOWNLOAD . $this->request->post['filename'])), 0, strlen(DIR_DOWNLOAD)) != DIR_DOWNLOAD) {
|
||||
$json['error']['filename'] = $this->language->get('error_directory');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_DOWNLOAD . $this->request->post['filename'])) {
|
||||
$json['error']['filename'] = $this->language->get('error_exists');
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/._-]|[\p{Cyrillic}]+/u', $this->request->post['filename'])) {
|
||||
$json['error']['filename'] = $this->language->get('error_filename_character');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['mask']) < 3) || (oc_strlen($this->request->post['mask']) > 128)) {
|
||||
$json['error']['mask'] = $this->language->get('error_mask');
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/._-]|[\p{Cyrillic}]+/u', $this->request->post['mask'])) {
|
||||
$json['error']['mask'] = $this->language->get('error_mask_character');
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
if (!$this->request->post['download_id']) {
|
||||
$json['download_id'] = $this->model_catalog_download->addDownload($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_download->editDownload($this->request->post['download_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/download')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $download_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByDownloadId($download_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
foreach ($selected as $download_id) {
|
||||
$this->model_catalog_download->deleteDownload($download_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function report(): void {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$this->response->setOutput($this->getReport());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getReport(): string {
|
||||
if (isset($this->request->get['download_id'])) {
|
||||
$download_id = (int)$this->request->get['download_id'];
|
||||
} else {
|
||||
$download_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page']) && $this->request->get['route'] == 'catalog/download.report') {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$limit = 10;
|
||||
|
||||
$data['reports'] = [];
|
||||
|
||||
$this->load->model('catalog/download');
|
||||
$this->load->model('customer/customer');
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$results = $this->model_catalog_download->getReports($download_id, ($page - 1) * $limit, $limit);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$store_info = $this->model_setting_store->getStore($result['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store = $store_info['name'];
|
||||
} elseif (!$result['store_id']) {
|
||||
$store = $this->config->get('config_name');
|
||||
} else {
|
||||
$store = '';
|
||||
}
|
||||
|
||||
$data['reports'][] = [
|
||||
'ip' => $result['ip'],
|
||||
'account' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']),
|
||||
'store' => $store,
|
||||
'country' => $result['country'],
|
||||
'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])),
|
||||
'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip'])
|
||||
];
|
||||
}
|
||||
|
||||
$report_total = $this->model_catalog_download->getTotalReports($download_id);
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $report_total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('catalog/download.report', 'user_token=' . $this->session->data['user_token'] . '&download_id=' . $download_id . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($report_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($report_total - $limit)) ? $report_total : ((($page - 1) * $limit) + $limit), $report_total, ceil($report_total / $limit));
|
||||
|
||||
return $this->load->view('catalog/download_report', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function upload(): void {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$json = [];
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'catalog/download')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (empty($this->request->files['file']['name']) || !is_file($this->request->files['file']['tmp_name'])) {
|
||||
$json['error'] = $this->language->get('error_upload');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Sanitize the filename
|
||||
$filename = basename(html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8'));
|
||||
|
||||
// Validate the filename length
|
||||
if ((oc_strlen($filename) < 3) || (oc_strlen($filename) > 128)) {
|
||||
$json['error'] = $this->language->get('error_filename');
|
||||
}
|
||||
|
||||
// Allowed file extension types
|
||||
$allowed = [];
|
||||
|
||||
$extension_allowed = preg_replace('~\r?\n~', "\n", $this->config->get('config_file_ext_allowed'));
|
||||
|
||||
$filetypes = explode("\n", $extension_allowed);
|
||||
|
||||
foreach ($filetypes as $filetype) {
|
||||
$allowed[] = trim($filetype);
|
||||
}
|
||||
|
||||
if (!in_array(strtolower(substr(strrchr($filename, '.'), 1)), $allowed)) {
|
||||
$json['error'] = $this->language->get('error_file_type');
|
||||
}
|
||||
|
||||
// Allowed file mime types
|
||||
$allowed = [];
|
||||
|
||||
$mime_allowed = preg_replace('~\r?\n~', "\n", $this->config->get('config_file_mime_allowed'));
|
||||
|
||||
$filetypes = explode("\n", $mime_allowed);
|
||||
|
||||
foreach ($filetypes as $filetype) {
|
||||
$allowed[] = trim($filetype);
|
||||
}
|
||||
|
||||
if (!in_array($this->request->files['file']['type'], $allowed)) {
|
||||
$json['error'] = $this->language->get('error_file_type');
|
||||
}
|
||||
|
||||
// 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']);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$file = $filename . '.' . oc_token(32);
|
||||
|
||||
move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
|
||||
|
||||
$json['filename'] = $file;
|
||||
$json['mask'] = $filename;
|
||||
|
||||
$json['success'] = $this->language->get('text_upload');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function download(): void {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
if (isset($this->request->get['filename'])) {
|
||||
$filename = basename($this->request->get['filename']);
|
||||
} else {
|
||||
$filename = '';
|
||||
}
|
||||
|
||||
$file = DIR_DOWNLOAD . $filename;
|
||||
|
||||
if (is_file($file)) {
|
||||
if (!headers_sent()) {
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Description: File Transfer');
|
||||
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Expires: 0');
|
||||
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||
header('Pragma: public');
|
||||
header('Content-Length: ' . filesize($file));
|
||||
|
||||
readfile($file, 'rb');
|
||||
exit;
|
||||
} else {
|
||||
exit($this->language->get('error_headers_sent'));
|
||||
}
|
||||
} else {
|
||||
$this->load->language('error/not_found');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('error/not_found', '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('error/not_found', $data));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function autocomplete(): void {
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => 5
|
||||
];
|
||||
|
||||
$results = $this->model_catalog_download->getDownloads($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$json[] = [
|
||||
'download_id' => $result['download_id'],
|
||||
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
366
admininistrator/controller/catalog/filter.php
Normal file
366
admininistrator/controller/catalog/filter.php
Normal file
@ -0,0 +1,366 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Filter
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class Filter extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/filter.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/filter.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/filter', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'fgd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/filter.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['filters'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
$filter_total = $this->model_catalog_filter->getTotalGroups();
|
||||
|
||||
$results = $this->model_catalog_filter->getGroups($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['filters'][] = [
|
||||
'filter_group_id' => $result['filter_group_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/filter.form', 'user_token=' . $this->session->data['user_token'] . '&filter_group_id=' . $result['filter_group_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/filter.list', 'user_token=' . $this->session->data['user_token'] . '&sort=fgd.name' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/filter.list', 'user_token=' . $this->session->data['user_token'] . '&sort=fg.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $filter_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/filter.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($filter_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($filter_total - $this->config->get('config_pagination_admin'))) ? $filter_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $filter_total, ceil($filter_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/filter_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['filter_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/filter.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['filter_group_id'])) {
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
$filter_group_info = $this->model_catalog_filter->getGroup($this->request->get['filter_group_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_group_id'])) {
|
||||
$data['filter_group_id'] = (int)$this->request->get['filter_group_id'];
|
||||
} else {
|
||||
$data['filter_group_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['filter_group_id'])) {
|
||||
$data['filter_group_description'] = $this->model_catalog_filter->getGroupDescriptions($this->request->get['filter_group_id']);
|
||||
} else {
|
||||
$data['filter_group_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($filter_group_info)) {
|
||||
$data['sort_order'] = $filter_group_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
if (!empty($filter_group_info)) {
|
||||
$data['filters'] = $this->model_catalog_filter->getDescriptions($this->request->get['filter_group_id']);
|
||||
} else {
|
||||
$data['filters'] = [];
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/filter_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/filter')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['filter_group_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 1) || (oc_strlen($value['name']) > 64)) {
|
||||
$json['error']['group_' . $language_id] = $this->language->get('error_group');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['filter'])) {
|
||||
foreach ($this->request->post['filter'] as $key => $filter) {
|
||||
foreach ($filter['filter_description'] as $language_id => $filter_description) {
|
||||
if ((oc_strlen(trim($filter_description['name'])) < 1) || (oc_strlen($filter_description['name']) > 64)) {
|
||||
$json['error']['filter_' . $key . '_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$json['error']['warning'] = $this->language->get('error_values');
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
if (!$this->request->post['filter_group_id']) {
|
||||
$json['filter_group_id'] = $this->model_catalog_filter->addFilter($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_filter->editFilter($this->request->post['filter_group_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/filter')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
foreach ($selected as $filter_id) {
|
||||
$this->model_catalog_filter->deleteFilter($filter_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function autocomplete(): void {
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => 5
|
||||
];
|
||||
|
||||
$filters = $this->model_catalog_filter->getFilters($filter_data);
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
$json[] = [
|
||||
'filter_id' => $filter['filter_id'],
|
||||
'name' => strip_tags(html_entity_decode($filter['group'] . ' > ' . $filter['name'], ENT_QUOTES, 'UTF-8'))
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
417
admininistrator/controller/catalog/information.php
Normal file
417
admininistrator/controller/catalog/information.php
Normal file
@ -0,0 +1,417 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Information
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class Information extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/information.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/information.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('catalog/information', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'id.title';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/information.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['informations'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
$information_total = $this->model_catalog_information->getTotalInformations();
|
||||
|
||||
$results = $this->model_catalog_information->getInformations($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['informations'][] = [
|
||||
'information_id' => $result['information_id'],
|
||||
'title' => $result['title'],
|
||||
'status' => $result['status'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/information.form', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $result['information_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_title'] = $this->url->link('catalog/information.list', 'user_token=' . $this->session->data['user_token'] . '&sort=id.title' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/information.list', 'user_token=' . $this->session->data['user_token'] . '&sort=i.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $information_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/information.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($information_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($information_total - $this->config->get('config_pagination_admin'))) ? $information_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $information_total, ceil($information_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/information_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->document->addScript('view/javascript/ckeditor/ckeditor.js');
|
||||
$this->document->addScript('view/javascript/ckeditor/adapters/jquery.js');
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['information_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/information.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['information_id'])) {
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
$information_info = $this->model_catalog_information->getInformation($this->request->get['information_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['information_id'])) {
|
||||
$data['information_id'] = (int)$this->request->get['information_id'];
|
||||
} else {
|
||||
$data['information_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['information_id'])) {
|
||||
$data['information_description'] = $this->model_catalog_information->getDescriptions($this->request->get['information_id']);
|
||||
} else {
|
||||
$data['information_description'] = [];
|
||||
}
|
||||
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = [
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['information_id'])) {
|
||||
$data['information_store'] = $this->model_catalog_information->getStores($this->request->get['information_id']);
|
||||
} else {
|
||||
$data['information_store'] = [0];
|
||||
}
|
||||
|
||||
if (!empty($information_info)) {
|
||||
$data['bottom'] = $information_info['bottom'];
|
||||
} else {
|
||||
$data['bottom'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($information_info)) {
|
||||
$data['status'] = $information_info['status'];
|
||||
} else {
|
||||
$data['status'] = true;
|
||||
}
|
||||
|
||||
if (!empty($information_info)) {
|
||||
$data['sort_order'] = $information_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['information_id'])) {
|
||||
$data['information_seo_url'] = $this->model_catalog_information->getSeoUrls($this->request->get['information_id']);
|
||||
} else {
|
||||
$data['information_seo_url'] = [];
|
||||
}
|
||||
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
if (isset($this->request->get['information_id'])) {
|
||||
$data['information_layout'] = $this->model_catalog_information->getLayouts($this->request->get['information_id']);
|
||||
} else {
|
||||
$data['information_layout'] = [];
|
||||
}
|
||||
|
||||
$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('catalog/information_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/information')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['information_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['title'])) < 1) || (oc_strlen($value['title']) > 64)) {
|
||||
$json['error']['title_' . $language_id] = $this->language->get('error_title');
|
||||
}
|
||||
|
||||
if ((oc_strlen(trim($value['meta_title'])) < 1) || (oc_strlen($value['meta_title']) > 255)) {
|
||||
$json['error']['meta_title_' . $language_id] = $this->language->get('error_meta_title');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->post['information_seo_url']) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($this->request->post['information_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if ((oc_strlen(trim($keyword)) < 1) || (oc_strlen($keyword) > 64)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword');
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/_-]|[\p{Cyrillic}]+/u', $keyword)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_character');
|
||||
}
|
||||
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($keyword, $store_id);
|
||||
|
||||
if ($seo_url_info && (!isset($this->request->post['information_id']) || $seo_url_info['key'] != 'information_id' || $seo_url_info['value'] != (int)$this->request->post['information_id'])) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_exists');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
if (!$this->request->post['information_id']) {
|
||||
$json['information_id'] = $this->model_catalog_information->addInformation($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_information->editInformation($this->request->post['information_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/information')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
foreach ($selected as $information_id) {
|
||||
if ($this->config->get('config_account_id') == $information_id) {
|
||||
$json['error'] = $this->language->get('error_account');
|
||||
}
|
||||
|
||||
if ($this->config->get('config_checkout_id') == $information_id) {
|
||||
$json['error'] = $this->language->get('error_checkout');
|
||||
}
|
||||
|
||||
if ($this->config->get('config_affiliate_id') == $information_id) {
|
||||
$json['error'] = $this->language->get('error_affiliate');
|
||||
}
|
||||
|
||||
if ($this->config->get('config_return_id') == $information_id) {
|
||||
$json['error'] = $this->language->get('error_return');
|
||||
}
|
||||
|
||||
$store_total = $this->model_setting_store->getTotalStoresByInformationId($information_id);
|
||||
|
||||
if ($store_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_store'), $store_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
foreach ($selected as $information_id) {
|
||||
$this->model_catalog_information->deleteInformation($information_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
432
admininistrator/controller/catalog/manufacturer.php
Normal file
432
admininistrator/controller/catalog/manufacturer.php
Normal file
@ -0,0 +1,432 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Manufacturer
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class Manufacturer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/manufacturer.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/manufacturer.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('catalog/manufacturer', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/manufacturer.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['manufacturers'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
$manufacturer_total = $this->model_catalog_manufacturer->getTotalManufacturers();
|
||||
|
||||
$results = $this->model_catalog_manufacturer->getManufacturers($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['manufacturers'][] = [
|
||||
'manufacturer_id' => $result['manufacturer_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/manufacturer.form', 'user_token=' . $this->session->data['user_token'] . '&manufacturer_id=' . $result['manufacturer_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/manufacturer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/manufacturer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $manufacturer_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/manufacturer.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($manufacturer_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($manufacturer_total - $this->config->get('config_pagination_admin'))) ? $manufacturer_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $manufacturer_total, ceil($manufacturer_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/manufacturer_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['manufacturer_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/manufacturer.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['manufacturer_id'] = (int)$this->request->get['manufacturer_id'];
|
||||
} else {
|
||||
$data['manufacturer_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($manufacturer_info)) {
|
||||
$data['name'] = $manufacturer_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = [
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['manufacturer_store'] = $this->model_catalog_manufacturer->getStores($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$data['manufacturer_store'] = [0];
|
||||
}
|
||||
|
||||
if (!empty($manufacturer_info)) {
|
||||
$data['image'] = $manufacturer_info['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'), 100, 100);
|
||||
} else {
|
||||
$data['thumb'] = $data['placeholder'];
|
||||
}
|
||||
|
||||
if (!empty($manufacturer_info)) {
|
||||
$data['sort_order'] = $manufacturer_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['manufacturer_seo_url'] = $this->model_catalog_manufacturer->getSeoUrls($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$data['manufacturer_seo_url'] = [];
|
||||
}
|
||||
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
if (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['manufacturer_layout'] = $this->model_catalog_manufacturer->getLayouts($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$data['manufacturer_layout'] = [];
|
||||
}
|
||||
|
||||
$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('catalog/manufacturer_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/manufacturer')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 1) || (oc_strlen($this->request->post['name']) > 64)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ($this->request->post['manufacturer_seo_url']) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($this->request->post['manufacturer_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if ((oc_strlen(trim($keyword)) < 1) || (oc_strlen($keyword) > 64)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword');
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/_-]|[\p{Cyrillic}]+/u', $keyword)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_character');
|
||||
}
|
||||
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($keyword, $store_id);
|
||||
|
||||
if ($seo_url_info && ($seo_url_info['key'] != 'manufacturer_id' || !isset($this->request->post['manufacturer_id']) || $seo_url_info['value'] != (int)$this->request->post['manufacturer_id'])) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_exists');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
if (!$this->request->post['manufacturer_id']) {
|
||||
$json['manufacturer_id'] = $this->model_catalog_manufacturer->addManufacturer($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_manufacturer->editManufacturer($this->request->post['manufacturer_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/manufacturer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $manufacturer_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByManufacturerId($manufacturer_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
foreach ($selected as $manufacturer_id) {
|
||||
$this->model_catalog_manufacturer->deleteManufacturer($manufacturer_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function autocomplete(): void {
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => 5
|
||||
];
|
||||
|
||||
$results = $this->model_catalog_manufacturer->getManufacturers($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$json[] = [
|
||||
'manufacturer_id' => $result['manufacturer_id'],
|
||||
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
481
admininistrator/controller/catalog/option.php
Normal file
481
admininistrator/controller/catalog/option.php
Normal file
@ -0,0 +1,481 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Option
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class Option extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/option.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/option.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('catalog/option', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'od.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/option.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['options'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
$option_total = $this->model_catalog_option->getTotalOptions();
|
||||
|
||||
$results = $this->model_catalog_option->getOptions($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['options'][] = [
|
||||
'option_id' => $result['option_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/option.form', 'user_token=' . $this->session->data['user_token'] . '&option_id=' . $result['option_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/option.list', 'user_token=' . $this->session->data['user_token'] . '&sort=od.name' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/option.list', 'user_token=' . $this->session->data['user_token'] . '&sort=o.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $option_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/option.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($option_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($option_total - $this->config->get('config_pagination_admin'))) ? $option_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $option_total, ceil($option_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/option_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['option_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/option.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['option_id'])) {
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
$option_info = $this->model_catalog_option->getOption($this->request->get['option_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['option_id'])) {
|
||||
$data['option_id'] = (int)$this->request->get['option_id'];
|
||||
} else {
|
||||
$data['option_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['option_id'])) {
|
||||
$data['option_description'] = $this->model_catalog_option->getDescriptions($this->request->get['option_id']);
|
||||
} else {
|
||||
$data['option_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($option_info)) {
|
||||
$data['type'] = $option_info['type'];
|
||||
} else {
|
||||
$data['type'] = '';
|
||||
}
|
||||
|
||||
if (!empty($option_info)) {
|
||||
$data['sort_order'] = $option_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['option_id'])) {
|
||||
$option_values = $this->model_catalog_option->getValueDescriptions($this->request->get['option_id']);
|
||||
} else {
|
||||
$option_values = [];
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['option_values'] = [];
|
||||
|
||||
foreach ($option_values as $option_value) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $option_value['image'];
|
||||
$thumb = $option_value['image'];
|
||||
} else {
|
||||
$image = '';
|
||||
$thumb = 'no_image.png';
|
||||
}
|
||||
|
||||
$data['option_values'][] = [
|
||||
'option_value_id' => $option_value['option_value_id'],
|
||||
'option_value_description' => $option_value['option_value_description'],
|
||||
'image' => $image,
|
||||
'thumb' => $this->model_tool_image->resize(html_entity_decode($thumb, ENT_QUOTES, 'UTF-8'), 100, 100),
|
||||
'sort_order' => $option_value['sort_order']
|
||||
];
|
||||
}
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
$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('catalog/option_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/option')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['option_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 1) || (oc_strlen($value['name']) > 128)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (($this->request->post['type'] == 'select' || $this->request->post['type'] == 'radio' || $this->request->post['type'] == 'checkbox') && !isset($this->request->post['option_value'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_type');
|
||||
}
|
||||
|
||||
if (isset($this->request->post['option_value'])) {
|
||||
if (isset($this->request->post['option_id'])) {
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$option_value_data = [];
|
||||
|
||||
foreach ($this->request->post['option_value'] as $option_value) {
|
||||
if ($option_value['option_value_id']) {
|
||||
$option_value_data[] = $option_value['option_value_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$product_option_values = $this->model_catalog_product->getOptionValuesByOptionId($this->request->post['option_id']);
|
||||
|
||||
foreach ($product_option_values as $product_option_value) {
|
||||
if (!in_array($product_option_value['option_value_id'], $option_value_data)) {
|
||||
$json['error']['warning'] = sprintf($this->language->get('error_value'), $this->model_catalog_product->getTotalProductsByOptionValueId($product_option_value['option_value_id']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['option_value'])) {
|
||||
foreach ($this->request->post['option_value'] as $option_value_id => $option_value) {
|
||||
foreach ($option_value['option_value_description'] as $language_id => $option_value_description) {
|
||||
if ((oc_strlen(trim($option_value_description['name'])) < 1) || (oc_strlen($option_value_description['name']) > 128)) {
|
||||
$json['error']['option_value_' . $option_value_id . '_' . $language_id] = $this->language->get('error_option_value');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
if (!$this->request->post['option_id']) {
|
||||
$json['option_id'] = $this->model_catalog_option->addOption($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_option->editOption($this->request->post['option_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/option')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $option_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByOptionId($option_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
foreach ($selected as $option_id) {
|
||||
$this->model_catalog_option->deleteOption($option_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function autocomplete(): void {
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => 5
|
||||
];
|
||||
|
||||
$options = $this->model_catalog_option->getOptions($filter_data);
|
||||
|
||||
foreach ($options as $option) {
|
||||
$option_value_data = [];
|
||||
|
||||
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
|
||||
$option_values = $this->model_catalog_option->getValues($option['option_id']);
|
||||
|
||||
foreach ($option_values as $option_value) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $this->model_tool_image->resize(html_entity_decode($option_value['image'], ENT_QUOTES, 'UTF-8'), 50, 50);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('no_image.png', 50, 50);
|
||||
}
|
||||
|
||||
$option_value_data[] = [
|
||||
'option_value_id' => $option_value['option_value_id'],
|
||||
'name' => strip_tags(html_entity_decode($option_value['name'], ENT_QUOTES, 'UTF-8')),
|
||||
'image' => $image
|
||||
];
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($option_value_data as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $option_value_data);
|
||||
}
|
||||
|
||||
$type = '';
|
||||
|
||||
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox') {
|
||||
$type = $this->language->get('text_choose');
|
||||
}
|
||||
|
||||
if ($option['type'] == 'text' || $option['type'] == 'textarea') {
|
||||
$type = $this->language->get('text_input');
|
||||
}
|
||||
|
||||
if ($option['type'] == 'file') {
|
||||
$type = $this->language->get('text_file');
|
||||
}
|
||||
|
||||
if ($option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
|
||||
$type = $this->language->get('text_date');
|
||||
}
|
||||
|
||||
$json[] = [
|
||||
'option_id' => $option['option_id'],
|
||||
'name' => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
|
||||
'category' => $type,
|
||||
'type' => $option['type'],
|
||||
'option_value' => $option_value_data
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
1378
admininistrator/controller/catalog/product.php
Normal file
1378
admininistrator/controller/catalog/product.php
Normal file
File diff suppressed because it is too large
Load Diff
575
admininistrator/controller/catalog/review.php
Normal file
575
admininistrator/controller/catalog/review.php
Normal file
@ -0,0 +1,575 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Review
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class Review extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$filter_product = $this->request->get['filter_product'];
|
||||
} else {
|
||||
$filter_product = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$filter_author = $this->request->get['filter_author'];
|
||||
} else {
|
||||
$filter_author = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$filter_status = $this->request->get['filter_status'];
|
||||
} else {
|
||||
$filter_status = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$filter_date_from = $this->request->get['filter_date_from'];
|
||||
} else {
|
||||
$filter_date_from = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$filter_date_to = $this->request->get['filter_date_to'];
|
||||
} else {
|
||||
$filter_date_to = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/review.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/review.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('catalog/review', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$filter_product = $this->request->get['filter_product'];
|
||||
} else {
|
||||
$filter_product = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$filter_author = $this->request->get['filter_author'];
|
||||
} else {
|
||||
$filter_author = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$filter_status = $this->request->get['filter_status'];
|
||||
} else {
|
||||
$filter_status = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$filter_date_from = $this->request->get['filter_date_from'];
|
||||
} else {
|
||||
$filter_date_from = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$filter_date_to = $this->request->get['filter_date_to'];
|
||||
} else {
|
||||
$filter_date_to = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'DESC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'r.date_added';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/review.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['reviews'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_product' => $filter_product,
|
||||
'filter_author' => $filter_author,
|
||||
'filter_status' => $filter_status,
|
||||
'filter_date_from' => $filter_date_from,
|
||||
'filter_date_to' => $filter_date_to,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
$review_total = $this->model_catalog_review->getTotalReviews($filter_data);
|
||||
|
||||
$results = $this->model_catalog_review->getReviews($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['reviews'][] = [
|
||||
'review_id' => $result['review_id'],
|
||||
'name' => $result['name'],
|
||||
'author' => $result['author'],
|
||||
'rating' => $result['rating'],
|
||||
'status' => $result['status'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'edit' => $this->url->link('catalog/review.form', 'user_token=' . $this->session->data['user_token'] . '&review_id=' . $result['review_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_product'] = $this->url->link('catalog/review.list', 'user_token=' . $this->session->data['user_token'] . '&sort=pd.name' . $url);
|
||||
$data['sort_author'] = $this->url->link('catalog/review.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.author' . $url);
|
||||
$data['sort_rating'] = $this->url->link('catalog/review.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.rating' . $url);
|
||||
$data['sort_date_added'] = $this->url->link('catalog/review.list', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_added' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $review_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/review.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($review_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($review_total - $this->config->get('config_pagination_admin'))) ? $review_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $review_total, ceil($review_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['filter_product'] = $filter_product;
|
||||
$data['filter_author'] = $filter_author;
|
||||
$data['filter_status'] = $filter_status;
|
||||
$data['filter_date_from'] = $filter_date_from;
|
||||
$data['filter_date_to'] = $filter_date_to;
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/review_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['review_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/review.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['review_id'])) {
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
$review_info = $this->model_catalog_review->getReview($this->request->get['review_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['review_id'])) {
|
||||
$data['review_id'] = (int)$this->request->get['review_id'];
|
||||
} else {
|
||||
$data['review_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($review_info)) {
|
||||
$data['product_id'] = $review_info['product_id'];
|
||||
} else {
|
||||
$data['product_id'] = '';
|
||||
}
|
||||
|
||||
if (!empty($review_info)) {
|
||||
$data['product'] = $review_info['product'];
|
||||
} else {
|
||||
$data['product'] = '';
|
||||
}
|
||||
|
||||
if (!empty($review_info)) {
|
||||
$data['author'] = $review_info['author'];
|
||||
} else {
|
||||
$data['author'] = '';
|
||||
}
|
||||
|
||||
if (!empty($review_info)) {
|
||||
$data['text'] = $review_info['text'];
|
||||
} else {
|
||||
$data['text'] = '';
|
||||
}
|
||||
|
||||
if (!empty($review_info)) {
|
||||
$data['rating'] = $review_info['rating'];
|
||||
} else {
|
||||
$data['rating'] = '';
|
||||
}
|
||||
|
||||
if (!empty($review_info)) {
|
||||
$data['date_added'] = ($review_info['date_added'] != '0000-00-00 00:00' ? $review_info['date_added'] : date('Y-m-d'));
|
||||
} else {
|
||||
$data['date_added'] = date('Y-m-d');
|
||||
}
|
||||
|
||||
if (!empty($review_info)) {
|
||||
$data['status'] = $review_info['status'];
|
||||
} else {
|
||||
$data['status'] = '';
|
||||
}
|
||||
|
||||
$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('catalog/review_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/review')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['author']) < 3) || (oc_strlen($this->request->post['author']) > 64)) {
|
||||
$json['error']['author'] = $this->language->get('error_author');
|
||||
}
|
||||
|
||||
if (!$this->request->post['product_id']) {
|
||||
$json['error']['product'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
if (oc_strlen($this->request->post['text']) < 1) {
|
||||
$json['error']['text'] = $this->language->get('error_text');
|
||||
}
|
||||
|
||||
if (!isset($this->request->post['rating']) || $this->request->post['rating'] < 0 || $this->request->post['rating'] > 5) {
|
||||
$json['error']['rating'] = $this->language->get('error_rating');
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
if (!$this->request->post['review_id']) {
|
||||
$json['review_id'] = $this->model_catalog_review->addReview($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_review->editReview($this->request->post['review_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/review')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
foreach ($selected as $review_id) {
|
||||
$this->model_catalog_review->deleteReview($review_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function sync(): void {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/review')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
$total = $this->model_catalog_product->getTotalProducts();
|
||||
$limit = 10;
|
||||
|
||||
$start = ($page - 1) * $limit;
|
||||
$end = $start > ($total - $limit) ? $total : ($start + $limit);
|
||||
|
||||
$product_data = [
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$results = $this->model_catalog_product->getProducts($product_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$this->model_catalog_product->editRating($result['product_id'], $this->model_catalog_review->getRating($result['product_id']));
|
||||
}
|
||||
|
||||
if ($total && $end < $total) {
|
||||
$json['text'] = sprintf($this->language->get('text_next'), $end, $total);
|
||||
|
||||
$json['next'] = $this->url->link('catalog/review.sync', 'user_token=' . $this->session->data['user_token'] . '&page=' . ($page + 1), true);
|
||||
} else {
|
||||
$json['success'] = sprintf($this->language->get('text_next'), $end, $total);
|
||||
|
||||
$json['next'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
432
admininistrator/controller/catalog/subscription_plan.php
Normal file
432
admininistrator/controller/catalog/subscription_plan.php
Normal file
@ -0,0 +1,432 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Catalog;
|
||||
/**
|
||||
* Class Subscription Plan
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Catalog
|
||||
*/
|
||||
class SubscriptionPlan extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('catalog/subscription_plan');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/subscription_plan', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('catalog/subscription_plan.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['copy'] = $this->url->link('catalog/subscription_plan.copy', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('catalog/subscription_plan.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('catalog/subscription_plan', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('catalog/subscription_plan');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'rd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('catalog/subscription_plan.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['subscription_plans'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('catalog/subscription_plan');
|
||||
|
||||
$subscription_plan_total = $this->model_catalog_subscription_plan->getTotalSubscriptionPlans();
|
||||
|
||||
$results = $this->model_catalog_subscription_plan->getSubscriptionPlans($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['subscription_plans'][] = [
|
||||
'subscription_plan_id' => $result['subscription_plan_id'],
|
||||
'name' => $result['name'],
|
||||
'status' => $result['status'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/subscription_plan.form', 'user_token=' . $this->session->data['user_token'] . '&subscription_plan_id=' . $result['subscription_plan_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/subscription_plan.list', 'user_token=' . $this->session->data['user_token'] . '&sort=spd.name' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/subscription_plan.list', 'user_token=' . $this->session->data['user_token'] . '&sort=sp.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $subscription_plan_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('catalog/subscription_plan.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($subscription_plan_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($subscription_plan_total - $this->config->get('config_pagination_admin'))) ? $subscription_plan_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $subscription_plan_total, ceil($subscription_plan_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('catalog/subscription_plan_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('catalog/subscription_plan');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['subscription_plan_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/subscription_plan', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('catalog/subscription_plan.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('catalog/subscription_plan', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['subscription_plan_id'])) {
|
||||
$this->load->model('catalog/subscription_plan');
|
||||
|
||||
$subscription_info = $this->model_catalog_subscription_plan->getSubscriptionPlan($this->request->get['subscription_plan_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['subscription_plan_id'])) {
|
||||
$data['subscription_plan_id'] = (int)$this->request->get['subscription_plan_id'];
|
||||
} else {
|
||||
$data['subscription_plan_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['subscription_plan_id'])) {
|
||||
$data['subscription_plan_description'] = $this->model_catalog_subscription_plan->getDescription($this->request->get['subscription_plan_id']);
|
||||
} else {
|
||||
$data['subscription_plan_description'] = [];
|
||||
}
|
||||
|
||||
$data['frequencies'] = [];
|
||||
|
||||
$data['frequencies'][] = [
|
||||
'text' => $this->language->get('text_day'),
|
||||
'value' => 'day'
|
||||
];
|
||||
|
||||
$data['frequencies'][] = [
|
||||
'text' => $this->language->get('text_week'),
|
||||
'value' => 'week'
|
||||
];
|
||||
|
||||
$data['frequencies'][] = [
|
||||
'text' => $this->language->get('text_semi_month'),
|
||||
'value' => 'semi_month'
|
||||
];
|
||||
|
||||
$data['frequencies'][] = [
|
||||
'text' => $this->language->get('text_month'),
|
||||
'value' => 'month'
|
||||
];
|
||||
|
||||
$data['frequencies'][] = [
|
||||
'text' => $this->language->get('text_year'),
|
||||
'value' => 'year'
|
||||
];
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['trial_frequency'] = $subscription_info['trial_frequency'];
|
||||
} else {
|
||||
$data['trial_frequency'] = '';
|
||||
}
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['trial_duration'] = $subscription_info['trial_duration'];
|
||||
} else {
|
||||
$data['trial_duration'] = '0';
|
||||
}
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['trial_cycle'] = $subscription_info['trial_cycle'];
|
||||
} else {
|
||||
$data['trial_cycle'] = '1';
|
||||
}
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['trial_status'] = $subscription_info['trial_status'];
|
||||
} else {
|
||||
$data['trial_status'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['frequency'] = $subscription_info['frequency'];
|
||||
} else {
|
||||
$data['frequency'] = '';
|
||||
}
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['duration'] = $subscription_info['duration'];
|
||||
} else {
|
||||
$data['duration'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['cycle'] = $subscription_info['cycle'];
|
||||
} else {
|
||||
$data['cycle'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['status'] = $subscription_info['status'];
|
||||
} else {
|
||||
$data['status'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($subscription_info)) {
|
||||
$data['sort_order'] = $subscription_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = 0;
|
||||
}
|
||||
|
||||
$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('catalog/subscription_plan_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('catalog/subscription_plan');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/subscription_plan')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['subscription_plan_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 3) || (oc_strlen($value['name']) > 255)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->post['trial_duration'] && (int)$this->request->post['trial_duration'] < 1) {
|
||||
$json['error']['trial_duration'] = $this->language->get('error_trial_duration');
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/subscription_plan');
|
||||
|
||||
if (!$this->request->post['subscription_plan_id']) {
|
||||
$json['subscription_plan_id'] = $this->model_catalog_subscription_plan->addSubscriptionPlan($this->request->post);
|
||||
} else {
|
||||
$this->model_catalog_subscription_plan->editSubscriptionPlan($this->request->post['subscription_plan_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function copy(): void {
|
||||
$this->load->language('catalog/subscription_plan');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/subscription_plan')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/subscription_plan');
|
||||
|
||||
foreach ($selected as $subscription_plan_id) {
|
||||
$this->model_catalog_subscription_plan->copySubscriptionPlan($subscription_plan_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('catalog/subscription_plan');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'catalog/subscription_plan')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $subscription_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsBySubscriptionPlanId($subscription_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('catalog/subscription_plan');
|
||||
|
||||
foreach ($selected as $subscription_plan_id) {
|
||||
$this->model_catalog_subscription_plan->deleteSubscriptionPlan($subscription_plan_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
320
admininistrator/controller/cms/antispam.php
Normal file
320
admininistrator/controller/cms/antispam.php
Normal file
@ -0,0 +1,320 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Cms;
|
||||
/**
|
||||
* Class Anti-Spam
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Cms
|
||||
*/
|
||||
class Antispam extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('cms/antispam');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$filter_keyword = (string)$this->request->get['filter_keyword'];
|
||||
} else {
|
||||
$filter_keyword = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('cms/antispam', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('cms/antispam.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('cms/antispam.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$data['filter_keyword'] = $filter_keyword;
|
||||
|
||||
$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('cms/antispam', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('cms/antispam');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$filter_keyword = (string)$this->request->get['filter_keyword'];
|
||||
} else {
|
||||
$filter_keyword = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'keyword';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('cms/antispam.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['antispams'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_keyword' => $filter_keyword,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('cms/antispam');
|
||||
|
||||
$antispam_total = $this->model_cms_antispam->getTotalAntispams($filter_data);
|
||||
|
||||
$results = $this->model_cms_antispam->getAntispams($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['antispams'][] = [
|
||||
'antispam_id' => $result['antispam_id'],
|
||||
'keyword' => $result['keyword'],
|
||||
'edit' => $this->url->link('cms/antispam.form', 'user_token=' . $this->session->data['user_token'] . '&antispam_id=' . $result['antispam_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_keyword'] = $this->url->link('cms/antispam.list', 'user_token=' . $this->session->data['user_token'] . '&sort=keyword' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $antispam_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('cms/antispam.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($antispam_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($antispam_total - $this->config->get('config_pagination_admin'))) ? $antispam_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $antispam_total, ceil($antispam_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('cms/antispam_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('cms/antispam');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['antispam_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('cms/antispam', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('cms/antispam.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('cms/antispam', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['antispam_id'])) {
|
||||
$this->load->model('cms/antispam');
|
||||
|
||||
$antispam_info = $this->model_cms_antispam->getAntispam($this->request->get['antispam_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['antispam_id'])) {
|
||||
$data['antispam_id'] = (int)$this->request->get['antispam_id'];
|
||||
} else {
|
||||
$data['antispam_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($antispam_info)) {
|
||||
$data['keyword'] = $antispam_info['keyword'];
|
||||
} else {
|
||||
$data['keyword'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('cms/antispam_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('cms/antispam');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/antispam')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['keyword']) < 1) || (oc_strlen($this->request->post['keyword']) > 64)) {
|
||||
$json['error']['keyword'] = $this->language->get('error_keyword');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('cms/antispam');
|
||||
|
||||
if (!$this->request->post['antispam_id']) {
|
||||
$json['antispam_id'] = $this->model_cms_antispam->addAntispam($this->request->post);
|
||||
} else {
|
||||
$this->model_cms_antispam->editAntispam($this->request->post['antispam_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('cms/antispam');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/antispam')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('cms/antispam');
|
||||
|
||||
foreach ($selected as $antispam_id) {
|
||||
$this->model_cms_antispam->deleteAntispam($antispam_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
431
admininistrator/controller/cms/article.php
Normal file
431
admininistrator/controller/cms/article.php
Normal file
@ -0,0 +1,431 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Cms;
|
||||
/**
|
||||
* Class Article
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Cms
|
||||
*/
|
||||
class Article extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('cms/article');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('cms/article', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('cms/article.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('cms/article.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('cms/article', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('cms/article');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'date_added';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('cms/article.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['articles'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('cms/article');
|
||||
|
||||
$article_total = $this->model_cms_article->getTotalArticles();
|
||||
|
||||
$results = $this->model_cms_article->getArticles($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['articles'][] = [
|
||||
'article_id' => $result['article_id'],
|
||||
'name' => $result['name'],
|
||||
'author' => $result['author'],
|
||||
'status' => $result['status'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'edit' => $this->url->link('cms/article.form', 'user_token=' . $this->session->data['user_token'] . '&article_id=' . $result['article_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('cms/article.list', 'user_token=' . $this->session->data['user_token'] . '&sort=ad.name' . $url);
|
||||
$data['sort_author'] = $this->url->link('cms/article.list', 'user_token=' . $this->session->data['user_token'] . '&sort=a.author' . $url);
|
||||
$data['sort_date_added'] = $this->url->link('cms/article.list', 'user_token=' . $this->session->data['user_token'] . '&sort=a.date_added' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $article_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('cms/article.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($article_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($article_total - $this->config->get('config_pagination_admin'))) ? $article_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $article_total, ceil($article_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('cms/article_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('cms/article');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->document->addScript('view/javascript/ckeditor/ckeditor.js');
|
||||
$this->document->addScript('view/javascript/ckeditor/adapters/jquery.js');
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['article_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('cms/article', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('cms/article.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('cms/article', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['article_id'])) {
|
||||
$this->load->model('cms/article');
|
||||
|
||||
$article_info = $this->model_cms_article->getArticle($this->request->get['article_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['article_id'])) {
|
||||
$data['article_id'] = (int)$this->request->get['article_id'];
|
||||
} else {
|
||||
$data['article_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
$data['article_description'] = [];
|
||||
|
||||
if (isset($this->request->get['article_id'])) {
|
||||
$results = $this->model_cms_article->getDescriptions($this->request->get['article_id']);
|
||||
|
||||
foreach ($results as $key => $result) {
|
||||
$data['article_description'][$key] = $result;
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['article_description'][$key]['thumb'] = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), 100, 100);
|
||||
} else {
|
||||
$data['article_description'][$key]['thumb'] = $data['placeholder'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($article_info)) {
|
||||
$data['author'] = $article_info['author'];
|
||||
} else {
|
||||
$data['author'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('cms/topic');
|
||||
|
||||
$data['topics'] = $this->model_cms_topic->getTopics();
|
||||
|
||||
if (!empty($article_info)) {
|
||||
$data['topic_id'] = $article_info['topic_id'];
|
||||
} else {
|
||||
$data['topic_id'] = 0;
|
||||
}
|
||||
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = [
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['article_id'])) {
|
||||
$data['article_store'] = $this->model_cms_article->getStores($this->request->get['article_id']);
|
||||
} else {
|
||||
$data['article_store'] = [0];
|
||||
}
|
||||
|
||||
if (!empty($article_info)) {
|
||||
$data['image'] = $article_info['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'), 100, 100);
|
||||
} else {
|
||||
$data['thumb'] = $data['placeholder'];
|
||||
}
|
||||
|
||||
if (!empty($article_info)) {
|
||||
$data['status'] = $article_info['status'];
|
||||
} else {
|
||||
$data['status'] = true;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['article_id'])) {
|
||||
$data['article_seo_url'] = $this->model_cms_article->getSeoUrls($this->request->get['article_id']);
|
||||
} else {
|
||||
$data['article_seo_url'] = [];
|
||||
}
|
||||
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
if (isset($this->request->get['article_id'])) {
|
||||
$data['article_layout'] = $this->model_cms_article->getLayouts($this->request->get['article_id']);
|
||||
} else {
|
||||
$data['article_layout'] = [];
|
||||
}
|
||||
|
||||
$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('cms/article_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('cms/article');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/article')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['article_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 1) || (oc_strlen($value['name']) > 255)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen(trim($value['meta_title'])) < 1) || (oc_strlen($value['meta_title']) > 255)) {
|
||||
$json['error']['meta_title_' . $language_id] = $this->language->get('error_meta_title');
|
||||
}
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['author']) < 3) || (oc_strlen($this->request->post['author']) > 64)) {
|
||||
$json['error']['author'] = $this->language->get('error_author');
|
||||
}
|
||||
|
||||
if ($this->request->post['article_seo_url']) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($this->request->post['article_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if ((oc_strlen(trim($keyword)) < 1) || (oc_strlen($keyword) > 64)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword');
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/_-]|[\p{Cyrillic}]+/u', $keyword)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_character');
|
||||
}
|
||||
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($keyword, $store_id);
|
||||
|
||||
if ($seo_url_info && (!isset($this->request->post['article_id']) || $seo_url_info['key'] != 'article_id' || $seo_url_info['value'] != (int)$this->request->post['article_id'])) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_exists');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('cms/article');
|
||||
|
||||
if (!$this->request->post['article_id']) {
|
||||
$json['article_id'] = $this->model_cms_article->addArticle($this->request->post);
|
||||
} else {
|
||||
$this->model_cms_article->editArticle($this->request->post['article_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('cms/article');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/article')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('cms/article');
|
||||
|
||||
foreach ($selected as $article_id) {
|
||||
$this->model_cms_article->deleteArticle($article_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
396
admininistrator/controller/cms/comment.php
Normal file
396
admininistrator/controller/cms/comment.php
Normal file
@ -0,0 +1,396 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Cms;
|
||||
/**
|
||||
* Class Comments
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Cms
|
||||
*/
|
||||
class Comment extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
||||
public function index() {
|
||||
$this->load->language('cms/comment');
|
||||
|
||||
$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'])
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('cms/comment', 'user_token=' . $this->session->data['user_token'])
|
||||
);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('cms/comment', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('cms/comment');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$filter_keyword = $this->request->get['filter_keyword'];
|
||||
} else {
|
||||
$filter_keyword = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_title'])) {
|
||||
$filter_title = $this->request->get['filter_title'];
|
||||
} else {
|
||||
$filter_title = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$filter_customer = $this->request->get['filter_customer'];
|
||||
} else {
|
||||
$filter_customer = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$filter_status = $this->request->get['filter_status'];
|
||||
} else {
|
||||
$filter_status = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$filter_date_added = $this->request->get['filter_date_added'];
|
||||
} else {
|
||||
$filter_date_added = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = $this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_title'])) {
|
||||
$url .= '&filter_title=' . urlencode(html_entity_decode($this->request->get['filter_title'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['comments'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'filter_keyword' => $filter_keyword,
|
||||
'filter_title' => $filter_title,
|
||||
'filter_customer' => $filter_customer,
|
||||
'filter_status' => $filter_status,
|
||||
'filter_date_added' => $filter_date_added,
|
||||
'start' => ($page - 1) * 10,
|
||||
'limit' => 10
|
||||
);
|
||||
|
||||
$this->load->model('cms/article');
|
||||
|
||||
$comment_total = $this->model_cms_article->getTotalComments($filter_data);
|
||||
|
||||
$results = $this->model_cms_article->getComments($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if (!$result['status']) {
|
||||
$approve = $this->url->link('cms/comment.approve', 'user_token=' . $this->session->data['user_token'] . '&comment_id=' . $result['comment_id'] . $url);
|
||||
} else {
|
||||
$approve = '';
|
||||
}
|
||||
|
||||
$data['comments'][] = array(
|
||||
'article' => $result['article'],
|
||||
'article_edit' => $this->url->link('cms/article.edit', 'user_token=' . $this->session->data['user_token'] . '&article_id=' . $result['article_id']),
|
||||
'customer' => $result['customer'],
|
||||
'customer_edit' => $this->url->link('customer/customer.edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id']),
|
||||
'comment' => nl2br($result['comment']),
|
||||
'date_added' => date('d/m/Y', strtotime($result['date_added'])),
|
||||
'approve' => $approve,
|
||||
'spam' => $this->url->link('cms/comment.spam', 'user_token=' . $this->session->data['user_token'] . '&comment_id=' . $result['comment_id'] . $url),
|
||||
'delete' => $this->url->link('cms/comment.delete', 'user_token=' . $this->session->data['user_token'] . '&comment_id=' . $result['comment_id'] . $url)
|
||||
);
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_title'])) {
|
||||
$url .= '&filter_title=' . urlencode(html_entity_decode($this->request->get['filter_title'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', array(
|
||||
'total' => $comment_total,
|
||||
'page' => $page,
|
||||
'limit' => 10,
|
||||
'url' => $this->url->link('cms/comment.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
));
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($comment_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($comment_total - $this->config->get('config_pagination_admin'))) ? $comment_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $comment_total, ceil($comment_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
return $this->load->view('cms/comment_list', $data);
|
||||
}
|
||||
|
||||
public function approve() {
|
||||
$this->load->language('cms/comment');
|
||||
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['article_comment_id'])) {
|
||||
$article_comment_id = $this->request->get['article_comment_id'];
|
||||
} else {
|
||||
$article_comment_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/comment')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('cms/article');
|
||||
|
||||
$comment_info = $this->model_cms_article->getComment($article_comment_id);
|
||||
|
||||
if (!$comment_info) {
|
||||
$json['error'] = $this->language->get('error_comment');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Approve Commentor
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$this->model_customer_customer->editCommentor($comment_info['customer_id'], 1);
|
||||
|
||||
// Approve all past comments
|
||||
$filter_data = array(
|
||||
'filter_customer_id' => $comment_info['customer_id'],
|
||||
'filter_status' => 0
|
||||
);
|
||||
|
||||
$results = $this->model_cms_comment->getComments($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$this->model_cms_comment->editStatus($result['customer_id'], 1);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_title'])) {
|
||||
$url .= '&filter_title=' . urlencode(html_entity_decode($this->request->get['filter_title'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$json['redirect'] = $this->url->link('cms/comment.comment', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function spam() {
|
||||
$this->load->language('cms/comment');
|
||||
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['comment_id'])) {
|
||||
$comment_id = $this->request->get['comment_id'];
|
||||
} else {
|
||||
$comment_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/comment')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('cms/article');
|
||||
|
||||
$comment_info = $this->model_cms_article->getComment($comment_id);
|
||||
|
||||
if (!$comment_info) {
|
||||
$json['error'] = $this->language->get('error_comment');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$this->model_customer_customer->editCommentor($comment_info['customer_id'], 0);
|
||||
$this->model_customer_customer->editStatus($comment_info['customer_id'], 0);
|
||||
$this->model_customer_customer->addHistory($comment_info['customer_id'], 'SPAMMER!!!');
|
||||
|
||||
// Delete all customer comments
|
||||
$results = $this->model_cms_comment->getComments(array('filter_customer_id' => $comment_info['customer_id']));
|
||||
|
||||
foreach ($results as $result) {
|
||||
$this->model_cms_comment->deleteCommentsByCustomerId($result['comment_id']);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_title'])) {
|
||||
$url .= '&filter_title=' . urlencode(html_entity_decode($this->request->get['filter_title'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$json['redirect'] = $this->url->link('cms/comment/comment', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('cms/comment');
|
||||
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['comment_id'])) {
|
||||
$comment_id = $this->request->get['comment_id'];
|
||||
} else {
|
||||
$comment_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/comment')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('cms/article');
|
||||
|
||||
$comment_info = $this->model_cms_article->getComment($comment_id);
|
||||
|
||||
if (!$comment_info) {
|
||||
$json['error'] = $this->language->get('error_comment');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->model_cms_article->deleteComment($comment_id);
|
||||
|
||||
$json['success'] = $this->language->get('error_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode($this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_title'])) {
|
||||
$url .= '&filter_title=' . urlencode(html_entity_decode($this->request->get['filter_title'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$json['redirect'] = $this->url->link('cms/comment.comment', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
389
admininistrator/controller/cms/topic.php
Normal file
389
admininistrator/controller/cms/topic.php
Normal file
@ -0,0 +1,389 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Cms;
|
||||
/**
|
||||
* Class Topic
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Cms
|
||||
*/
|
||||
class Topic extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('cms/topic');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('cms/topic', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('cms/topic.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('cms/topic.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('cms/topic', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('cms/topic');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 't.sort_order';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('cms/topic.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['topics'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('cms/topic');
|
||||
|
||||
$topic_total = $this->model_cms_topic->getTotalTopics();
|
||||
|
||||
$results = $this->model_cms_topic->getTopics($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['topics'][] = [
|
||||
'topic_id' => $result['topic_id'],
|
||||
'name' => $result['name'],
|
||||
'status' => $result['status'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('cms/topic.form', 'user_token=' . $this->session->data['user_token'] . '&topic_id=' . $result['topic_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('cms/topic.list', 'user_token=' . $this->session->data['user_token'] . '&sort=bcd.name' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('cms/topic.list', 'user_token=' . $this->session->data['user_token'] . '&sort=bc.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $topic_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('cms/topic.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($topic_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($topic_total - $this->config->get('config_pagination_admin'))) ? $topic_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $topic_total, ceil($topic_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('cms/topic_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('cms/topic');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->document->addScript('view/javascript/ckeditor/ckeditor.js');
|
||||
$this->document->addScript('view/javascript/ckeditor/adapters/jquery.js');
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['topic_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('cms/topic', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('cms/topic.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('cms/topic', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['topic_id'])) {
|
||||
$this->load->model('cms/topic');
|
||||
|
||||
$topic_info = $this->model_cms_topic->getTopic($this->request->get['topic_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['topic_id'])) {
|
||||
$data['topic_id'] = (int)$this->request->get['topic_id'];
|
||||
} else {
|
||||
$data['topic_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
$data['topic_description'] = [];
|
||||
|
||||
if (isset($this->request->get['topic_id'])) {
|
||||
$results = $this->model_cms_topic->getDescriptions($this->request->get['topic_id']);
|
||||
|
||||
foreach ($results as $key => $result) {
|
||||
$data['topic_description'][$key] = $result;
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['topic_description'][$key]['thumb'] = $this->model_tool_image->resize(html_entity_decode($result['image'], ENT_QUOTES, 'UTF-8'), 100, 100);
|
||||
} else {
|
||||
$data['topic_description'][$key]['thumb'] = $data['placeholder'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = [
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['topic_id'])) {
|
||||
$data['topic_store'] = $this->model_cms_topic->getStores($this->request->get['topic_id']);
|
||||
} else {
|
||||
$data['topic_store'] = [0];
|
||||
}
|
||||
|
||||
if (!empty($topic_info)) {
|
||||
$data['sort_order'] = $topic_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($topic_info)) {
|
||||
$data['status'] = $topic_info['status'];
|
||||
} else {
|
||||
$data['status'] = true;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['topic_id'])) {
|
||||
$data['topic_seo_url'] = $this->model_cms_topic->getSeoUrls($this->request->get['topic_id']);
|
||||
} else {
|
||||
$data['topic_seo_url'] = [];
|
||||
}
|
||||
|
||||
$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('cms/topic_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('cms/topic');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/topic')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['topic_description'] as $language_id => $value) {
|
||||
if ((oc_strlen(trim($value['name'])) < 1) || (oc_strlen($value['name']) > 255)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen(trim($value['meta_title'])) < 1) || (oc_strlen($value['meta_title']) > 255)) {
|
||||
$json['error']['meta_title_' . $language_id] = $this->language->get('error_meta_title');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->post['topic_seo_url']) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($this->request->post['topic_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if ((oc_strlen(trim($keyword)) < 1) || (oc_strlen($keyword) > 64)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword');
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/_-]|[\p{Cyrillic}]+/u', $keyword)) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_character');
|
||||
}
|
||||
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($keyword, $store_id);
|
||||
|
||||
if ($seo_url_info && (!isset($this->request->post['topic_id']) || $seo_url_info['key'] != 'topic_id' || $seo_url_info['value'] != (int)$this->request->post['topic_id'])) {
|
||||
$json['error']['keyword_' . $store_id . '_' . $language_id] = $this->language->get('error_keyword_exists');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($json['error']) && !isset($json['error']['warning'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('cms/topic');
|
||||
|
||||
if (!$this->request->post['topic_id']) {
|
||||
$json['topic_id'] = $this->model_cms_topic->addTopic($this->request->post);
|
||||
} else {
|
||||
$this->model_cms_topic->editTopic($this->request->post['topic_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('cms/topic');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'cms/topic')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('cms/topic');
|
||||
|
||||
foreach ($selected as $topic_id) {
|
||||
$this->model_cms_topic->deleteTopic($topic_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
243
admininistrator/controller/common/authorize.php
Normal file
243
admininistrator/controller/common/authorize.php
Normal file
@ -0,0 +1,243 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Authorize
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Authorize extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (isset($this->request->cookie['authorize'])) {
|
||||
$token = $this->request->cookie['authorize'];
|
||||
} else {
|
||||
$token = '';
|
||||
}
|
||||
|
||||
// Check to see if user is using incorrect 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'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$login_info = $this->model_user_user->getAuthorizeByToken($this->user->getId(), $token);
|
||||
|
||||
if (!$login_info) {
|
||||
// Create a token that can be stored as a cookie and will be used to identify device is safe.
|
||||
$token = oc_token(32);
|
||||
|
||||
$authorize_data = [
|
||||
'token' => $token,
|
||||
'ip' => $this->request->server['REMOTE_ADDR'],
|
||||
'user_agent' => $this->request->server['HTTP_USER_AGENT']
|
||||
];
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->model_user_user->addAuthorize($this->user->getId(), $authorize_data);
|
||||
|
||||
setcookie('authorize', $token, time() + 60 * 60 * 24 * 365 * 10);
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('common/authorize.validate', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
// Set the code to be emailed
|
||||
$this->session->data['code'] = oc_token(4);
|
||||
|
||||
if (isset($this->request->get['route']) && $this->request->get['route'] != 'common/login' && $this->request->get['route'] != 'common/authorize') {
|
||||
$args = $this->request->get;
|
||||
|
||||
$route = $args['route'];
|
||||
|
||||
unset($args['route']);
|
||||
unset($args['user_token']);
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($args) {
|
||||
$url .= http_build_query($args);
|
||||
}
|
||||
|
||||
$data['redirect'] = $this->url->link($route, $url);
|
||||
} else {
|
||||
$data['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/authorize', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function send() {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
$json = [];
|
||||
|
||||
$json['success'] = $this->language->get('text_resend');
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function validate(): void {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->cookie['authorize'])) {
|
||||
$token = $this->request->cookie['authorize'];
|
||||
} else {
|
||||
$token = '';
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$authorize_info = $this->model_user_user->getAuthorizeByToken($this->user->getId(), $token);
|
||||
|
||||
if ($authorize_info) {
|
||||
if (($authorize_info['attempts'] <= 2) && (!isset($this->request->post['code']) || !isset($this->session->data['code']) || ($this->request->post['code'] != $this->session->data['code']))) {
|
||||
$json['error'] = $this->language->get('error_code');
|
||||
|
||||
$this->model_user_user->editAuthorizeTotal($authorize_info['user_authorize_id'], $authorize_info['total'] + 1);
|
||||
}
|
||||
|
||||
if ($authorize_info['attempts'] >= 2) {
|
||||
$json['redirect'] = $this->url->link('common/authorize.unlock', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_code');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->model_user_user->editAuthorizeStatus($authorize_info['user_authorize_id'], 1);
|
||||
$this->model_user_user->editAuthorizeTotal($authorize_info['user_authorize_id'], 0);
|
||||
|
||||
// Register the cookie for security.
|
||||
if (isset($this->request->post['redirect']) && (strpos($this->request->post['redirect'], HTTP_SERVER) === 0)) {
|
||||
$json['redirect'] = str_replace('&', '&', $this->request->post['redirect'] . '&user_token=' . $this->session->data['user_token']);
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function unlock() {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
if (isset($this->request->cookie['authorize'])) {
|
||||
$token = $this->request->cookie['authorize'];
|
||||
} else {
|
||||
$token = '';
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$authorize_info = $this->model_user_user->getAuthorizeByToken($this->user->getId(), $token);
|
||||
|
||||
if ($authorize_info && $authorize_info['status']) {
|
||||
// Redirect if already have a valid token.
|
||||
$this->response->redirect($this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true));
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/authorize_unlock', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm() {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
$json = [];
|
||||
|
||||
$json['success'] = $this->language->get('text_link');
|
||||
|
||||
// Create reset code
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->model_user_user->editCode($this->user->getEmail(), oc_token(32));
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function reset() {
|
||||
$this->load->language('common/authorize');
|
||||
|
||||
if (isset($this->request->get['email'])) {
|
||||
$email = (string)$this->request->get['email'];
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = (string)$this->request->get['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUserByEmail($email);
|
||||
|
||||
if ($user_info && $user_info['code'] && $code && $user_info['code'] === $code) {
|
||||
$this->model_user_user->resetAuthorizes($user_info['user_id']);
|
||||
|
||||
$this->model_user_user->editCode($email, '');
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_unlocked');
|
||||
|
||||
$this->response->redirect($this->url->link('common/authorize', 'user_token=' . $this->session->data['user_token'], true));
|
||||
} else {
|
||||
$this->user->logout();
|
||||
|
||||
$this->model_user_user->editCode($email, '');
|
||||
|
||||
$this->session->data['error'] = $this->language->get('error_reset');
|
||||
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
}
|
||||
}
|
808
admininistrator/controller/common/column_left.php
Normal file
808
admininistrator/controller/common/column_left.php
Normal file
@ -0,0 +1,808 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Column Left
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class ColumnLeft extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
if (isset($this->request->get['user_token']) && isset($this->session->data['user_token']) && ((string)$this->request->get['user_token'] == $this->session->data['user_token'])) {
|
||||
$this->load->language('common/column_left');
|
||||
|
||||
// Create a 3 level menu array
|
||||
// Level 2 cannot have children
|
||||
|
||||
// Menu
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-dashboard',
|
||||
'icon' => 'fas fa-home',
|
||||
'name' => $this->language->get('text_dashboard'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
|
||||
// Catalog
|
||||
$catalog = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/category')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_category'),
|
||||
'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/product')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_product'),
|
||||
'href' => $this->url->link('catalog/product', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/subscription_plan')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_subscription_plan'),
|
||||
'href' => $this->url->link('catalog/subscription_plan', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/filter')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_filter'),
|
||||
'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Attributes
|
||||
$attribute = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/attribute')) {
|
||||
$attribute[] = [
|
||||
'name' => $this->language->get('text_attribute'),
|
||||
'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/attribute_group')) {
|
||||
$attribute[] = [
|
||||
'name' => $this->language->get('text_attribute_group'),
|
||||
'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($attribute) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_attribute'),
|
||||
'href' => '',
|
||||
'children' => $attribute
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/option')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_option'),
|
||||
'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/manufacturer')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_manufacturer'),
|
||||
'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/download')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_download'),
|
||||
'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/review')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_review'),
|
||||
'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'catalog/information')) {
|
||||
$catalog[] = [
|
||||
'name' => $this->language->get('text_information'),
|
||||
'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($catalog) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-catalog',
|
||||
'icon' => 'fa-solid fa-tag',
|
||||
'name' => $this->language->get('text_catalog'),
|
||||
'href' => '',
|
||||
'children' => $catalog
|
||||
];
|
||||
}
|
||||
|
||||
$cms = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'cms/topic')) {
|
||||
$cms[] = [
|
||||
'name' => $this->language->get('text_topic'),
|
||||
'href' => $this->url->link('cms/topic', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'cms/article')) {
|
||||
$cms[] = [
|
||||
'name' => $this->language->get('text_article'),
|
||||
'href' => $this->url->link('cms/article', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'cms/comment')) {
|
||||
$cms[] = [
|
||||
'name' => $this->language->get('text_comment'),
|
||||
'href' => $this->url->link('cms/comment', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'cms/antispam')) {
|
||||
$cms[] = [
|
||||
'name' => $this->language->get('text_antispam'),
|
||||
'href' => $this->url->link('cms/antispam', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
// Still in development
|
||||
//if ($cms) {
|
||||
// $data['menus'][] = [
|
||||
// 'id' => 'menu-cms',
|
||||
// 'icon' => 'fa-regular fa-newspaper',
|
||||
// 'name' => $this->language->get('text_cms'),
|
||||
// 'href' => '',
|
||||
// 'children' => $cms
|
||||
// ];
|
||||
//}
|
||||
|
||||
// Extension
|
||||
$marketplace = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/marketplace')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_marketplace'),
|
||||
'href' => $this->url->link('marketplace/marketplace', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/installer')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_installer'),
|
||||
'href' => $this->url->link('marketplace/installer', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/extension')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_extension'),
|
||||
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/startup')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_startup'),
|
||||
'href' => $this->url->link('marketplace/startup', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/event')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_event'),
|
||||
'href' => $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketplace/cron')) {
|
||||
$marketplace[] = [
|
||||
'name' => $this->language->get('text_cron'),
|
||||
'href' => $this->url->link('marketplace/cron', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($marketplace) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-extension',
|
||||
'icon' => 'fas fa-puzzle-piece',
|
||||
'name' => $this->language->get('text_extension'),
|
||||
'href' => '',
|
||||
'children' => $marketplace
|
||||
];
|
||||
}
|
||||
|
||||
// Design
|
||||
$design = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/layout')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_layout'),
|
||||
'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/theme')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_theme'),
|
||||
'href' => $this->url->link('design/theme', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/translation')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_language_editor'),
|
||||
'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/banner')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_banner'),
|
||||
'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
$seo = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'design/seo_url')) {
|
||||
$design[] = [
|
||||
'name' => $this->language->get('text_seo_url'),
|
||||
'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($design) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-design',
|
||||
'icon' => 'fas fa-desktop',
|
||||
'name' => $this->language->get('text_design'),
|
||||
'href' => '',
|
||||
'children' => $design
|
||||
];
|
||||
}
|
||||
|
||||
// Sales
|
||||
$sale = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/order')) {
|
||||
$sale[] = [
|
||||
'name' => $this->language->get('text_order'),
|
||||
'href' => $this->url->link('sale/order', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/subscription')) {
|
||||
$sale[] = [
|
||||
'name' => $this->language->get('text_subscription'),
|
||||
'href' => $this->url->link('sale/subscription', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/returns')) {
|
||||
$sale[] = [
|
||||
'name' => $this->language->get('text_return'),
|
||||
'href' => $this->url->link('sale/returns', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Voucher
|
||||
$voucher = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/voucher')) {
|
||||
$voucher[] = [
|
||||
'name' => $this->language->get('text_voucher'),
|
||||
'href' => $this->url->link('sale/voucher', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'sale/voucher_theme')) {
|
||||
$voucher[] = [
|
||||
'name' => $this->language->get('text_voucher_theme'),
|
||||
'href' => $this->url->link('sale/voucher_theme', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($voucher) {
|
||||
$sale[] = [
|
||||
'name' => $this->language->get('text_voucher'),
|
||||
'href' => '',
|
||||
'children' => $voucher
|
||||
];
|
||||
}
|
||||
|
||||
if ($sale) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-sale',
|
||||
'icon' => 'fas fa-shopping-cart',
|
||||
'name' => $this->language->get('text_sale'),
|
||||
'href' => '',
|
||||
'children' => $sale
|
||||
];
|
||||
}
|
||||
|
||||
// Customer
|
||||
$customer = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/customer')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_customer'),
|
||||
'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/customer_group')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_customer_group'),
|
||||
'href' => $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/customer_approval')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_customer_approval'),
|
||||
'href' => $this->url->link('customer/customer_approval', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/gdpr')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_gdpr'),
|
||||
'href' => $this->url->link('customer/gdpr', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'customer/custom_field')) {
|
||||
$customer[] = [
|
||||
'name' => $this->language->get('text_custom_field'),
|
||||
'href' => $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($customer) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-customer',
|
||||
'icon' => 'fas fa-user',
|
||||
'name' => $this->language->get('text_customer'),
|
||||
'href' => '',
|
||||
'children' => $customer
|
||||
];
|
||||
}
|
||||
|
||||
// Marketing
|
||||
$marketing = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketing/affiliate')) {
|
||||
$marketing[] = [
|
||||
'name' => $this->language->get('text_affiliate'),
|
||||
'href' => $this->url->link('marketing/affiliate', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketing/marketing')) {
|
||||
$marketing[] = [
|
||||
'name' => $this->language->get('text_marketing'),
|
||||
'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketing/coupon')) {
|
||||
$marketing[] = [
|
||||
'name' => $this->language->get('text_coupon'),
|
||||
'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'marketing/contact')) {
|
||||
$marketing[] = [
|
||||
'name' => $this->language->get('text_contact'),
|
||||
'href' => $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($marketing) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-marketing',
|
||||
'icon' => 'fas fa-share-alt',
|
||||
'name' => $this->language->get('text_marketing'),
|
||||
'href' => '',
|
||||
'children' => $marketing
|
||||
];
|
||||
}
|
||||
|
||||
// System
|
||||
$system = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'setting/setting')) {
|
||||
$system[] = [
|
||||
'name' => $this->language->get('text_setting'),
|
||||
'href' => $this->url->link('setting/store', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Users
|
||||
$user = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'user/user')) {
|
||||
$user[] = [
|
||||
'name' => $this->language->get('text_users'),
|
||||
'href' => $this->url->link('user/user', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'user/user_permission')) {
|
||||
$user[] = [
|
||||
'name' => $this->language->get('text_user_group'),
|
||||
'href' => $this->url->link('user/user_permission', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'user/api')) {
|
||||
$user[] = [
|
||||
'name' => $this->language->get('text_api'),
|
||||
'href' => $this->url->link('user/api', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($user) {
|
||||
$system[] = [
|
||||
'name' => $this->language->get('text_users'),
|
||||
'href' => '',
|
||||
'children' => $user
|
||||
];
|
||||
}
|
||||
|
||||
// Localisation
|
||||
$localisation = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/location')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_location'),
|
||||
'href' => $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/language')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_language'),
|
||||
'href' => $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/currency')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_currency'),
|
||||
'href' => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/stock_status')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_stock_status'),
|
||||
'href' => $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/order_status')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_order_status'),
|
||||
'href' => $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/subscription_status')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_subscription_status'),
|
||||
'href' => $this->url->link('localisation/subscription_status', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Returns
|
||||
$returns = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/return_status')) {
|
||||
$returns[] = [
|
||||
'name' => $this->language->get('text_return_status'),
|
||||
'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/return_action')) {
|
||||
$returns[] = [
|
||||
'name' => $this->language->get('text_return_action'),
|
||||
'href' => $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/return_reason')) {
|
||||
$returns[] = [
|
||||
'name' => $this->language->get('text_return_reason'),
|
||||
'href' => $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($returns) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_return'),
|
||||
'href' => '',
|
||||
'children' => $returns
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/country')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_country'),
|
||||
'href' => $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/zone')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_zone'),
|
||||
'href' => $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/geo_zone')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_geo_zone'),
|
||||
'href' => $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
// Tax
|
||||
$tax = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/tax_class')) {
|
||||
$tax[] = [
|
||||
'name' => $this->language->get('text_tax_class'),
|
||||
'href' => $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/tax_rate')) {
|
||||
$tax[] = [
|
||||
'name' => $this->language->get('text_tax_rate'),
|
||||
'href' => $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($tax) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_tax'),
|
||||
'href' => '',
|
||||
'children' => $tax
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/length_class')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_length_class'),
|
||||
'href' => $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/weight_class')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_weight_class'),
|
||||
'href' => $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'localisation/address_format')) {
|
||||
$localisation[] = [
|
||||
'name' => $this->language->get('text_address_format'),
|
||||
'href' => $this->url->link('localisation/address_format', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($localisation) {
|
||||
$system[] = [
|
||||
'name' => $this->language->get('text_localisation'),
|
||||
'href' => '',
|
||||
'children' => $localisation
|
||||
];
|
||||
}
|
||||
|
||||
// Tools
|
||||
$maintenance = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'tool/upgrade')) {
|
||||
$maintenance[] = [
|
||||
'name' => $this->language->get('text_upgrade'),
|
||||
'href' => $this->url->link('tool/upgrade', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'tool/backup')) {
|
||||
$maintenance[] = [
|
||||
'name' => $this->language->get('text_backup'),
|
||||
'href' => $this->url->link('tool/backup', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'tool/upload')) {
|
||||
$maintenance[] = [
|
||||
'name' => $this->language->get('text_upload'),
|
||||
'href' => $this->url->link('tool/upload', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'tool/log')) {
|
||||
$maintenance[] = [
|
||||
'name' => $this->language->get('text_log'),
|
||||
'href' => $this->url->link('tool/log', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($maintenance) {
|
||||
$system[] = [
|
||||
'name' => $this->language->get('text_maintenance'),
|
||||
'href' => '',
|
||||
'children' => $maintenance
|
||||
];
|
||||
}
|
||||
|
||||
if ($system) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-system',
|
||||
'icon' => 'fas fa-cog',
|
||||
'name' => $this->language->get('text_system'),
|
||||
'href' => '',
|
||||
'children' => $system
|
||||
];
|
||||
}
|
||||
|
||||
$report = [];
|
||||
|
||||
if ($this->user->hasPermission('access', 'report/report')) {
|
||||
$report[] = [
|
||||
'name' => $this->language->get('text_reports'),
|
||||
'href' => $this->url->link('report/report', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'report/online')) {
|
||||
$report[] = [
|
||||
'name' => $this->language->get('text_online'),
|
||||
'href' => $this->url->link('report/online', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'report/statistics')) {
|
||||
$report[] = [
|
||||
'name' => $this->language->get('text_statistics'),
|
||||
'href' => $this->url->link('report/statistics', 'user_token=' . $this->session->data['user_token']),
|
||||
'children' => []
|
||||
];
|
||||
}
|
||||
|
||||
if ($report) {
|
||||
$data['menus'][] = [
|
||||
'id' => 'menu-report',
|
||||
'icon' => 'fas fa-chart-bar',
|
||||
'name' => $this->language->get('text_reports'),
|
||||
'href' => '',
|
||||
'children' => $report
|
||||
];
|
||||
}
|
||||
|
||||
// Stats
|
||||
if ($this->user->hasPermission('access', 'report/statistics')) {
|
||||
$this->load->model('sale/order');
|
||||
|
||||
$order_total = (float)$this->model_sale_order->getTotalOrders();
|
||||
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$complete_total = (float)$this->model_report_statistics->getValue('order_complete');
|
||||
|
||||
if ($complete_total && $order_total) {
|
||||
$data['complete_status'] = round(($complete_total / $order_total) * 100);
|
||||
} else {
|
||||
$data['complete_status'] = 0;
|
||||
}
|
||||
|
||||
$processing_total = (float)$this->model_report_statistics->getValue('order_processing');
|
||||
|
||||
if ($processing_total && $order_total) {
|
||||
$data['processing_status'] = round(($processing_total / $order_total) * 100);
|
||||
} else {
|
||||
$data['processing_status'] = 0;
|
||||
}
|
||||
|
||||
$other_total = (float)$this->model_report_statistics->getValue('order_other');
|
||||
|
||||
if ($other_total && $order_total) {
|
||||
$data['other_status'] = round(($other_total / $order_total) * 100);
|
||||
} else {
|
||||
$data['other_status'] = 0;
|
||||
}
|
||||
|
||||
$data['statistics_status'] = true;
|
||||
} else {
|
||||
$data['statistics_status'] = false;
|
||||
}
|
||||
|
||||
return $this->load->view('common/column_left', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
100
admininistrator/controller/common/dashboard.php
Normal file
100
admininistrator/controller/common/dashboard.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Dashboard
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Dashboard extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/dashboard');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
// Dashboard Extensions
|
||||
$dashboards = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
// Get a list of installed modules
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('dashboard');
|
||||
|
||||
// Add all the modules which have multiple settings for each module
|
||||
foreach ($extensions as $extension) {
|
||||
if ($this->config->get('dashboard_' . $extension['code'] . '_status') && $this->user->hasPermission('access', 'extension/' . $extension['extension'] . '/dashboard/' . $extension['code'])) {
|
||||
$output = $this->load->controller('extension/' . $extension['extension'] . '/dashboard/' . $extension['code'] . '.dashboard');
|
||||
|
||||
//if (!$output instanceof \Exception) {
|
||||
if ($output) {
|
||||
$dashboards[] = [
|
||||
'code' => $extension['code'],
|
||||
'width' => $this->config->get('dashboard_' . $extension['code'] . '_width'),
|
||||
'sort_order' => $this->config->get('dashboard_' . $extension['code'] . '_sort_order'),
|
||||
'output' => $output
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($dashboards as $key => $value) {
|
||||
$sort_order[$key] = $value['sort_order'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $dashboards);
|
||||
|
||||
// Split the array so the columns width is not more than 12 on each row.
|
||||
$width = 0;
|
||||
$column = [];
|
||||
$data['rows'] = [];
|
||||
|
||||
foreach ($dashboards as $dashboard) {
|
||||
$column[] = $dashboard;
|
||||
|
||||
$width = ($width + $dashboard['width']);
|
||||
|
||||
if ($width >= 12) {
|
||||
$data['rows'][] = $column;
|
||||
|
||||
$width = 0;
|
||||
$column = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($column)) {
|
||||
$data['rows'][] = $column;
|
||||
}
|
||||
|
||||
if ($this->user->hasPermission('access', 'common/developer')) {
|
||||
$data['developer_status'] = true;
|
||||
} else {
|
||||
$data['developer_status'] = false;
|
||||
}
|
||||
|
||||
$data['security'] = $this->load->controller('common/security');
|
||||
|
||||
$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('common/dashboard', $data));
|
||||
}
|
||||
}
|
130
admininistrator/controller/common/developer.php
Normal file
130
admininistrator/controller/common/developer.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Developer
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Developer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/developer');
|
||||
|
||||
$data['developer_sass'] = $this->config->get('developer_sass');
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->response->setOutput($this->load->view('common/developer', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function edit(): void {
|
||||
$this->load->language('common/developer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'common/developer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$this->model_setting_setting->editSetting('developer', $this->request->post, 0);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function theme(): void {
|
||||
$this->load->language('common/developer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'common/developer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$directories = glob(DIR_CACHE . 'template/*', GLOB_ONLYDIR);
|
||||
|
||||
if ($directories) {
|
||||
foreach ($directories as $directory) {
|
||||
$files = glob($directory . '/*');
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_dir($directory)) {
|
||||
rmdir($directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = sprintf($this->language->get('text_cache'), $this->language->get('text_theme'));
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function sass(): void {
|
||||
$this->load->language('common/developer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'common/developer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Before we delete we need to make sure there is a sass file to regenerate the css
|
||||
$file = DIR_APPLICATION . 'view/stylesheet/bootstrap.css';
|
||||
|
||||
if (is_file($file) && is_file(DIR_APPLICATION . 'view/stylesheet/scss/bootstrap.scss')) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
$files = glob(DIR_CATALOG . 'view/theme/*/stylesheet/scss/bootstrap.scss');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file = substr($file, 0, -20) . '/bootstrap.css';
|
||||
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
$files = glob(DIR_CATALOG . 'view/theme/*/stylesheet/stylesheet.scss');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$file = substr($file, 0, -16) . '/stylesheet.css';
|
||||
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = sprintf($this->language->get('text_cache'), $this->language->get('text_sass'));
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
485
admininistrator/controller/common/filemanager.php
Normal file
485
admininistrator/controller/common/filemanager.php
Normal file
@ -0,0 +1,485 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class File Manager
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class FileManager extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$data['error_upload_size'] = sprintf($this->language->get('error_upload_size'), $this->config->get('config_file_max_size'));
|
||||
|
||||
$data['config_file_max_size'] = ((int)$this->config->get('config_file_max_size') * 1024 * 1024);
|
||||
|
||||
// Return the target ID for the file manager to set the value
|
||||
if (isset($this->request->get['target'])) {
|
||||
$data['target'] = $this->request->get['target'];
|
||||
} else {
|
||||
$data['target'] = '';
|
||||
}
|
||||
|
||||
// Return the thumbnail for the file manager to show a thumbnail
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$data['thumb'] = $this->request->get['thumb'];
|
||||
} else {
|
||||
$data['thumb'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$data['ckeditor'] = $this->request->get['ckeditor'];
|
||||
} else {
|
||||
$data['ckeditor'] = '';
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->response->setOutput($this->load->view('common/filemanager', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$base = DIR_IMAGE . 'catalog/';
|
||||
|
||||
// Make sure we have the correct directory
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$directory = $base . html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8') . '/';
|
||||
} else {
|
||||
$directory = $base;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$filter_name = basename(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$filter_name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$allowed = [
|
||||
'.ico',
|
||||
'.jpg',
|
||||
'.jpeg',
|
||||
'.png',
|
||||
'.gif',
|
||||
'.webp',
|
||||
'.JPG',
|
||||
'.JPEG',
|
||||
'.PNG',
|
||||
'.GIF'
|
||||
];
|
||||
|
||||
$data['directories'] = [];
|
||||
$data['images'] = [];
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
// Get directories and files
|
||||
$paths = array_merge(
|
||||
glob($directory . $filter_name . '*', GLOB_ONLYDIR),
|
||||
glob($directory . $filter_name . '*{' . implode(',', $allowed) . '}', GLOB_BRACE)
|
||||
);
|
||||
|
||||
$total = count($paths);
|
||||
$limit = 16;
|
||||
$start = ($page - 1) * $limit;
|
||||
|
||||
if ($paths) {
|
||||
// Split the array based on current page number and max number of items per page of 10
|
||||
foreach (array_slice($paths, $start, $limit) as $path) {
|
||||
$path = str_replace('\\', '/', realpath($path));
|
||||
|
||||
if (substr($path, 0, strlen($path)) == $path) {
|
||||
$name = basename($path);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['target'])) {
|
||||
$url .= '&target=' . $this->request->get['target'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$url .= '&thumb=' . $this->request->get['thumb'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$url .= '&ckeditor=' . $this->request->get['ckeditor'];
|
||||
}
|
||||
|
||||
if (is_dir($path)) {
|
||||
$data['directories'][] = [
|
||||
'name' => $name,
|
||||
'path' => oc_substr($path, oc_strlen($base)) . '/',
|
||||
'href' => $this->url->link('common/filemanager.list', 'user_token=' . $this->session->data['user_token'] . '&directory=' . urlencode(oc_substr($path, oc_strlen($base))) . $url)
|
||||
];
|
||||
}
|
||||
|
||||
if (is_file($path) && in_array(substr($path, strrpos($path, '.')), $allowed)) {
|
||||
$data['images'][] = [
|
||||
'name' => $name,
|
||||
'path' => oc_substr($path, oc_strlen($base)),
|
||||
'href' => HTTP_CATALOG . 'image/catalog/' . oc_substr($path, oc_strlen($base)),
|
||||
'thumb' => $this->model_tool_image->resize(oc_substr($path, oc_strlen(DIR_IMAGE)), 136, 136)
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$data['directory'] = urldecode($this->request->get['directory']);
|
||||
} else {
|
||||
$data['directory'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$data['filter_name'] = $this->request->get['filter_name'];
|
||||
} else {
|
||||
$data['filter_name'] = '';
|
||||
}
|
||||
|
||||
// Parent
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$pos = strrpos($this->request->get['directory'], '/');
|
||||
|
||||
if ($pos) {
|
||||
$url .= '&directory=' . urlencode(substr($this->request->get['directory'], 0, $pos));
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->get['target'])) {
|
||||
$url .= '&target=' . $this->request->get['target'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$url .= '&thumb=' . $this->request->get['thumb'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$url .= '&ckeditor=' . $this->request->get['ckeditor'];
|
||||
}
|
||||
|
||||
$data['parent'] = $this->url->link('common/filemanager.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
// Refresh
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$url .= '&directory=' . urlencode(html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['target'])) {
|
||||
$url .= '&target=' . $this->request->get['target'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$url .= '&thumb=' . $this->request->get['thumb'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$url .= '&ckeditor=' . $this->request->get['ckeditor'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['refresh'] = $this->url->link('common/filemanager.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$url .= '&directory=' . urlencode(html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['target'])) {
|
||||
$url .= '&target=' . $this->request->get['target'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['thumb'])) {
|
||||
$url .= '&thumb=' . $this->request->get['thumb'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['ckeditor'])) {
|
||||
$url .= '&ckeditor=' . $this->request->get['ckeditor'];
|
||||
}
|
||||
|
||||
// Get total number of files and directories
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('common/filemanager.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$this->response->setOutput($this->load->view('common/filemanager_list', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function upload(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$json = [];
|
||||
|
||||
$base = DIR_IMAGE . 'catalog/';
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'common/filemanager')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
// Make sure we have the correct directory
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$directory = $base . html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8') . '/';
|
||||
} else {
|
||||
$directory = $base;
|
||||
}
|
||||
|
||||
// Check it's a directory
|
||||
if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)) . '/', 0, strlen($base)) != $base) {
|
||||
$json['error'] = $this->language->get('error_directory');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Check if multiple files are uploaded or just one
|
||||
$files = [];
|
||||
|
||||
if (!empty($this->request->files['file']['name']) && is_array($this->request->files['file']['name'])) {
|
||||
foreach (array_keys($this->request->files['file']['name']) as $key) {
|
||||
$files[] = [
|
||||
'name' => $this->request->files['file']['name'][$key],
|
||||
'type' => $this->request->files['file']['type'][$key],
|
||||
'tmp_name' => $this->request->files['file']['tmp_name'][$key],
|
||||
'error' => $this->request->files['file']['error'][$key],
|
||||
'size' => $this->request->files['file']['size'][$key]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file['tmp_name'])) {
|
||||
// Sanitize the filename
|
||||
$filename = preg_replace('[/\\?%*:|"<>]', '', basename(html_entity_decode($file['name'], ENT_QUOTES, 'UTF-8')));
|
||||
|
||||
// Validate the filename length
|
||||
if ((oc_strlen($filename) < 4) || (oc_strlen($filename) > 255)) {
|
||||
$json['error'] = $this->language->get('error_filename');
|
||||
}
|
||||
|
||||
// Allowed file extension types
|
||||
$allowed = [
|
||||
'ico',
|
||||
'jpg',
|
||||
'jpeg',
|
||||
'png',
|
||||
'gif',
|
||||
'webp',
|
||||
'JPG',
|
||||
'JPEG',
|
||||
'PNG',
|
||||
'GIF'
|
||||
];
|
||||
|
||||
if (!in_array(substr($filename, strrpos($filename, '.') + 1), $allowed)) {
|
||||
$json['error'] = $this->language->get('error_file_type');
|
||||
}
|
||||
|
||||
// Allowed file mime types
|
||||
$allowed = [
|
||||
'image/x-icon',
|
||||
'image/jpeg',
|
||||
'image/pjpeg',
|
||||
'image/png',
|
||||
'image/x-png',
|
||||
'image/gif',
|
||||
'image/webp'
|
||||
];
|
||||
|
||||
if (!in_array($file['type'], $allowed)) {
|
||||
$json['error'] = $this->language->get('error_file_type');
|
||||
}
|
||||
|
||||
// Return any upload error
|
||||
if ($file['error'] != UPLOAD_ERR_OK) {
|
||||
$json['error'] = $this->language->get('error_upload_' . $file['error']);
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_upload');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
move_uploaded_file($file['tmp_name'], $directory . $filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$json['success'] = $this->language->get('text_uploaded');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function folder(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$json = [];
|
||||
|
||||
$base = DIR_IMAGE . 'catalog/';
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'common/filemanager')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
// Make sure we have the correct directory
|
||||
if (isset($this->request->get['directory'])) {
|
||||
$directory = $base . html_entity_decode($this->request->get['directory'], ENT_QUOTES, 'UTF-8') . '/';
|
||||
} else {
|
||||
$directory = $base;
|
||||
}
|
||||
|
||||
// Check its a directory
|
||||
if (!is_dir($directory) || substr(str_replace('\\', '/', realpath($directory)) . '/', 0, strlen($base)) != $base) {
|
||||
$json['error'] = $this->language->get('error_directory');
|
||||
}
|
||||
|
||||
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
|
||||
// Sanitize the folder name
|
||||
$folder = preg_replace('[/\\?%*&:|"<>]', '', basename(html_entity_decode($this->request->post['folder'], ENT_QUOTES, 'UTF-8')));
|
||||
|
||||
// Validate the filename length
|
||||
if ((oc_strlen($folder) < 3) || (oc_strlen($folder) > 128)) {
|
||||
$json['error'] = $this->language->get('error_folder');
|
||||
}
|
||||
|
||||
// Check if directory already exists or not
|
||||
if (is_dir($directory . $folder)) {
|
||||
$json['error'] = $this->language->get('error_exists');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
mkdir($directory . '/' . $folder, 0777);
|
||||
|
||||
chmod($directory . '/' . $folder, 0777);
|
||||
|
||||
@touch($directory . '/' . $folder . '/' . 'index.html');
|
||||
|
||||
$json['success'] = $this->language->get('text_directory');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('common/filemanager');
|
||||
|
||||
$json = [];
|
||||
|
||||
$base = DIR_IMAGE . 'catalog/';
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'common/filemanager')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (isset($this->request->post['path'])) {
|
||||
$paths = $this->request->post['path'];
|
||||
} else {
|
||||
$paths = [];
|
||||
}
|
||||
|
||||
// Loop through each path to run validations
|
||||
foreach ($paths as $path) {
|
||||
// Convert any html encoded characters.
|
||||
$path = html_entity_decode($path, ENT_QUOTES, 'UTF-8');
|
||||
|
||||
// Check path exists
|
||||
if (($path == $base) || (substr(str_replace('\\', '/', realpath($base . $path)) . '/', 0, strlen($base)) != $base)) {
|
||||
$json['error'] = $this->language->get('error_delete');
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Loop through each path
|
||||
foreach ($paths as $path) {
|
||||
$path = rtrim($base . html_entity_decode($path, ENT_QUOTES, 'UTF-8'), '/');
|
||||
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$path];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
if (is_dir($next)) {
|
||||
foreach (glob(trim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
$directory[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $next;
|
||||
}
|
||||
|
||||
// Reverse sort the file array
|
||||
rsort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
// If file just delete
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// If directory use the remove directory function
|
||||
if (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_delete');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
25
admininistrator/controller/common/footer.php
Normal file
25
admininistrator/controller/common/footer.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Footer
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Footer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('common/footer');
|
||||
|
||||
if ($this->user->isLogged() && isset($this->request->get['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) {
|
||||
$data['text_version'] = sprintf($this->language->get('text_version'), VERSION);
|
||||
} else {
|
||||
$data['text_version'] = '';
|
||||
}
|
||||
|
||||
$data['bootstrap'] = 'view/javascript/bootstrap/js/bootstrap.bundle.min.js';
|
||||
|
||||
return $this->load->view('common/footer', $data);
|
||||
}
|
||||
}
|
214
admininistrator/controller/common/forgotten.php
Normal file
214
admininistrator/controller/common/forgotten.php
Normal file
@ -0,0 +1,214 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Forgotten
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Forgotten extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/forgotten');
|
||||
|
||||
if ($this->user->isLogged() || !$this->config->get('config_mail_engine')) {
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard')
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('common/forgotten')
|
||||
];
|
||||
|
||||
$data['confirm'] = $this->url->link('common/forgotten.confirm');
|
||||
$data['back'] = $this->url->link('common/login');
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/forgotten', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function confirm(): void {
|
||||
$this->load->language('common/forgotten');
|
||||
|
||||
$json = [];
|
||||
|
||||
// Stop any undefined index messages.
|
||||
if ($this->user->isLogged() || !$this->config->get('config_mail_engine')) {
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
$keys = ['email'];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUserByEmail($this->request->post['email']);
|
||||
|
||||
if (!$user_info) {
|
||||
$json['error'] = $this->language->get('error_email');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->model_user_user->editCode($this->request->post['email'], oc_token(40));
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function reset(): void {
|
||||
$this->load->language('common/forgotten');
|
||||
|
||||
if (isset($this->request->get['email'])) {
|
||||
$email = (string)$this->request->get['email'];
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = (string)$this->request->get['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if ($this->user->isLogged() || !$this->config->get('config_mail_engine')) {
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUserByEmail($email);
|
||||
|
||||
if (!$user_info || !$user_info['code'] || $user_info['code'] !== $code) {
|
||||
$this->model_user_user->editCode($email, '');
|
||||
|
||||
$this->session->data['error'] = $this->language->get('error_code');
|
||||
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_reset'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard')
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('common/forgotten.reset')
|
||||
];
|
||||
|
||||
$this->session->data['reset_token'] = substr(bin2hex(openssl_random_pseudo_bytes(26)), 0, 26);
|
||||
|
||||
$data['reset'] = $this->url->link('common/forgotten.password', 'email=' . urlencode($email) . '&code=' . $code . '&reset_token=' . $this->session->data['reset_token']);
|
||||
$data['back'] = $this->url->link('common/login');
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/forgotten_reset', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function password(): void {
|
||||
$this->load->language('common/forgotten');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['email'])) {
|
||||
$email = (string)$this->request->get['email'];
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = (string)$this->request->get['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
$keys = [
|
||||
'password',
|
||||
'confirm'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->request->get['reset_token']) || !isset($this->session->data['reset_token']) || ($this->session->data['reset_token'] != $this->request->get['reset_token'])) {
|
||||
$this->session->data['error'] = $this->language->get('error_session');
|
||||
|
||||
$json['redirect'] = $this->url->link('account/forgotten', true);
|
||||
}
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUserByEmail($email);
|
||||
|
||||
if (!$user_info || !$user_info['code'] || $user_info['code'] !== $code) {
|
||||
$this->model_user_user->editCode($email, '');
|
||||
|
||||
$this->session->data['error'] = $this->language->get('error_code');
|
||||
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if ((oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (oc_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) {
|
||||
$json['error']['password'] = $this->language->get('error_password');
|
||||
}
|
||||
|
||||
if ($this->request->post['confirm'] != $this->request->post['password']) {
|
||||
$json['error']['confirm'] = $this->language->get('error_confirm');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->model_user_user->editPassword($user_info['user_id'], $this->request->post['password']);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_reset');
|
||||
|
||||
unset($this->session->data['reset_token']);
|
||||
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
117
admininistrator/controller/common/header.php
Normal file
117
admininistrator/controller/common/header.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Header
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Header extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$data['lang'] = $this->language->get('code');
|
||||
$data['direction'] = $this->language->get('direction');
|
||||
|
||||
$data['title'] = $this->document->getTitle();
|
||||
$data['base'] = HTTP_SERVER;
|
||||
$data['description'] = $this->document->getDescription();
|
||||
$data['keywords'] = $this->document->getKeywords();
|
||||
|
||||
// Hard coding css so they can be replaced via the event's system.
|
||||
$data['bootstrap'] = 'view/stylesheet/bootstrap.css';
|
||||
$data['icons'] = 'view/stylesheet/fonts/fontawesome/css/all.min.css';
|
||||
$data['stylesheet'] = 'view/stylesheet/stylesheet.css';
|
||||
|
||||
// Hard coding scripts so they can be replaced via the event's system.
|
||||
$data['jquery'] = 'view/javascript/jquery/jquery-3.7.1.min.js';
|
||||
|
||||
$data['links'] = $this->document->getLinks();
|
||||
$data['styles'] = $this->document->getStyles();
|
||||
$data['scripts'] = $this->document->getScripts();
|
||||
|
||||
$this->load->language('common/header');
|
||||
|
||||
if (!isset($this->request->get['user_token']) || !isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token'])) {
|
||||
$data['logged'] = false;
|
||||
|
||||
$data['home'] = $this->url->link('common/login');
|
||||
} else {
|
||||
$data['logged'] = true;
|
||||
|
||||
$data['home'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['language'] = $this->load->controller('common/language');
|
||||
|
||||
// Notifications
|
||||
$filter_data = [
|
||||
'start' => 0,
|
||||
'limit' => 5
|
||||
];
|
||||
|
||||
$data['notifications'] = [];
|
||||
|
||||
$this->load->model('tool/notification');
|
||||
|
||||
$results = $this->model_tool_notification->getNotifications($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['notifications'][] = [
|
||||
'title' => $result['title'],
|
||||
'href' => $this->url->link('tool/notification.info', 'user_token=' . $this->session->data['user_token'] . '¬ification_id=' . $result['notification_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$data['notification_all'] = $this->url->link('tool/notification', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['notification_total'] = $this->model_tool_notification->getTotalNotifications(['filter_status' => 0]);
|
||||
|
||||
$data['profile'] = $this->url->link('user/profile', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['image'] = $this->model_tool_image->resize('profile.png', 45, 45);
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$user_info = $this->model_user_user->getUser($this->user->getId());
|
||||
|
||||
if ($user_info) {
|
||||
$data['firstname'] = $user_info['firstname'];
|
||||
$data['lastname'] = $user_info['lastname'];
|
||||
$data['username'] = $user_info['username'];
|
||||
$data['user_group'] = $user_info['user_group'];
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($user_info['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['image'] = $this->model_tool_image->resize(html_entity_decode($user_info['image'], ENT_QUOTES, 'UTF-8'), 45, 45);
|
||||
}
|
||||
} else {
|
||||
$data['firstname'] = '';
|
||||
$data['lastname'] = '';
|
||||
$data['user_group'] = '';
|
||||
}
|
||||
|
||||
// Stores
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'name' => $this->config->get('config_name'),
|
||||
'href' => HTTP_CATALOG
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$results = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['stores'][] = [
|
||||
'name' => $result['name'],
|
||||
'href' => $result['url']
|
||||
];
|
||||
}
|
||||
|
||||
$data['logout'] = $this->url->link('common/logout', 'user_token=' . $this->session->data['user_token']);
|
||||
}
|
||||
|
||||
return $this->load->view('common/header', $data);
|
||||
}
|
||||
}
|
98
admininistrator/controller/common/language.php
Normal file
98
admininistrator/controller/common/language.php
Normal file
@ -0,0 +1,98 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$data['languages'] = [];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$results = $this->model_localisation_language->getLanguages();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['languages'][] = [
|
||||
'name' => $result['name'],
|
||||
'code' => $result['code'],
|
||||
'image' => $result['image']
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->request->cookie['language'])) {
|
||||
$data['code'] = $this->request->cookie['language'];
|
||||
} else {
|
||||
$data['code'] = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Redirect
|
||||
$url_data = $this->request->get;
|
||||
|
||||
if (isset($url_data['route'])) {
|
||||
$route = $url_data['route'];
|
||||
} else {
|
||||
$route = 'common/dashboard';
|
||||
}
|
||||
|
||||
unset($url_data['route']);
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($url_data) {
|
||||
$url .= '&' . urldecode(http_build_query($url_data));
|
||||
}
|
||||
|
||||
$data['redirect'] = $this->url->link($route, $url);
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
return $this->load->view('common/language', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('common/language');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['code'])) {
|
||||
$code = $this->request->post['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['redirect'])) {
|
||||
$redirect = htmlspecialchars_decode($this->request->post['redirect'], ENT_COMPAT);
|
||||
} else {
|
||||
$redirect = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguageByCode($code);
|
||||
|
||||
if (!$language_info) {
|
||||
$json['error'] = $this->language->get('error_language');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
setcookie('language', $code, time() + 60 * 60 * 24 * 365 * 10);
|
||||
|
||||
if ($redirect && substr($redirect, 0, strlen($this->config->get('config_url'))) == $this->config->get('config_url')) {
|
||||
$json['redirect'] = $redirect;
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
137
admininistrator/controller/common/login.php
Normal file
137
admininistrator/controller/common/login.php
Normal file
@ -0,0 +1,137 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Login
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Login extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('common/login');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
// Check to see if user is already logged
|
||||
if ($this->user->isLogged() && isset($this->request->get['user_token']) && isset($this->session->data['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) {
|
||||
$this->response->redirect($this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true));
|
||||
}
|
||||
|
||||
// Check to see if user is using incorrect token
|
||||
if (isset($this->request->get['user_token']) && (!isset($this->session->data['user_token']) || ($this->request->get['user_token'] != $this->session->data['user_token']))) {
|
||||
$data['error_warning'] = $this->language->get('error_token');
|
||||
} elseif (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'] = '';
|
||||
}
|
||||
|
||||
// Create a login token to prevent brute force attacks
|
||||
$this->session->data['login_token'] = oc_token(32);
|
||||
|
||||
$data['login'] = $this->url->link('common/login.login', 'login_token=' . $this->session->data['login_token'], true);
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$data['forgotten'] = $this->url->link('common/forgotten');
|
||||
} else {
|
||||
$data['forgotten'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['route']) && $this->request->get['route'] != 'common/login') {
|
||||
$args = $this->request->get;
|
||||
|
||||
$route = $args['route'];
|
||||
|
||||
unset($args['route']);
|
||||
unset($args['user_token']);
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($this->request->get) {
|
||||
$url .= http_build_query($args);
|
||||
}
|
||||
|
||||
$data['redirect'] = $this->url->link($route, $url);
|
||||
} else {
|
||||
$data['redirect'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('common/login', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function login(): void {
|
||||
$this->load->language('common/login');
|
||||
|
||||
$json = [];
|
||||
|
||||
// Stop any undefined index messages.
|
||||
$keys = [
|
||||
'username',
|
||||
'password',
|
||||
'redirect'
|
||||
];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (!isset($this->request->post[$key])) {
|
||||
$this->request->post[$key] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->user->isLogged() && isset($this->request->get['user_token']) && isset($this->session->data['user_token']) && ($this->request->get['user_token'] == $this->session->data['user_token'])) {
|
||||
$json['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
|
||||
if (!isset($this->request->get['login_token']) || !isset($this->session->data['login_token']) || $this->request->get['login_token'] != $this->session->data['login_token']) {
|
||||
$this->session->data['error'] = $this->language->get('error_login');
|
||||
|
||||
$json['redirect'] = $this->url->link('common/login', '', true);
|
||||
}
|
||||
|
||||
if (!$json && !$this->user->login($this->request->post['username'], html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$json['error'] = $this->language->get('error_login');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->session->data['user_token'] = oc_token(32);
|
||||
|
||||
// Remove login token so it cannot be used again.
|
||||
unset($this->session->data['login_token']);
|
||||
|
||||
$login_data = [
|
||||
'ip' => $this->request->server['REMOTE_ADDR'],
|
||||
'user_agent' => $this->request->server['HTTP_USER_AGENT']
|
||||
];
|
||||
|
||||
$this->load->model('user/user');
|
||||
|
||||
$this->model_user_user->addLogin($this->user->getId(), $login_data);
|
||||
|
||||
if ($this->request->post['redirect'] && (strpos($this->request->post['redirect'], HTTP_SERVER) === 0)) {
|
||||
$json['redirect'] = str_replace('&', '&', $this->request->post['redirect'] . '&user_token=' . $this->session->data['user_token']);
|
||||
} else {
|
||||
$json['redirect'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
19
admininistrator/controller/common/logout.php
Normal file
19
admininistrator/controller/common/logout.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Logout
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Logout extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->user->logout();
|
||||
|
||||
unset($this->session->data['user_token']);
|
||||
|
||||
$this->response->redirect($this->url->link('common/login', '', true));
|
||||
}
|
||||
}
|
106
admininistrator/controller/common/pagination.php
Normal file
106
admininistrator/controller/common/pagination.php
Normal file
@ -0,0 +1,106 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Pagination
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Pagination extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param array $setting
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function index(array $setting): string {
|
||||
if (isset($setting['total'])) {
|
||||
$total = $setting['total'];
|
||||
} else {
|
||||
$total = 0;
|
||||
}
|
||||
|
||||
if (isset($setting['page']) && $setting['page'] > 0) {
|
||||
$page = (int)$setting['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($setting['limit']) && (int)$setting['limit']) {
|
||||
$limit = (int)$setting['limit'];
|
||||
} else {
|
||||
$limit = 10;
|
||||
}
|
||||
|
||||
if (isset($setting['url'])) {
|
||||
$url = str_replace('%7Bpage%7D', '{page}', (string)$setting['url']);
|
||||
} else {
|
||||
$url = '';
|
||||
}
|
||||
|
||||
$num_links = 8;
|
||||
$num_pages = ceil($total / $limit);
|
||||
|
||||
if ($url && $page > 1 && $num_pages < $page) {
|
||||
$back = true;
|
||||
} else {
|
||||
$back = false;
|
||||
}
|
||||
|
||||
$data['page'] = $page;
|
||||
|
||||
if ($page > 1) {
|
||||
$data['first'] = str_replace(['&page={page}', '?page={page}', '&page={page}'], '', $url);
|
||||
|
||||
if ($page - 1 === 1) {
|
||||
$data['prev'] = str_replace(['&page={page}', '?page={page}', '&page={page}'], '', $url);
|
||||
} else {
|
||||
$data['prev'] = str_replace('{page}', $page - 1, $url);
|
||||
}
|
||||
} else {
|
||||
$data['first'] = '';
|
||||
$data['prev'] = '';
|
||||
}
|
||||
|
||||
$data['links'] = [];
|
||||
|
||||
if ($num_pages > 1) {
|
||||
if ($num_pages <= $num_links) {
|
||||
$start = 1;
|
||||
$end = $num_pages;
|
||||
} else {
|
||||
$start = $page - floor($num_links / 2);
|
||||
$end = $page + floor($num_links / 2);
|
||||
|
||||
if ($start < 1) {
|
||||
$end += abs($start) + 1;
|
||||
$start = 1;
|
||||
}
|
||||
|
||||
if ($end > $num_pages) {
|
||||
$start -= ($end - $num_pages);
|
||||
$end = $num_pages;
|
||||
}
|
||||
}
|
||||
|
||||
for ($i = $start; $i <= $end; $i++) {
|
||||
$data['links'][] = [
|
||||
'page' => $i,
|
||||
'href' => str_replace('{page}', $i, $url)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($num_pages > $page) {
|
||||
$data['next'] = str_replace('{page}', $page + 1, $url);
|
||||
$data['last'] = str_replace('{page}', $num_pages, $url);
|
||||
} else {
|
||||
$data['next'] = '';
|
||||
$data['last'] = '';
|
||||
}
|
||||
|
||||
if ($num_pages > 1 || $back) {
|
||||
return $this->load->view('common/pagination', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
455
admininistrator/controller/common/security.php
Normal file
455
admininistrator/controller/common/security.php
Normal file
@ -0,0 +1,455 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Common;
|
||||
/**
|
||||
* Class Security
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Common
|
||||
*/
|
||||
class Security extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('common/security');
|
||||
|
||||
// Check install directory exists
|
||||
if (is_dir(DIR_OPENCART . 'install/')) {
|
||||
$data['install'] = DIR_OPENCART . 'install/';
|
||||
} else {
|
||||
$data['install'] = '';
|
||||
}
|
||||
|
||||
// Check storage directory exists
|
||||
if (DIR_STORAGE == DIR_SYSTEM . 'storage/') {
|
||||
// Check install directory exists
|
||||
$data['storage'] = DIR_STORAGE;
|
||||
|
||||
$data['document_root'] = str_replace('\\', '/', realpath($this->request->server['DOCUMENT_ROOT'] . '/../')) . '/';
|
||||
|
||||
$path = '';
|
||||
|
||||
$data['paths'] = [];
|
||||
|
||||
$parts = explode('/', rtrim($data['document_root'], '/'));
|
||||
|
||||
foreach ($parts as $part) {
|
||||
$path .= $part . '/';
|
||||
|
||||
$data['paths'][] = $path;
|
||||
}
|
||||
|
||||
rsort($data['paths']);
|
||||
} else {
|
||||
$data['storage'] = '';
|
||||
}
|
||||
|
||||
// Check admin directory ia renamed
|
||||
if (DIR_APPLICATION == DIR_OPENCART . 'admin/') {
|
||||
$data['admin'] = 'admin';
|
||||
} else {
|
||||
$data['admin'] = '';
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
if ($data['install'] || $data['storage'] || $data['admin']) {
|
||||
return $this->load->view('common/security', $data);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('common/security');
|
||||
|
||||
$json = [];
|
||||
|
||||
if ($this->user->hasPermission('modify', 'common/security')) {
|
||||
if (!is_dir(DIR_OPENCART . 'install/')) {
|
||||
$json['error'] = $this->language->get('error_install');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$files = [];
|
||||
|
||||
$path = DIR_OPENCART . 'install/';
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$path];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
if (is_dir($next)) {
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
if (is_dir($file)) {
|
||||
$directory[] = $file;
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rsort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
} elseif (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($path);
|
||||
|
||||
$json['success'] = $this->language->get('text_install_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function storage(): void {
|
||||
$this->load->language('common/security');
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['name'])) {
|
||||
$name = preg_replace('[^a-zA-z0-9_]', '', basename(html_entity_decode(trim($this->request->get['name']), ENT_QUOTES, 'UTF-8')));
|
||||
} else {
|
||||
$name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$path = preg_replace('[^a-zA-z0-9_\:\/]', '', html_entity_decode(trim($this->request->get['path']), ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
$json = [];
|
||||
|
||||
if ($this->user->hasPermission('modify', 'common/security')) {
|
||||
$base_old = DIR_STORAGE;
|
||||
$base_new = $path . $name . '/';
|
||||
|
||||
if (!is_dir($base_old)) {
|
||||
$json['error'] = $this->language->get('error_storage');
|
||||
}
|
||||
|
||||
$root = str_replace('\\', '/', realpath($this->request->server['DOCUMENT_ROOT'] . '/../'));
|
||||
|
||||
if ((substr($base_new, 0, strlen($root)) != $root) || ($root == $base_new)) {
|
||||
$json['error'] = $this->language->get('error_storage');
|
||||
}
|
||||
|
||||
if (is_dir($base_new) && $page < 2) {
|
||||
$json['error'] = $this->language->get('error_storage_exists');
|
||||
}
|
||||
|
||||
if (!is_writable(DIR_OPENCART . 'config.php') || !is_writable(DIR_APPLICATION . 'config.php')) {
|
||||
$json['error'] = $this->language->get('error_writable');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$base_old];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
if (is_dir($file)) {
|
||||
$directory[] = $file;
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Create the new storage folder
|
||||
if (!is_dir($base_new)) {
|
||||
mkdir($base_new, 0777);
|
||||
}
|
||||
|
||||
// Copy the
|
||||
$total = count($files);
|
||||
$limit = 200;
|
||||
|
||||
$start = ($page - 1) * $limit;
|
||||
$end = $start > ($total - $limit) ? $total : ($start + $limit);
|
||||
|
||||
for ($i = $start; $i < $end; $i++) {
|
||||
$destination = substr($files[$i], strlen($base_old));
|
||||
|
||||
if (is_dir($base_old . $destination) && !is_dir($base_new . $destination)) {
|
||||
mkdir($base_new . $destination, 0777);
|
||||
}
|
||||
|
||||
if (is_file($base_old . $destination) && !is_file($base_new . $destination)) {
|
||||
copy($base_old . $destination, $base_new . $destination);
|
||||
}
|
||||
}
|
||||
|
||||
if ($end < $total) {
|
||||
$json['next'] = $this->url->link('common/security.storage', '&user_token=' . $this->session->data['user_token'] . '&name=' . $name . '&path=' . $path . '&page=' . ($page + 1), true);
|
||||
} else {
|
||||
// Start deleting old storage location files.
|
||||
rsort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
// If file just delete
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// If directory use the remove directory function
|
||||
if (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($base_old);
|
||||
|
||||
// Modify the config files
|
||||
$files = [
|
||||
DIR_APPLICATION . 'config.php',
|
||||
DIR_OPENCART . 'config.php'
|
||||
];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$output = '';
|
||||
|
||||
$lines = file($file);
|
||||
|
||||
foreach ($lines as $line_id => $line) {
|
||||
if (strpos($line, 'define(\'DIR_STORAGE') !== false) {
|
||||
$output .= 'define(\'DIR_STORAGE\', \'' . $base_new . '\');' . "\n";
|
||||
} else {
|
||||
$output .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
$file = fopen($file, 'w');
|
||||
|
||||
fwrite($file, $output);
|
||||
|
||||
fclose($file);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_storage_success');
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function admin(): void {
|
||||
$this->load->language('common/security');
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['name'])) {
|
||||
$name = preg_replace('[^a-zA-z0-9]', '', basename(html_entity_decode(trim((string)$this->request->get['name']), ENT_QUOTES, 'UTF-8')));
|
||||
} else {
|
||||
$name = 'admin';
|
||||
}
|
||||
|
||||
$json = [];
|
||||
|
||||
if ($this->user->hasPermission('modify', 'common/security')) {
|
||||
$base_old = DIR_OPENCART . 'admin/';
|
||||
$base_new = DIR_OPENCART . $name . '/';
|
||||
|
||||
if (!is_dir($base_old)) {
|
||||
$json['error'] = $this->language->get('error_admin');
|
||||
}
|
||||
|
||||
if (is_dir($base_new) && $page < 2) {
|
||||
$json['error'] = $this->language->get('error_admin_exists');
|
||||
}
|
||||
|
||||
if ($name == 'admin') {
|
||||
$json['error'] = $this->language->get('error_admin_name');
|
||||
}
|
||||
|
||||
if (!is_writable(DIR_OPENCART . 'config.php') || !is_writable(DIR_APPLICATION . 'config.php')) {
|
||||
$json['error'] = $this->language->get('error_writable');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// 1. // 1. We need to copy the files, as rename cannot be used on any directory, the executing script is running under
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$base_old];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
if (is_dir($file)) {
|
||||
$directory[] = $file;
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Create the new admin folder name
|
||||
if (!is_dir($base_new)) {
|
||||
mkdir($base_new, 0777);
|
||||
}
|
||||
|
||||
// 3. split the file copies into chunks.
|
||||
$total = count($files);
|
||||
$limit = 200;
|
||||
|
||||
$start = ($page - 1) * $limit;
|
||||
$end = $start > ($total - $limit) ? $total : ($start + $limit);
|
||||
|
||||
// 4. Copy the files across
|
||||
foreach (array_slice($files, $start, $end) as $file) {
|
||||
$destination = substr($file, strlen($base_old));
|
||||
|
||||
if (is_dir($base_old . $destination) && !is_dir($base_new . $destination)) {
|
||||
mkdir($base_new . $destination, 0777);
|
||||
}
|
||||
|
||||
if (is_file($base_old . $destination) && !is_file($base_new . $destination)) {
|
||||
copy($base_old . $destination, $base_new . $destination);
|
||||
}
|
||||
}
|
||||
|
||||
if (($page * $limit) <= $total) {
|
||||
$json['next'] = $this->url->link('common/security.admin', '&user_token=' . $this->session->data['user_token'] . '&name=' . $name . '&page=' . ($page + 1), true);
|
||||
} else {
|
||||
// Update the old config files
|
||||
$file = $base_new . 'config.php';
|
||||
|
||||
$output = '';
|
||||
|
||||
$lines = file($file);
|
||||
|
||||
foreach ($lines as $line_id => $line) {
|
||||
$status = true;
|
||||
|
||||
if (strpos($line, 'define(\'HTTP_SERVER') !== false) {
|
||||
$output .= 'define(\'HTTP_SERVER\', \'' . substr(HTTP_SERVER, 0, strrpos(HTTP_SERVER, '/admin/')) . '/' . $name . '/\');' . "\n";
|
||||
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if (strpos($line, 'define(\'DIR_APPLICATION') !== false) {
|
||||
$output .= 'define(\'DIR_APPLICATION\', DIR_OPENCART . \'' . $name . '/\');' . "\n";
|
||||
|
||||
$status = false;
|
||||
}
|
||||
|
||||
if ($status) {
|
||||
$output .= $line;
|
||||
}
|
||||
}
|
||||
|
||||
$file = fopen($file, 'w');
|
||||
|
||||
fwrite($file, $output);
|
||||
|
||||
fclose($file);
|
||||
|
||||
// 6. redirect to the new admin
|
||||
$json['redirect'] = str_replace('&', '&', substr(HTTP_SERVER, 0, -6) . $name . '/index.php?route=common/login');
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __destruct() {
|
||||
// Remove old admin if exists
|
||||
$path = DIR_OPENCART . 'admin/';
|
||||
|
||||
if (is_dir($path) && DIR_APPLICATION != $path) {
|
||||
// 1. We need to copy the files, as rename cannot be used on any directory, the executing script is running under
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [$path];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
if (is_dir($file)) {
|
||||
$directory[] = $file;
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. reverse file order
|
||||
rsort($files);
|
||||
|
||||
// 5. Delete the old admin directory
|
||||
foreach ($files as $file) {
|
||||
// If file just delete
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// If directory use the remove directory function
|
||||
if (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($path);
|
||||
}
|
||||
}
|
||||
}
|
438
admininistrator/controller/customer/custom_field.php
Normal file
438
admininistrator/controller/customer/custom_field.php
Normal file
@ -0,0 +1,438 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Customer;
|
||||
/**
|
||||
* Class Custom Field
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Customer
|
||||
*/
|
||||
class CustomField extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('customer/custom_field');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('customer/custom_field.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('customer/custom_field.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('customer/custom_field', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('customer/custom_field');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'cfd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('customer/custom_field.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['custom_fields'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('customer/custom_field');
|
||||
|
||||
$custom_field_total = $this->model_customer_custom_field->getTotalCustomFields();
|
||||
|
||||
$results = $this->model_customer_custom_field->getCustomFields($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$type = '';
|
||||
|
||||
switch ($result['type']) {
|
||||
case 'select':
|
||||
$type = $this->language->get('text_select');
|
||||
break;
|
||||
case 'radio':
|
||||
$type = $this->language->get('text_radio');
|
||||
break;
|
||||
case 'checkbox':
|
||||
$type = $this->language->get('text_checkbox');
|
||||
break;
|
||||
case 'input':
|
||||
$type = $this->language->get('text_input');
|
||||
break;
|
||||
case 'text':
|
||||
$type = $this->language->get('text_text');
|
||||
break;
|
||||
case 'textarea':
|
||||
$type = $this->language->get('text_textarea');
|
||||
break;
|
||||
case 'file':
|
||||
$type = $this->language->get('text_file');
|
||||
break;
|
||||
case 'date':
|
||||
$type = $this->language->get('text_date');
|
||||
break;
|
||||
case 'datetime':
|
||||
$type = $this->language->get('text_datetime');
|
||||
break;
|
||||
case 'time':
|
||||
$type = $this->language->get('text_time');
|
||||
break;
|
||||
}
|
||||
|
||||
$data['custom_fields'][] = [
|
||||
'custom_field_id' => $result['custom_field_id'],
|
||||
'name' => $result['name'],
|
||||
'location' => $this->language->get('text_' . $result['location']),
|
||||
'type' => $type,
|
||||
'status' => $result['status'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('customer/custom_field.form', 'user_token=' . $this->session->data['user_token'] . '&custom_field_id=' . $result['custom_field_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('customer/custom_field.list', 'user_token=' . $this->session->data['user_token'] . '&sort=cfd.name' . $url);
|
||||
$data['sort_location'] = $this->url->link('customer/custom_field.list', 'user_token=' . $this->session->data['user_token'] . '&sort=cf.location' . $url);
|
||||
$data['sort_type'] = $this->url->link('customer/custom_field.list', 'user_token=' . $this->session->data['user_token'] . '&sort=cf.type' . $url);
|
||||
$data['sort_status'] = $this->url->link('customer/custom_field.list', 'user_token=' . $this->session->data['user_token'] . '&sort=cf.status' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('customer/custom_field.list', 'user_token=' . $this->session->data['user_token'] . '&sort=cf.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $custom_field_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('customer/custom_field.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($custom_field_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($custom_field_total - $this->config->get('config_pagination_admin'))) ? $custom_field_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $custom_field_total, ceil($custom_field_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('customer/custom_field_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('customer/custom_field');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['custom_field_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('customer/custom_field.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('customer/custom_field', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['custom_field_id'])) {
|
||||
$this->load->model('customer/custom_field');
|
||||
|
||||
$custom_field_info = $this->model_customer_custom_field->getCustomField($this->request->get['custom_field_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['custom_field_id'])) {
|
||||
$data['custom_field_id'] = (int)$this->request->get['custom_field_id'];
|
||||
} else {
|
||||
$data['custom_field_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['custom_field_id'])) {
|
||||
$data['custom_field_description'] = $this->model_customer_custom_field->getDescriptions($this->request->get['custom_field_id']);
|
||||
} else {
|
||||
$data['custom_field_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($custom_field_info)) {
|
||||
$data['location'] = $custom_field_info['location'];
|
||||
} else {
|
||||
$data['location'] = '';
|
||||
}
|
||||
|
||||
if (!empty($custom_field_info)) {
|
||||
$data['type'] = $custom_field_info['type'];
|
||||
} else {
|
||||
$data['type'] = '';
|
||||
}
|
||||
|
||||
if (!empty($custom_field_info)) {
|
||||
$data['value'] = $custom_field_info['value'];
|
||||
} else {
|
||||
$data['value'] = '';
|
||||
}
|
||||
|
||||
if (!empty($custom_field_info)) {
|
||||
$data['validation'] = $custom_field_info['validation'];
|
||||
} else {
|
||||
$data['validation'] = '';
|
||||
}
|
||||
|
||||
if (!empty($custom_field_info)) {
|
||||
$data['status'] = $custom_field_info['status'];
|
||||
} else {
|
||||
$data['status'] = '';
|
||||
}
|
||||
|
||||
if (!empty($custom_field_info)) {
|
||||
$data['sort_order'] = $custom_field_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['custom_field_id'])) {
|
||||
$custom_field_values = $this->model_customer_custom_field->getValueDescriptions($this->request->get['custom_field_id']);
|
||||
} else {
|
||||
$custom_field_values = [];
|
||||
}
|
||||
|
||||
$data['custom_field_values'] = [];
|
||||
|
||||
foreach ($custom_field_values as $custom_field_value) {
|
||||
$data['custom_field_values'][] = [
|
||||
'custom_field_value_id' => $custom_field_value['custom_field_value_id'],
|
||||
'custom_field_value_description' => $custom_field_value['custom_field_value_description'],
|
||||
'sort_order' => $custom_field_value['sort_order']
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['custom_field_id'])) {
|
||||
$custom_field_customer_groups = $this->model_customer_custom_field->getCustomerGroups($this->request->get['custom_field_id']);
|
||||
} else {
|
||||
$custom_field_customer_groups = [];
|
||||
}
|
||||
|
||||
$data['custom_field_customer_group'] = [];
|
||||
|
||||
foreach ($custom_field_customer_groups as $custom_field_customer_group) {
|
||||
if (isset($custom_field_customer_group['customer_group_id'])) {
|
||||
$data['custom_field_customer_group'][] = $custom_field_customer_group['customer_group_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer_group');
|
||||
|
||||
$data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();
|
||||
|
||||
$data['custom_field_required'] = [];
|
||||
|
||||
foreach ($custom_field_customer_groups as $custom_field_customer_group) {
|
||||
if (isset($custom_field_customer_group['required']) && $custom_field_customer_group['required'] && isset($custom_field_customer_group['customer_group_id'])) {
|
||||
$data['custom_field_required'][] = $custom_field_customer_group['customer_group_id'];
|
||||
}
|
||||
}
|
||||
|
||||
$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('customer/custom_field_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('customer/custom_field');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/custom_field')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['custom_field_description'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['name']) < 1) || (oc_strlen($value['name']) > 128)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (($this->request->post['type'] == 'select' || $this->request->post['type'] == 'radio' || $this->request->post['type'] == 'checkbox')) {
|
||||
if (!isset($this->request->post['custom_field_value'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_type');
|
||||
}
|
||||
|
||||
if (isset($this->request->post['custom_field_value'])) {
|
||||
foreach ($this->request->post['custom_field_value'] as $custom_field_value_id => $custom_field_value) {
|
||||
foreach ($custom_field_value['custom_field_value_description'] as $language_id => $custom_field_value_description) {
|
||||
if ((oc_strlen($custom_field_value_description['name']) < 1) || (oc_strlen($custom_field_value_description['name']) > 128)) {
|
||||
$json['error']['custom_field_value_' . $custom_field_value_id . '_' . $language_id] = $this->language->get('error_custom_value');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->post['type'] == 'text' && $this->request->post['validation'] && @preg_match(html_entity_decode($this->request->post['validation'], ENT_QUOTES, 'UTF-8'), null) === false) {
|
||||
$json['error']['validation'] = $this->language->get('error_validation');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('customer/custom_field');
|
||||
|
||||
if (!$this->request->post['custom_field_id']) {
|
||||
$json['custom_field_id'] = $this->model_customer_custom_field->addCustomField($this->request->post);
|
||||
} else {
|
||||
$this->model_customer_custom_field->editCustomField($this->request->post['custom_field_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('customer/custom_field');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/custom_field')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('customer/custom_field');
|
||||
|
||||
foreach ($selected as $custom_field_id) {
|
||||
$this->model_customer_custom_field->deleteCustomField($custom_field_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
1429
admininistrator/controller/customer/customer.php
Normal file
1429
admininistrator/controller/customer/customer.php
Normal file
File diff suppressed because it is too large
Load Diff
297
admininistrator/controller/customer/customer_approval.php
Normal file
297
admininistrator/controller/customer/customer_approval.php
Normal file
@ -0,0 +1,297 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Customer;
|
||||
/**
|
||||
* Class Customer Approval
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Customer
|
||||
*/
|
||||
class CustomerApproval extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('customer/customer_approval');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('customer/customer_approval', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['approve'] = $this->url->link('customer/customer_approval.approve', 'user_token=' . $this->session->data['user_token'], true);
|
||||
$data['deny'] = $this->url->link('customer/customer_approval.deny', 'user_token=' . $this->session->data['user_token'], true);
|
||||
|
||||
$this->load->model('customer/customer_group');
|
||||
|
||||
$data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('customer/customer_approval', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('customer/customer_approval');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$filter_customer = $this->request->get['filter_customer'];
|
||||
} else {
|
||||
$filter_customer = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_email'])) {
|
||||
$filter_email = $this->request->get['filter_email'];
|
||||
} else {
|
||||
$filter_email = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer_group_id'])) {
|
||||
$filter_customer_group_id = (int)$this->request->get['filter_customer_group_id'];
|
||||
} else {
|
||||
$filter_customer_group_id = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_type'])) {
|
||||
$filter_type = $this->request->get['filter_type'];
|
||||
} else {
|
||||
$filter_type = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$filter_date_from = $this->request->get['filter_date_from'];
|
||||
} else {
|
||||
$filter_date_from = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$filter_date_to = $this->request->get['filter_date_to'];
|
||||
} else {
|
||||
$filter_date_to = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_email'])) {
|
||||
$url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer_group_id'])) {
|
||||
$url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_type'])) {
|
||||
$url .= '&filter_type=' . $this->request->get['filter_type'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('customer/customer_approval.list', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['customer_approvals'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_customer' => $filter_customer,
|
||||
'filter_email' => $filter_email,
|
||||
'filter_customer_group_id' => $filter_customer_group_id,
|
||||
'filter_type' => $filter_type,
|
||||
'filter_date_from' => $filter_date_from,
|
||||
'filter_date_to' => $filter_date_to,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('customer/customer_approval');
|
||||
|
||||
$customer_approval_total = $this->model_customer_customer_approval->getTotalCustomerApprovals($filter_data);
|
||||
|
||||
$results = $this->model_customer_customer_approval->getCustomerApprovals($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['customer_approvals'][] = [
|
||||
'customer_approval_id' => $result['customer_approval_id'],
|
||||
'customer_id' => $result['customer_id'],
|
||||
'customer' => $result['customer'],
|
||||
'email' => $result['email'],
|
||||
'customer_group' => $result['customer_group'],
|
||||
'type' => $this->language->get('text_' . $result['type']),
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'approve' => $this->url->link('customer/customer_approval.approve', 'user_token=' . $this->session->data['user_token'] . '&customer_approval_id=' . $result['customer_approval_id'], true),
|
||||
'deny' => $this->url->link('customer/customer_approval.deny', 'user_token=' . $this->session->data['user_token'] . '&customer_approval_id=' . $result['customer_approval_id'], true),
|
||||
'edit' => $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_customer'])) {
|
||||
$url .= '&filter_customer=' . urlencode(html_entity_decode($this->request->get['filter_customer'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_email'])) {
|
||||
$url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_customer_group_id'])) {
|
||||
$url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_type'])) {
|
||||
$url .= '&filter_type=' . $this->request->get['filter_type'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $customer_approval_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('customer/customer_approval.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($customer_approval_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($customer_approval_total - $this->config->get('config_pagination_admin'))) ? $customer_approval_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $customer_approval_total, ceil($customer_approval_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
return $this->load->view('customer/customer_approval_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function approve(): void {
|
||||
$this->load->language('customer/customer_approval');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/customer_approval')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('customer/customer_approval');
|
||||
|
||||
$approvals = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$approvals = $this->request->post['selected'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['customer_approval_id'])) {
|
||||
$approvals[] = (int)$this->request->get['customer_approval_id'];
|
||||
}
|
||||
|
||||
foreach ($approvals as $customer_approval_id) {
|
||||
$customer_approval_info = $this->model_customer_customer_approval->getCustomerApproval($customer_approval_id);
|
||||
|
||||
if ($customer_approval_info) {
|
||||
if ($customer_approval_info['type'] == 'customer') {
|
||||
$this->model_customer_customer_approval->approveCustomer($customer_approval_info['customer_id']);
|
||||
}
|
||||
|
||||
if ($customer_approval_info['type'] == 'affiliate') {
|
||||
$this->model_customer_customer_approval->approveAffiliate($customer_approval_info['customer_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function deny(): void {
|
||||
$this->load->language('customer/customer_approval');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/customer_approval')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('customer/customer_approval');
|
||||
|
||||
$denials = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$denials = $this->request->post['selected'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['customer_approval_id'])) {
|
||||
$denials[] = (int)$this->request->get['customer_approval_id'];
|
||||
}
|
||||
|
||||
foreach ($denials as $customer_approval_id) {
|
||||
$customer_approval_info = $this->model_customer_customer_approval->getCustomerApproval($customer_approval_id);
|
||||
|
||||
if ($customer_approval_info) {
|
||||
if ($customer_approval_info['type'] == 'customer') {
|
||||
$this->model_customer_customer_approval->denyCustomer($customer_approval_info['customer_id']);
|
||||
}
|
||||
|
||||
if ($customer_approval_info['type'] == 'affiliate') {
|
||||
$this->model_customer_customer_approval->denyAffiliate($customer_approval_info['customer_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
330
admininistrator/controller/customer/customer_group.php
Normal file
330
admininistrator/controller/customer/customer_group.php
Normal file
@ -0,0 +1,330 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Customer;
|
||||
/**
|
||||
* Class Customer Group
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Customer
|
||||
*/
|
||||
class CustomerGroup extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('customer/customer_group');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('customer/customer_group.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('customer/customer_group.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('customer/customer_group', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('customer/customer_group');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'cgd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('customer/customer_group.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['customer_groups'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('customer/customer_group');
|
||||
|
||||
$customer_group_total = $this->model_customer_customer_group->getTotalCustomerGroups();
|
||||
|
||||
$results = $this->model_customer_customer_group->getCustomerGroups($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['customer_groups'][] = [
|
||||
'customer_group_id' => $result['customer_group_id'],
|
||||
'name' => $result['name'] . (($result['customer_group_id'] == $this->config->get('config_customer_group_id')) ? $this->language->get('text_default') : ''),
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('customer/customer_group.form', 'user_token=' . $this->session->data['user_token'] . '&customer_group_id=' . $result['customer_group_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('customer/customer_group.list', 'user_token=' . $this->session->data['user_token'] . '&sort=cgd.name' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('customer/customer_group.list', 'user_token=' . $this->session->data['user_token'] . '&sort=cg.sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $customer_group_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('customer/customer_group.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($customer_group_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($customer_group_total - $this->config->get('config_pagination_admin'))) ? $customer_group_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $customer_group_total, ceil($customer_group_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('customer/customer_group_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('customer/customer_group');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['customer_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('customer/customer_group.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('customer/customer_group', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['customer_group_id'])) {
|
||||
$this->load->model('customer/customer_group');
|
||||
|
||||
$customer_group_info = $this->model_customer_customer_group->getCustomerGroup($this->request->get['customer_group_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['customer_group_id'])) {
|
||||
$data['customer_group_id'] = (int)$this->request->get['customer_group_id'];
|
||||
} else {
|
||||
$data['customer_group_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['customer_group_id'])) {
|
||||
$data['customer_group_description'] = $this->model_customer_customer_group->getDescriptions($this->request->get['customer_group_id']);
|
||||
} else {
|
||||
$data['customer_group_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($customer_group_info)) {
|
||||
$data['approval'] = $customer_group_info['approval'];
|
||||
} else {
|
||||
$data['approval'] = '';
|
||||
}
|
||||
|
||||
if (!empty($customer_group_info)) {
|
||||
$data['sort_order'] = $customer_group_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('customer/customer_group_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('customer/customer_group');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/customer_group')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['customer_group_description'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['name']) < 3) || (oc_strlen($value['name']) > 32)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('customer/customer_group');
|
||||
|
||||
if (!$this->request->post['customer_group_id']) {
|
||||
$json['customer_group_id'] = $this->model_customer_customer_group->addCustomerGroup($this->request->post);
|
||||
} else {
|
||||
$this->model_customer_customer_group->editCustomerGroup($this->request->post['customer_group_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('customer/customer_group');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/customer_group')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
foreach ($selected as $customer_group_id) {
|
||||
if ($this->config->get('config_customer_group_id') == $customer_group_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$store_total = $this->model_setting_store->getTotalStoresByCustomerGroupId($customer_group_id);
|
||||
|
||||
if ($store_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_store'), $store_total);
|
||||
}
|
||||
|
||||
$customer_total = $this->model_customer_customer->getTotalCustomersByCustomerGroupId($customer_group_id);
|
||||
|
||||
if ($customer_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_customer'), $customer_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('customer/customer_group');
|
||||
|
||||
foreach ($selected as $customer_group_id) {
|
||||
$this->model_customer_customer_group->deleteCustomerGroup($customer_group_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
336
admininistrator/controller/customer/gdpr.php
Normal file
336
admininistrator/controller/customer/gdpr.php
Normal file
@ -0,0 +1,336 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Customer;
|
||||
/**
|
||||
* Class GDPR
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Customer
|
||||
*/
|
||||
class Gdpr extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('customer/gdpr');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('customer/gdpr', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['text_info'] = sprintf($this->language->get('text_info'), $this->config->get('config_gdpr_limit'));
|
||||
|
||||
$data['approve'] = $this->url->link('customer/gdpr.approve', 'user_token=' . $this->session->data['user_token'], true);
|
||||
$data['deny'] = $this->url->link('customer/gdpr.deny', 'user_token=' . $this->session->data['user_token'], true);
|
||||
$data['delete'] = $this->url->link('customer/gdpr.delete', 'user_token=' . $this->session->data['user_token'], true);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('customer/gdpr', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('customer/gdpr');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('customer/gdpr');
|
||||
|
||||
if (isset($this->request->get['filter_email'])) {
|
||||
$filter_email = $this->request->get['filter_email'];
|
||||
} else {
|
||||
$filter_email = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_action'])) {
|
||||
$filter_action = $this->request->get['filter_action'];
|
||||
} else {
|
||||
$filter_action = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$filter_status = $this->request->get['filter_status'];
|
||||
} else {
|
||||
$filter_status = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$filter_date_from = $this->request->get['filter_date_from'];
|
||||
} else {
|
||||
$filter_date_from = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$filter_date_to = $this->request->get['filter_date_to'];
|
||||
} else {
|
||||
$filter_date_to = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_email'])) {
|
||||
$url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_action'])) {
|
||||
$url .= '&filter_action=' . $this->request->get['filter_action'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('customer/gdpr.list', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['gdprs'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_email' => $filter_email,
|
||||
'filter_action' => $filter_action,
|
||||
'filter_status' => $filter_status,
|
||||
'filter_date_from' => $filter_date_from,
|
||||
'filter_date_to' => $filter_date_to,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('customer/gdpr');
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$gdpr_total = $this->model_customer_gdpr->getTotalGdprs($filter_data);
|
||||
|
||||
$results = $this->model_customer_gdpr->getGdprs($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$customer_info = $this->model_customer_customer->getCustomerByEmail($result['email']);
|
||||
|
||||
if ($customer_info) {
|
||||
$edit = $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_info['customer_id'], true);
|
||||
} else {
|
||||
$edit = '';
|
||||
}
|
||||
|
||||
$data['gdprs'][] = [
|
||||
'gdpr_id' => $result['gdpr_id'],
|
||||
'email' => $result['email'],
|
||||
'action' => $this->language->get('text_' . $result['action']),
|
||||
'status' => $result['status'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'approve' => $this->url->link('customer/gdpr.approve', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true),
|
||||
'deny' => $this->url->link('customer/gdpr.deny', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true),
|
||||
'edit' => $edit,
|
||||
'delete' => $this->url->link('customer/gdpr.delete', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_email'])) {
|
||||
$url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_action'])) {
|
||||
$url .= '&filter_action=' . $this->request->get['filter_action'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $gdpr_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('customer/gdpr.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($gdpr_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($gdpr_total - $this->config->get('config_pagination_admin'))) ? $gdpr_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $gdpr_total, ceil($gdpr_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
return $this->load->view('customer/gdpr_list', $data);
|
||||
}
|
||||
|
||||
/*
|
||||
* Action Statuses
|
||||
*
|
||||
* EXPORT
|
||||
*
|
||||
* unverified = 0
|
||||
* pending = 1
|
||||
* complete = 3
|
||||
*
|
||||
* REMOVE
|
||||
*
|
||||
* unverified = 0
|
||||
* pending = 1
|
||||
* processing = 2
|
||||
* delete = 3
|
||||
*
|
||||
* DENY
|
||||
*
|
||||
* unverified = 0
|
||||
* pending = 1
|
||||
* processing = 2
|
||||
* denied = -1
|
||||
*/
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function approve(): void {
|
||||
$this->load->language('customer/gdpr');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$gdprs = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$gdprs = $this->request->post['selected'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['gdpr_id'])) {
|
||||
$gdprs[] = (int)$this->request->get['gdpr_id'];
|
||||
}
|
||||
|
||||
$this->load->model('customer/gdpr');
|
||||
|
||||
foreach ($gdprs as $gdpr_id) {
|
||||
$gdpr_info = $this->model_customer_gdpr->getGdpr($gdpr_id);
|
||||
|
||||
if ($gdpr_info) {
|
||||
// If we remove we want to change the status to processing
|
||||
// to give time for store owners to process orders and refunds.
|
||||
if ($gdpr_info['action'] == 'export') {
|
||||
$this->model_customer_gdpr->editStatus($gdpr_id, 3);
|
||||
} else {
|
||||
$this->model_customer_gdpr->editStatus($gdpr_id, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function deny(): void {
|
||||
$this->load->language('customer/gdpr');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$gdprs = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$gdprs = $this->request->post['selected'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['gdpr_id'])) {
|
||||
$gdprs[] = (int)$this->request->get['gdpr_id'];
|
||||
}
|
||||
|
||||
$this->load->model('customer/gdpr');
|
||||
|
||||
foreach ($gdprs as $gdpr_id) {
|
||||
$this->model_customer_gdpr->editStatus($gdpr_id, -1);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('customer/gdpr');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$gdprs = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$gdprs = $this->request->post['selected'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['gdpr_id'])) {
|
||||
$gdprs[] = (int)$this->request->get['gdpr_id'];
|
||||
}
|
||||
|
||||
$this->load->model('customer/gdpr');
|
||||
|
||||
foreach ($gdprs as $gdpr_id) {
|
||||
$this->model_customer_gdpr->deleteGdpr($gdpr_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
344
admininistrator/controller/design/banner.php
Normal file
344
admininistrator/controller/design/banner.php
Normal file
@ -0,0 +1,344 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Design;
|
||||
/**
|
||||
* Class Banner
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Design
|
||||
*/
|
||||
class Banner extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('design/banner');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('design/banner.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('design/banner.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('design/banner', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('design/banner');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('design/banner.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['banners'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('design/banner');
|
||||
|
||||
$banner_total = $this->model_design_banner->getTotalBanners();
|
||||
|
||||
$results = $this->model_design_banner->getBanners($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['banners'][] = [
|
||||
'banner_id' => $result['banner_id'],
|
||||
'name' => $result['name'],
|
||||
'status' => $result['status'],
|
||||
'edit' => $this->url->link('design/banner.form', 'user_token=' . $this->session->data['user_token'] . '&banner_id=' . $result['banner_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('design/banner.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $banner_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('design/banner.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($banner_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($banner_total - $this->config->get('config_pagination_admin'))) ? $banner_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $banner_total, ceil($banner_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('design/banner_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('design/banner');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['banner_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('design/banner.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('design/banner', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['banner_id'])) {
|
||||
$this->load->model('design/banner');
|
||||
|
||||
$banner_info = $this->model_design_banner->getBanner($this->request->get['banner_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['banner_id'])) {
|
||||
$data['banner_id'] = (int)$this->request->get['banner_id'];
|
||||
} else {
|
||||
$data['banner_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($banner_info)) {
|
||||
$data['name'] = $banner_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($banner_info)) {
|
||||
$data['status'] = $banner_info['status'];
|
||||
} else {
|
||||
$data['status'] = true;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (!empty($banner_info)) {
|
||||
$banner_images = $this->model_design_banner->getImages($this->request->get['banner_id']);
|
||||
} else {
|
||||
$banner_images = [];
|
||||
}
|
||||
|
||||
$data['banner_images'] = [];
|
||||
|
||||
foreach ($banner_images as $language_id => $banner_image) {
|
||||
foreach ($banner_image as $value) {
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($value['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$image = $value['image'];
|
||||
$thumb = $value['image'];
|
||||
} else {
|
||||
$image = '';
|
||||
$thumb = 'no_image.png';
|
||||
}
|
||||
|
||||
$data['banner_images'][$language_id][] = [
|
||||
'title' => $value['title'],
|
||||
'link' => $value['link'],
|
||||
'image' => $image,
|
||||
'thumb' => $this->model_tool_image->resize(html_entity_decode($thumb, ENT_QUOTES, 'UTF-8'), 100, 100),
|
||||
'sort_order' => $value['sort_order']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
$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('design/banner_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('design/banner');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'design/banner')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if (isset($this->request->post['banner_image'])) {
|
||||
foreach ($this->request->post['banner_image'] as $language_id => $banner_image) {
|
||||
foreach ($banner_image as $key => $value) {
|
||||
if ((oc_strlen(trim($value['title'])) < 2) || (oc_strlen($value['title']) > 64)) {
|
||||
$json['error']['image_' . $language_id . '_' . $key . '_title'] = $this->language->get('error_title');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/banner');
|
||||
|
||||
if (!$this->request->post['banner_id']) {
|
||||
$json['banner_id'] = $this->model_design_banner->addBanner($this->request->post);
|
||||
} else {
|
||||
$this->model_design_banner->editBanner($this->request->post['banner_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('design/banner');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'design/banner')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/banner');
|
||||
|
||||
foreach ($selected as $banner_id) {
|
||||
$this->model_design_banner->deleteBanner($banner_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
410
admininistrator/controller/design/layout.php
Normal file
410
admininistrator/controller/design/layout.php
Normal file
@ -0,0 +1,410 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Design;
|
||||
/**
|
||||
* Class Layout
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Design
|
||||
*/
|
||||
class Layout extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('design/layout');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('design/layout.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('design/layout.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('design/layout', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('design/layout');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('design/layout.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['layouts'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$layout_total = $this->model_design_layout->getTotalLayouts();
|
||||
|
||||
$results = $this->model_design_layout->getLayouts($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['layouts'][] = [
|
||||
'layout_id' => $result['layout_id'],
|
||||
'name' => $result['name'],
|
||||
'edit' => $this->url->link('design/layout.form', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $result['layout_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('design/layout.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $layout_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('design/layout.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($layout_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($layout_total - $this->config->get('config_pagination_admin'))) ? $layout_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $layout_total, ceil($layout_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('design/layout_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('design/layout');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['layout_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('design/layout.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['layout_id'])) {
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$layout_info = $this->model_design_layout->getLayout($this->request->get['layout_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['layout_id'])) {
|
||||
$data['layout_id'] = (int)$this->request->get['layout_id'];
|
||||
} else {
|
||||
$data['layout_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($layout_info)) {
|
||||
$data['name'] = $layout_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$data['stores'] = $this->model_setting_store->getStores();
|
||||
|
||||
if (isset($this->request->get['layout_id'])) {
|
||||
$data['layout_routes'] = $this->model_design_layout->getRoutes($this->request->get['layout_id']);
|
||||
} else {
|
||||
$data['layout_routes'] = [];
|
||||
}
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->load->model('setting/module');
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
// Get a list of installed modules
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('module');
|
||||
|
||||
// Add all the modules which have multiple settings for each module
|
||||
foreach ($extensions as $extension) {
|
||||
$this->load->language('extension/' . $extension['extension'] . '/module/' . $extension['code'], $extension['code']);
|
||||
|
||||
$module_data = [];
|
||||
|
||||
$modules = $this->model_setting_module->getModulesByCode($extension['extension'] .'.' . $extension['code']);
|
||||
|
||||
foreach ($modules as $module) {
|
||||
$module_data[] = [
|
||||
'name' => strip_tags($module['name']),
|
||||
'code' => $extension['extension'] . '.' . $extension['code'] . '.' . $module['module_id']
|
||||
];
|
||||
}
|
||||
|
||||
if ($this->config->has('module_' . $extension['code'] . '_status') || $module_data) {
|
||||
$data['extensions'][] = [
|
||||
'name' => strip_tags($this->language->get($extension['code'] . '_heading_title')),
|
||||
'code' => $extension['extension'] . '.' . $extension['code'],
|
||||
'module' => $module_data
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// Modules layout
|
||||
if (!empty($layout_info)) {
|
||||
$layout_modules = $this->model_design_layout->getModules($this->request->get['layout_id']);
|
||||
} else {
|
||||
$layout_modules = [];
|
||||
}
|
||||
|
||||
$data['layout_modules'] = [];
|
||||
|
||||
// Add all the modules which have multiple settings for each module
|
||||
foreach ($layout_modules as $layout_module) {
|
||||
$part = explode('.', $layout_module['code']);
|
||||
|
||||
if (!isset($part[2])) {
|
||||
$data['layout_modules'][] = [
|
||||
'code' => $layout_module['code'],
|
||||
'position' => $layout_module['position'],
|
||||
'sort_order' => $layout_module['sort_order'],
|
||||
'edit' => $this->url->link('extension/' . $part[0] . '/module/' . $part[1], 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
} else {
|
||||
$module_info = $this->model_setting_module->getModule($part[2]);
|
||||
|
||||
if ($module_info) {
|
||||
$data['layout_modules'][] = [
|
||||
'code' => $layout_module['code'],
|
||||
'position' => $layout_module['position'],
|
||||
'sort_order' => $layout_module['sort_order'],
|
||||
'edit' => $this->url->link('extension/' . $part[0] . '/module/' . $part[1], 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $part[2])
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$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('design/layout_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('design/layout');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'design/layout')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/layout');
|
||||
|
||||
if (!$this->request->post['layout_id']) {
|
||||
$json['layout_id'] = $this->model_design_layout->addLayout($this->request->post);
|
||||
} else {
|
||||
$this->model_design_layout->editLayout($this->request->post['layout_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('design/layout');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'design/layout')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('catalog/product');
|
||||
$this->load->model('catalog/category');
|
||||
$this->load->model('catalog/manufacturer');
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
foreach ($selected as $layout_id) {
|
||||
if ($this->config->get('config_layout_id') == $layout_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$store_total = $this->model_setting_store->getTotalStoresByLayoutId($layout_id);
|
||||
|
||||
if ($store_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_store'), $store_total);
|
||||
}
|
||||
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByLayoutId($layout_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
|
||||
$category_total = $this->model_catalog_category->getTotalCategoriesByLayoutId($layout_id);
|
||||
|
||||
if ($category_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_category'), $category_total);
|
||||
}
|
||||
|
||||
$manufacturer_total = $this->model_catalog_manufacturer->getTotalManufacturersByLayoutId($layout_id);
|
||||
|
||||
if ($manufacturer_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_manufacturer'), $manufacturer_total);
|
||||
}
|
||||
|
||||
$information_total = $this->model_catalog_information->getTotalInformationsByLayoutId($layout_id);
|
||||
|
||||
if ($information_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_information'), $information_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/layout');
|
||||
|
||||
foreach ($selected as $layout_id) {
|
||||
$this->model_design_layout->deleteLayout($layout_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
573
admininistrator/controller/design/seo_url.php
Normal file
573
admininistrator/controller/design/seo_url.php
Normal file
@ -0,0 +1,573 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Design;
|
||||
/**
|
||||
* Class SEO URL
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Design
|
||||
*/
|
||||
class SeoUrl extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('design/seo_url');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$filter_keyword = (string)$this->request->get['filter_keyword'];
|
||||
} else {
|
||||
$filter_keyword = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_key'])) {
|
||||
$filter_key = (string)$this->request->get['filter_key'];
|
||||
} else {
|
||||
$filter_key = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_value'])) {
|
||||
$filter_value = (string)$this->request->get['filter_value'];
|
||||
} else {
|
||||
$filter_value = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_store_id'])) {
|
||||
$filter_store_id = (int)$this->request->get['filter_store_id'];
|
||||
} else {
|
||||
$filter_store_id = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_language_id'])) {
|
||||
$filter_language_id = (int)$this->request->get['filter_language_id'];
|
||||
} else {
|
||||
$filter_language_id = 0;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_key'])) {
|
||||
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_value'])) {
|
||||
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_store_id'])) {
|
||||
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_language_id'])) {
|
||||
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . (string)$this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . (string)$this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . (int)$this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('design/seo_url.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('design/seo_url.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$data['stores'] = $this->model_setting_store->getStores();
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
$data['filter_keyword'] = $filter_keyword;
|
||||
$data['filter_key'] = $filter_key;
|
||||
$data['filter_value'] = $filter_value;
|
||||
$data['filter_store_id'] = $filter_store_id;
|
||||
$data['filter_language_id'] = $filter_language_id;
|
||||
|
||||
$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('design/seo_url', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('design/seo_url');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$filter_keyword = (string)$this->request->get['filter_keyword'];
|
||||
} else {
|
||||
$filter_keyword = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_key'])) {
|
||||
$filter_key = (string)$this->request->get['filter_key'];
|
||||
} else {
|
||||
$filter_key = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_value'])) {
|
||||
$filter_value = (string)$this->request->get['filter_value'];
|
||||
} else {
|
||||
$filter_value = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_store_id'])) {
|
||||
$filter_store_id = (int)$this->request->get['filter_store_id'];
|
||||
} else {
|
||||
$filter_store_id = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_language_id'])) {
|
||||
$filter_language_id = (int)$this->request->get['filter_language_id'];
|
||||
} else {
|
||||
$filter_language_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'key';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_key'])) {
|
||||
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_value'])) {
|
||||
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_store_id'])) {
|
||||
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_language_id'])) {
|
||||
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . (string)$this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . (string)$this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . (int)$this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['seo_urls'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_keyword' => $filter_keyword,
|
||||
'filter_key' => $filter_key,
|
||||
'filter_value' => $filter_value,
|
||||
'filter_store_id' => $filter_store_id,
|
||||
'filter_language_id' => $filter_language_id,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('design/seo_url');
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$seo_url_total = $this->model_design_seo_url->getTotalSeoUrls($filter_data);
|
||||
|
||||
$results = $this->model_design_seo_url->getSeoUrls($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$language_info = $this->model_localisation_language->getLanguage($result['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$code = $language_info['code'];
|
||||
$image = $language_info['image'];
|
||||
} else {
|
||||
$code = '';
|
||||
$image = '';
|
||||
}
|
||||
|
||||
$data['seo_urls'][] = [
|
||||
'seo_url_id' => $result['seo_url_id'],
|
||||
'keyword' => $result['keyword'],
|
||||
'image' => $image,
|
||||
'language' => $code,
|
||||
'key' => $result['key'],
|
||||
'value' => $result['value'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'store' => $result['store_id'] ? $result['store'] : $this->language->get('text_default'),
|
||||
'edit' => $this->url->link('design/seo_url.form', 'user_token=' . $this->session->data['user_token'] . '&seo_url_id=' . $result['seo_url_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_key'])) {
|
||||
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_value'])) {
|
||||
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_store_id'])) {
|
||||
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_language_id'])) {
|
||||
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
|
||||
}
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_keyword'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=keyword' . $url);
|
||||
$data['sort_key'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=key' . $url);
|
||||
$data['sort_value'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url);
|
||||
$data['sort_store'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=store' . $url);
|
||||
$data['sort_language'] = $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . '&sort=language' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_key'])) {
|
||||
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_value'])) {
|
||||
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_store_id'])) {
|
||||
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_language_id'])) {
|
||||
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . (string)$this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . (string)$this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $seo_url_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('design/seo_url.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($seo_url_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($seo_url_total - $this->config->get('config_pagination_admin'))) ? $seo_url_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $seo_url_total, ceil($seo_url_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('design/seo_url_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('design/seo_url');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['seo_url_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_keyword'])) {
|
||||
$url .= '&filter_keyword=' . urlencode(html_entity_decode((string)$this->request->get['filter_keyword'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_key'])) {
|
||||
$url .= '&filter_key=' . urlencode(html_entity_decode((string)$this->request->get['filter_key'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_value'])) {
|
||||
$url .= '&filter_value=' . urlencode(html_entity_decode((string)$this->request->get['filter_value'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_store_id'])) {
|
||||
$url .= '&filter_store_id=' . (int)$this->request->get['filter_store_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_language_id'])) {
|
||||
$url .= '&filter_language_id=' . (int)$this->request->get['filter_language_id'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . (string)$this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . (string)$this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . (int)$this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('design/seo_url.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('design/seo_url', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['seo_url_id'])) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrl($this->request->get['seo_url_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['seo_url_id'])) {
|
||||
$data['seo_url_id'] = (int)$this->request->get['seo_url_id'];
|
||||
} else {
|
||||
$data['seo_url_id'] = 0;
|
||||
}
|
||||
|
||||
$data['stores'] = [];
|
||||
|
||||
$data['stores'][] = [
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = [
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
];
|
||||
}
|
||||
|
||||
if (!empty($seo_url_info)) {
|
||||
$data['store_id'] = $seo_url_info['store_id'];
|
||||
} else {
|
||||
$data['store_id'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (!empty($seo_url_info)) {
|
||||
$data['language_id'] = $seo_url_info['language_id'];
|
||||
} else {
|
||||
$data['language_id'] = '';
|
||||
}
|
||||
|
||||
if (!empty($seo_url_info)) {
|
||||
$data['key'] = $seo_url_info['key'];
|
||||
} else {
|
||||
$data['key'] = '';
|
||||
}
|
||||
|
||||
if (!empty($seo_url_info)) {
|
||||
$data['value'] = $seo_url_info['value'];
|
||||
} else {
|
||||
$data['value'] = '';
|
||||
}
|
||||
|
||||
if (!empty($seo_url_info)) {
|
||||
$data['keyword'] = $seo_url_info['keyword'];
|
||||
} else {
|
||||
$data['keyword'] = '';
|
||||
}
|
||||
|
||||
if (!empty($seo_url_info)) {
|
||||
$data['sort_order'] = $seo_url_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('design/seo_url_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('design/seo_url');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'design/seo_url')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['key']) < 1) || (oc_strlen($this->request->post['key']) > 64)) {
|
||||
$json['error']['key'] = $this->language->get('error_key');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['value']) < 1) || (oc_strlen($this->request->post['value']) > 255)) {
|
||||
$json['error']['value'] = $this->language->get('error_value');
|
||||
}
|
||||
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
// Check if there is already a key value pair on the same store using the same language
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyValue($this->request->post['key'], $this->request->post['value'], $this->request->post['store_id'], $this->request->post['language_id']);
|
||||
|
||||
if ($seo_url_info && (!isset($this->request->post['seo_url_id']) || $seo_url_info['seo_url_id'] != (int)$this->request->post['seo_url_id'])) {
|
||||
$json['error']['value'] = $this->language->get('error_value_exists');
|
||||
}
|
||||
|
||||
// Split keywords by / so we can validate each keyword
|
||||
$keywords = explode('/', $this->request->post['keyword']);
|
||||
|
||||
foreach ($keywords as $keyword) {
|
||||
if ((oc_strlen(trim($keyword)) < 1) || (oc_strlen($keyword) > 64)) {
|
||||
$json['error']['keyword'] = $this->language->get('error_keyword');
|
||||
}
|
||||
|
||||
if (preg_match('/[^a-zA-Z0-9\/_-]|[\p{Cyrillic}]+/u', $keyword)) {
|
||||
$json['error']['keyword'] = $this->language->get('error_keyword_character');
|
||||
}
|
||||
}
|
||||
|
||||
// Check if keyword already exists and on the same store as long as the keyword matches the key / value pair
|
||||
$seo_url_info = $this->model_design_seo_url->getSeoUrlByKeyword($this->request->post['keyword'], $this->request->post['store_id']);
|
||||
|
||||
if ($seo_url_info && (($seo_url_info['key'] != $this->request->post['key']) || ($seo_url_info['value'] != $this->request->post['value']))) {
|
||||
$json['error']['keyword'] = $this->language->get('error_keyword_exists');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if (!$this->request->post['seo_url_id']) {
|
||||
$json['seo_url_id'] = $this->model_design_seo_url->addSeoUrl($this->request->post);
|
||||
} else {
|
||||
$this->model_design_seo_url->editSeoUrl($this->request->post['seo_url_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('design/seo_url');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'design/seo_url')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($selected as $seo_url_id) {
|
||||
$this->model_design_seo_url->deleteSeoUrl($seo_url_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
432
admininistrator/controller/design/theme.php
Normal file
432
admininistrator/controller/design/theme.php
Normal file
@ -0,0 +1,432 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Design;
|
||||
/**
|
||||
* Class Theme
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Design
|
||||
*/
|
||||
class Theme extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('design/theme');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/theme', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['stores'] = [];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$results = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['stores'][] = [
|
||||
'store_id' => $result['store_id'],
|
||||
'name' => $result['name']
|
||||
];
|
||||
}
|
||||
|
||||
$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('design/theme', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function history(): void {
|
||||
$this->load->language('design/theme');
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$limit = 10;
|
||||
|
||||
$data['histories'] = [];
|
||||
|
||||
$this->load->model('design/theme');
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$history_total = $this->model_design_theme->getTotalThemes();
|
||||
|
||||
$results = $this->model_design_theme->getThemes(($page - 1) * $limit, $limit);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$store_info = $this->model_setting_store->getStore($result['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store = $store_info['name'];
|
||||
} else {
|
||||
$store = '';
|
||||
}
|
||||
|
||||
$data['histories'][] = [
|
||||
'store_id' => $result['store_id'],
|
||||
'store' => ($result['store_id'] ? $store : $this->language->get('text_default')),
|
||||
'route' => $result['route'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'edit' => $this->url->link('design/theme.template', 'user_token=' . $this->session->data['user_token']),
|
||||
'delete' => $this->url->link('design/theme.delete', 'user_token=' . $this->session->data['user_token'] . '&theme_id=' . $result['theme_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $history_total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('design/theme.history', 'user_token=' . $this->session->data['user_token'] . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($history_total - $limit)) ? $history_total : ((($page - 1) * $limit) + $limit), $history_total, ceil($history_total / $limit));
|
||||
|
||||
$this->response->setOutput($this->load->view('design/theme_history', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function path(): void {
|
||||
$this->load->language('design/theme');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['store_id'])) {
|
||||
$store_id = (int)$this->request->get['store_id'];
|
||||
} else {
|
||||
$store_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$path = $this->request->get['path'];
|
||||
} else {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
// Default templates
|
||||
$json['directory'] = [];
|
||||
$json['file'] = [];
|
||||
|
||||
$directory = DIR_CATALOG . 'view/template';
|
||||
|
||||
if (substr(str_replace('\\', '/', realpath($directory . '/' . $path)), 0, strlen($directory)) == $directory) {
|
||||
// We grab the files from the default template directory
|
||||
$files = glob(rtrim(DIR_CATALOG . 'view/template/' . $path, '/') . '/*');
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_dir($file)) {
|
||||
$json['directory'][] = [
|
||||
'name' => basename($file),
|
||||
'path' => trim($path . '/' . basename($file), '/')
|
||||
];
|
||||
}
|
||||
|
||||
if (is_file($file)) {
|
||||
$json['file'][] = [
|
||||
'name' => basename($file),
|
||||
'path' => trim($path . '/' . basename($file), '/')
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$path) {
|
||||
$json['directory'][] = [
|
||||
'name' => $this->language->get('text_extension'),
|
||||
'path' => 'extension',
|
||||
];
|
||||
}
|
||||
|
||||
// Extension templates
|
||||
$json['extension'] = [];
|
||||
|
||||
// List all the extensions
|
||||
if ($path == 'extension') {
|
||||
$directories = glob(DIR_EXTENSION . '*', GLOB_ONLYDIR);
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
$json['extension']['directory'][] = [
|
||||
'name' => basename($directory),
|
||||
'path' => 'extension/' . basename($directory)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// List extension sub directories directories
|
||||
if (substr($path, 0, 10) == 'extension/') {
|
||||
$route = '';
|
||||
|
||||
$part = explode('/', $path);
|
||||
|
||||
$extension = $part[1];
|
||||
|
||||
unset($part[0]);
|
||||
unset($part[1]);
|
||||
|
||||
if (isset($part[2])) {
|
||||
$route = implode('/', $part);
|
||||
}
|
||||
|
||||
$safe = true;
|
||||
|
||||
if (substr(str_replace('\\', '/', realpath(DIR_EXTENSION . $extension)), 0, strlen(DIR_EXTENSION)) != DIR_EXTENSION) {
|
||||
$safe = false;
|
||||
}
|
||||
|
||||
$directory = DIR_EXTENSION . $extension . '/catalog/view/template';
|
||||
|
||||
if (substr(str_replace('\\', '/', realpath($directory . '/' . $route)), 0, strlen($directory)) != $directory) {
|
||||
$safe = false;
|
||||
}
|
||||
|
||||
if ($safe) {
|
||||
$files = glob(rtrim(DIR_EXTENSION . $extension . '/catalog/view/template/' . $route, '/') . '/*');
|
||||
|
||||
sort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
if (is_dir($file)) {
|
||||
$json['extension']['directory'][] = [
|
||||
'name' => basename($file),
|
||||
'path' => $path . '/' . basename($file)
|
||||
];
|
||||
}
|
||||
|
||||
if (is_file($file)) {
|
||||
$json['extension']['file'][] = [
|
||||
'name' => basename($file),
|
||||
'path' => $path . '/' . basename($file)
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($path) {
|
||||
$json['back'] = [
|
||||
'name' => $this->language->get('button_back'),
|
||||
'path' => urlencode(substr($path, 0, strrpos($path, '/'))),
|
||||
];
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function template(): void {
|
||||
$this->load->language('design/theme');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['store_id'])) {
|
||||
$store_id = (int)$this->request->get['store_id'];
|
||||
} else {
|
||||
$store_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$path = $this->request->get['path'];
|
||||
} else {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
// Default template load
|
||||
$directory = DIR_CATALOG . 'view/template';
|
||||
|
||||
if (is_file($directory . '/' . $path) && (substr(str_replace('\\', '/', realpath($directory . '/' . $path)), 0, strlen($directory)) == $directory)) {
|
||||
$json['code'] = file_get_contents(DIR_CATALOG . 'view/template/' . $path);
|
||||
}
|
||||
|
||||
// Extension template load
|
||||
if (substr($path, 0, 10) == 'extension/') {
|
||||
$part = explode('/', $path);
|
||||
|
||||
$extension = $part[1];
|
||||
|
||||
unset($part[0]);
|
||||
unset($part[1]);
|
||||
|
||||
$route = implode('/', $part);
|
||||
|
||||
$safe = true;
|
||||
|
||||
if (substr(str_replace('\\', '/', realpath(DIR_EXTENSION . $extension)), 0, strlen(DIR_EXTENSION)) != DIR_EXTENSION) {
|
||||
$safe = false;
|
||||
}
|
||||
|
||||
$directory = DIR_EXTENSION . $extension . '/catalog/view/template';
|
||||
|
||||
if (substr(str_replace('\\', '/', realpath($directory . '/' . $route)), 0, strlen($directory)) != $directory) {
|
||||
$safe = false;
|
||||
}
|
||||
|
||||
if ($safe && is_file($directory . '/' . $route)) {
|
||||
$json['code'] = file_get_contents($directory . '/' . $route);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom template load
|
||||
$this->load->model('design/theme');
|
||||
|
||||
$theme_info = $this->model_design_theme->getTheme($store_id, $path);
|
||||
|
||||
if ($theme_info) {
|
||||
$json['code'] = html_entity_decode($theme_info['code']);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('design/theme');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['store_id'])) {
|
||||
$store_id = (int)$this->request->get['store_id'];
|
||||
} else {
|
||||
$store_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$path = $this->request->get['path'];
|
||||
} else {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'design/theme')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (substr($path, -5) != '.twig') {
|
||||
$json['error'] = $this->language->get('error_twig');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/theme');
|
||||
|
||||
$pos = strpos($path, '.');
|
||||
|
||||
$this->model_design_theme->editTheme($store_id, ($pos !== false) ? substr($path, 0, $pos) : $path, $this->request->post['code']);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function reset(): void {
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['store_id'])) {
|
||||
$store_id = (int)$this->request->get['store_id'];
|
||||
} else {
|
||||
$store_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$path = $this->request->get['path'];
|
||||
} else {
|
||||
$path = '';
|
||||
}
|
||||
|
||||
$directory = DIR_CATALOG . 'view/template';
|
||||
|
||||
if (is_file($directory . '/' . $path) && (substr(str_replace('\\', '/', realpath($directory . '/' . $path)), 0, strlen($directory)) == $directory)) {
|
||||
$json['code'] = file_get_contents(DIR_CATALOG . 'view/template/' . $path);
|
||||
}
|
||||
|
||||
// Extension template load
|
||||
if (substr($path, 0, 10) == 'extension/') {
|
||||
$part = explode('/', $path);
|
||||
|
||||
$extension = $part[1];
|
||||
|
||||
unset($part[0]);
|
||||
unset($part[1]);
|
||||
|
||||
$route = implode('/', $part);
|
||||
|
||||
$safe = true;
|
||||
|
||||
if (substr(str_replace('\\', '/', realpath(DIR_EXTENSION . $extension)), 0, strlen(DIR_EXTENSION)) != DIR_EXTENSION) {
|
||||
$safe = false;
|
||||
}
|
||||
|
||||
$directory = DIR_EXTENSION . $extension . '/catalog/view/template';
|
||||
|
||||
if (substr(str_replace('\\', '/', realpath($directory . '/' . $route)), 0, strlen($directory)) != $directory) {
|
||||
$safe = false;
|
||||
}
|
||||
|
||||
if ($safe && is_file($directory . '/' . $route)) {
|
||||
$json['code'] = file_get_contents($directory . '/' . $route);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('design/theme');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['theme_id'])) {
|
||||
$theme_id = (int)$this->request->get['theme_id'];
|
||||
} else {
|
||||
$theme_id = 0;
|
||||
}
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'design/theme')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/theme');
|
||||
|
||||
$this->model_design_theme->deleteTheme($theme_id);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
459
admininistrator/controller/design/translation.php
Normal file
459
admininistrator/controller/design/translation.php
Normal file
@ -0,0 +1,459 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Design;
|
||||
/**
|
||||
* Class Translation
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Design
|
||||
*/
|
||||
class Translation extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('design/translation');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('design/translation.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('design/translation.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('design/translation', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('design/translation');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'store';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['translations'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('design/translation');
|
||||
|
||||
$translation_total = $this->model_design_translation->getTotalTranslations();
|
||||
|
||||
$results = $this->model_design_translation->getTranslations($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$language_info = $this->model_localisation_language->getLanguage($result['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$code = $language_info['code'];
|
||||
$image = $language_info['image'];
|
||||
} else {
|
||||
$code = '';
|
||||
$image = '';
|
||||
}
|
||||
|
||||
$data['translations'][] = [
|
||||
'translation_id' => $result['translation_id'],
|
||||
'store' => ($result['store_id'] ? $result['store'] : $this->language->get('text_default')),
|
||||
'route' => $result['route'],
|
||||
'image' => $image,
|
||||
'language' => $code,
|
||||
'key' => $result['key'],
|
||||
'value' => $result['value'],
|
||||
'edit' => $this->url->link('design/translation.form', 'user_token=' . $this->session->data['user_token'] . '&translation_id=' . $result['translation_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_store'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=store' . $url);
|
||||
$data['sort_language'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=language' . $url);
|
||||
$data['sort_route'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=route' . $url);
|
||||
$data['sort_key'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=key' . $url);
|
||||
$data['sort_value'] = $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url);
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $translation_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('design/translation.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($translation_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($translation_total - $this->config->get('config_pagination_admin'))) ? $translation_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $translation_total, ceil($translation_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('design/translation_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('design/translation');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['translation_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('design/translation.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('design/translation', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['translation_id'])) {
|
||||
$this->load->model('design/translation');
|
||||
|
||||
$translation_info = $this->model_design_translation->getTranslation($this->request->get['translation_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['translation_id'])) {
|
||||
$data['translation_id'] = (int)$this->request->get['translation_id'];
|
||||
} else {
|
||||
$data['translation_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$data['stores'] = $this->model_setting_store->getStores();
|
||||
|
||||
if (!empty($translation_info)) {
|
||||
$data['store_id'] = $translation_info['store_id'];
|
||||
} else {
|
||||
$data['store_id'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (!empty($translation_info)) {
|
||||
$data['language_id'] = $translation_info['language_id'];
|
||||
} else {
|
||||
$data['language_id'] = '';
|
||||
}
|
||||
|
||||
if (!empty($translation_info)) {
|
||||
$data['route'] = $translation_info['route'];
|
||||
} else {
|
||||
$data['route'] = '';
|
||||
}
|
||||
|
||||
if (!empty($translation_info)) {
|
||||
$data['key'] = $translation_info['key'];
|
||||
} else {
|
||||
$data['key'] = '';
|
||||
}
|
||||
|
||||
if (!empty($translation_info)) {
|
||||
$data['value'] = $translation_info['value'];
|
||||
} else {
|
||||
$data['value'] = '';
|
||||
}
|
||||
|
||||
$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('design/translation_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('design/translation');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'design/translation')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['key']) < 3) || (oc_strlen($this->request->post['key']) > 64)) {
|
||||
$json['error']['key'] = $this->language->get('error_key');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/translation');
|
||||
|
||||
if (!$this->request->post['translation_id']) {
|
||||
$json['translation_id'] = $this->model_design_translation->addTranslation($this->request->post);
|
||||
} else {
|
||||
$this->model_design_translation->editTranslation($this->request->post['translation_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('design/translation');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'design/translation')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('design/translation');
|
||||
|
||||
foreach ($selected as $translation_id) {
|
||||
$this->model_design_translation->deleteTranslation($translation_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function path(): void {
|
||||
$this->load->language('design/translation');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['language_id'])) {
|
||||
$language_id = (int)$this->request->get['language_id'];
|
||||
} else {
|
||||
$language_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($language_id);
|
||||
|
||||
if (!empty($language_info)) {
|
||||
$path = glob(DIR_CATALOG . 'language/' . $language_info['code'] . '/*');
|
||||
|
||||
while (count($path) != 0) {
|
||||
$next = array_shift($path);
|
||||
|
||||
foreach ((array)glob($next . '/*') as $file) {
|
||||
if (is_dir($file)) {
|
||||
$path[] = $file;
|
||||
}
|
||||
|
||||
if (substr($file, -4) == '.php') {
|
||||
$json[] = substr(substr($file, strlen(DIR_CATALOG . 'language/' . $language_info['code'] . '/')), 0, -4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$path = glob(DIR_EXTENSION . '*/catalog/language/' . $language_info['code'] . '/*');
|
||||
|
||||
while (count($path) != 0) {
|
||||
$next = array_shift($path);
|
||||
|
||||
foreach ((array)glob($next . '/*') as $file) {
|
||||
if (is_dir($file)) {
|
||||
$path[] = $file;
|
||||
}
|
||||
|
||||
if (substr($file, -4) == '.php') {
|
||||
$new_path = substr($file, strlen(DIR_EXTENSION));
|
||||
|
||||
$code = substr($new_path, 0, strpos($new_path, '/'));
|
||||
|
||||
$length = strlen(DIR_EXTENSION . $code . '/catalog/language/' . $language_info['code'] . '/');
|
||||
|
||||
$route = substr(substr($file, $length), 0, -4);
|
||||
|
||||
$json[] = 'extension/' . $code . '/' . $route;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function translation(): void {
|
||||
$this->load->language('design/translation');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['store_id'])) {
|
||||
$store_id = (int)$this->request->get['store_id'];
|
||||
} else {
|
||||
$store_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['language_id'])) {
|
||||
$language_id = (int)$this->request->get['language_id'];
|
||||
} else {
|
||||
$language_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
$route = $this->request->get['path'];
|
||||
} else {
|
||||
$route = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($language_id);
|
||||
|
||||
$part = explode('/', $route);
|
||||
|
||||
if ($part[0] != 'extension') {
|
||||
$directory = DIR_CATALOG . 'language/';
|
||||
} else {
|
||||
$directory = DIR_EXTENSION . $part[1] . '/catalog/language/';
|
||||
|
||||
array_shift($part);
|
||||
// Don't remove. Required for extension route.
|
||||
array_shift($part);
|
||||
|
||||
$route = implode('/', $part);
|
||||
}
|
||||
|
||||
if ($language_info && is_file($directory . $language_info['code'] . '/' . $route . '.php') && substr(str_replace('\\', '/', realpath($directory . $language_info['code'] . '/' . $route . '.php')), 0, strlen($directory)) == str_replace('\\', '/', $directory)) {
|
||||
$_ = [];
|
||||
|
||||
include($directory . $language_info['code'] . '/' . $route . '.php');
|
||||
|
||||
foreach ($_ as $key => $value) {
|
||||
$json[] = [
|
||||
'key' => $key,
|
||||
'value' => $value
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
40
admininistrator/controller/error/exception.php
Normal file
40
admininistrator/controller/error/exception.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Error;
|
||||
/**
|
||||
* Class Exception
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Error
|
||||
*/
|
||||
class Exception extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $message
|
||||
* @param string $code
|
||||
* @param string $file
|
||||
* @param string $line
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string $message, string $code, string $file, string $line): void {
|
||||
$this->load->language('error/exception');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('error/exception', '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('error/exception', $data));
|
||||
}
|
||||
}
|
35
admininistrator/controller/error/not_found.php
Normal file
35
admininistrator/controller/error/not_found.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Error;
|
||||
/**
|
||||
* Class Not Found
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Error
|
||||
*/
|
||||
class NotFound extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('error/not_found');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', isset($this->session->data['user_token']) ? 'user_token=' . $this->session->data['user_token'] : '')
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('error/not_found', isset($this->session->data['user_token']) ? '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('error/not_found', $data));
|
||||
}
|
||||
}
|
35
admininistrator/controller/error/permission.php
Normal file
35
admininistrator/controller/error/permission.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Error;
|
||||
/**
|
||||
* Class Permission
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Error
|
||||
*/
|
||||
class Permission extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('error/permission');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link($this->request->get['route'], '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('error/permission', $data));
|
||||
}
|
||||
}
|
36
admininistrator/controller/event/currency.php
Normal file
36
admininistrator/controller/event/currency.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Event;
|
||||
/**
|
||||
* Class Currency
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Event
|
||||
*/
|
||||
class Currency extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
*
|
||||
* model/setting/setting/editSetting
|
||||
* model/localisation/currency/addCurrency
|
||||
* model/localisation/currency/editCurrency
|
||||
*
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, array &$args, mixed &$output): void {
|
||||
if ($route == 'model/setting/setting/editSetting' && $args[0] == 'config' && isset($args[1]['config_currency'])) {
|
||||
$currency = $args[1]['config_currency'];
|
||||
} else {
|
||||
$currency = $this->config->get('config_currency');
|
||||
}
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extension_info = $this->model_setting_extension->getExtensionByCode('currency', $this->config->get('config_currency_engine'));
|
||||
|
||||
if ($extension_info) {
|
||||
$this->load->controller('extension/' . $extension_info['extension'] . '/currency/' . $extension_info['code'] . '.currency', $currency);
|
||||
}
|
||||
}
|
||||
}
|
40
admininistrator/controller/event/debug.php
Normal file
40
admininistrator/controller/event/debug.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Event;
|
||||
/**
|
||||
* Class Debug
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Event
|
||||
*/
|
||||
class Debug extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function before(string &$route, array &$args): void {
|
||||
if ($route == 'common/home') { // add the route you want to test
|
||||
//$this->session->data['debug'][$route] = microtime();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function after(string $route, array &$args, mixed &$output): void {
|
||||
if ($route == 'common/home') { // add the route you want to test
|
||||
if (isset($this->session->data['debug'][$route])) {
|
||||
$log_data = [
|
||||
'route' => $route,
|
||||
'time' => microtime() - $this->session->data['debug'][$route]
|
||||
];
|
||||
|
||||
$this->log->write($route);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
61
admininistrator/controller/event/language.php
Normal file
61
admininistrator/controller/event/language.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Event;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Event
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Controller {
|
||||
// view/*/before
|
||||
// Dump all the language vars into the template.
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, array &$args): void {
|
||||
foreach ($this->language->all() as $key => $value) {
|
||||
if (!isset($args[$key])) {
|
||||
$args[$key] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// controller/*/before
|
||||
// 1. Before controller load store all current loaded language data.
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function before(string &$route, array &$args): void {
|
||||
$data = $this->language->all();
|
||||
|
||||
if ($data) {
|
||||
$this->language->set('backup', json_encode($data));
|
||||
}
|
||||
}
|
||||
|
||||
// controller/*/after
|
||||
// 2. After controller load restore old language data.
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function after(string &$route, array &$args, mixed &$output): void {
|
||||
$data = json_decode($this->language->get('backup'), true);
|
||||
|
||||
if (is_array($data)) {
|
||||
$this->language->clear();
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
$this->language->set($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
admininistrator/controller/event/statistics.php
Normal file
67
admininistrator/controller/event/statistics.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Event;
|
||||
/**
|
||||
* Class Statistics
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Event
|
||||
*/
|
||||
class Statistics extends \Opencart\System\Engine\Controller {
|
||||
// admin/model/catalog/review/addReview/after
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReview(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$this->model_report_statistics->addValue('review', 1);
|
||||
}
|
||||
|
||||
// admin/model/catalog/review/deleteReview/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReview(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$this->model_report_statistics->removeValue('review', 1);
|
||||
}
|
||||
|
||||
// admin/model/sale/returns/addReturn/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addReturn(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$this->model_report_statistics->addValue('returns', 1);
|
||||
}
|
||||
|
||||
// admin/model/sale/returns/deleteReturn/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteReturn(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->model('report/statistics');
|
||||
|
||||
$this->model_report_statistics->removeValue('returns', 1);
|
||||
}
|
||||
}
|
184
admininistrator/controller/extension/analytics.php
Normal file
184
admininistrator/controller/extension/analytics.php
Normal file
@ -0,0 +1,184 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Analytics
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Analytics extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/analytics');
|
||||
|
||||
// Promotion
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/analytics/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('analytics');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
// Uninstall any missing extensions
|
||||
$this->model_setting_extension->uninstall('analytics', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/analytics/' . $code, $code);
|
||||
|
||||
$store_data = [];
|
||||
|
||||
$store_data[] = [
|
||||
'name' => $this->config->get('config_name'),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/analytics/' . $code, 'user_token=' . $this->session->data['user_token'] . '&store_id=0'),
|
||||
'status' => $this->config->get('analytics_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled')
|
||||
];
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$store_data[] = [
|
||||
'name' => $store['name'],
|
||||
'edit' => $this->url->link('extension/' . $extension . '/analytics/' . $code, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id']),
|
||||
'status' => $this->model_setting_setting->getValue('analytics_' . $code . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled')
|
||||
];
|
||||
}
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'install' => $this->url->link('extension/analytics.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/analytics.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'store' => $store_data
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->load->view('extension/analytics', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/analytics');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/analytics')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/analytics/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('analytics', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/analytics/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/analytics/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/analytics/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/analytics');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/analytics')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('analytics', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/analytics/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
161
admininistrator/controller/extension/captcha.php
Normal file
161
admininistrator/controller/extension/captcha.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Captcha
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Captcha extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
// Had top load again because the method is called directly.
|
||||
$this->load->language('extension/captcha');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/captcha/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('captcha');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('captcha', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/captcha/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title') . ($code == $this->config->get('config_captcha') ? $this->language->get('text_default') : ''),
|
||||
'status' => $this->config->get('captcha_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'install' => $this->url->link('extension/captcha.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/captcha.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/captcha/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/captcha', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/captcha');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/captcha')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/captcha/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('captcha', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/captcha/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/captcha/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/captcha/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/captcha');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/captcha')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('captcha', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/captcha/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
160
admininistrator/controller/extension/currency.php
Normal file
160
admininistrator/controller/extension/currency.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Currency
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Currency extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/currency');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/currency/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('currency');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('currency', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/currency/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title') . ($code == $this->config->get('config_currency') ? $this->language->get('text_default') : ''),
|
||||
'status' => $this->config->get('currency_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'install' => $this->url->link('extension/currency.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/currency.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/currency/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/currency', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/currency');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/currency')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/currency/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('currency', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/currency/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/currency/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/currency/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/currency');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/currency')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('currency', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/currency/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
173
admininistrator/controller/extension/dashboard.php
Normal file
173
admininistrator/controller/extension/dashboard.php
Normal file
@ -0,0 +1,173 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Dashboard
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Dashboard extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/dashboard');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/dashboard/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('dashboard');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('dashboard', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/dashboard/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'width' => $this->config->get('dashboard_' . $code . '_width'),
|
||||
'status' => $this->config->get('dashboard_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'sort_order' => $this->config->get('dashboard_' . $code . '_sort_order'),
|
||||
'install' => $this->url->link('extension/dashboard.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/dashboard.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/dashboard/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/dashboard', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate(): bool {
|
||||
if (!$this->user->hasPermission('modify', 'extension/dashboard')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/dashboard');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/dashboard')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/dashboard/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('dashboard', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/dashboard/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' .$extension . '/dashboard/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/dashboard/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/dashboard');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/dashboard')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('dashboard', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/dashboard/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
171
admininistrator/controller/extension/feed.php
Normal file
171
admininistrator/controller/extension/feed.php
Normal file
@ -0,0 +1,171 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Feed
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Feed extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/feed');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/feed/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('feed');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('feed', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/feed/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $this->config->get('feed_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'install' => $this->url->link('extension/feed.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/feed.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/feed/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/feed', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function validate(): bool {
|
||||
if (!$this->user->hasPermission('modify', 'extension/feed')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/feed');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/feed')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/feed/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('feed', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/feed/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/feed/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/feed/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/feed');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/feed')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('feed', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/feed/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
160
admininistrator/controller/extension/fraud.php
Normal file
160
admininistrator/controller/extension/fraud.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Fraud
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Fraud extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/fraud');
|
||||
|
||||
$available = [];
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/fraud/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('fraud');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('fraud', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/fraud/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $this->config->get('fraud_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'install' => $this->url->link('extension/fraud.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/fraud.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/fraud/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/fraud', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/fraud');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/fraud')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/fraud/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('fraud', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/fraud/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/fraud/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/fraud/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/fraud');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/fraud')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('fraud', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/fraud/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
160
admininistrator/controller/extension/language.php
Normal file
160
admininistrator/controller/extension/language.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/language');
|
||||
|
||||
$available = [];
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/language/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('language');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('language', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/language/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $this->config->get('language_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'install' => $this->url->link('extension/language.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/language.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/language/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/language', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/language');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename((string)$this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename((string)$this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/language')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/language/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('language', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/language/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/language/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/language/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/language');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/language')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('language', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/language/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
160
admininistrator/controller/extension/marketplace.php
Normal file
160
admininistrator/controller/extension/marketplace.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Marketplace
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Marketplace extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/marketplace');
|
||||
|
||||
$available = [];
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/marketplace/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('marketplace');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('marketplace', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/marketplace/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $this->config->get('language_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'install' => $this->url->link('extension/marketplace.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/marketplace.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/marketplace/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/marketplace', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/marketplace');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename((string)$this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename((string)$this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/marketplace')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/marketplace/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('marketplace', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/marketplace/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/marketplace/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/marketplace/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/marketplace');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/marketplace')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('marketplace', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/marketplace/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
262
admininistrator/controller/extension/module.php
Normal file
262
admininistrator/controller/extension/module.php
Normal file
@ -0,0 +1,262 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Module
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Module extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/module');
|
||||
|
||||
$this->load->model('setting/module');
|
||||
|
||||
$this->load->language('extension/module');
|
||||
|
||||
$data['text_layout'] = sprintf($this->language->get('text_layout'), $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token']));
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/module/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('module');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('module', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('setting/module');
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/module/' . $code, $code);
|
||||
|
||||
$module_data = [];
|
||||
|
||||
$modules = $this->model_setting_module->getModulesByCode($extension . '.' . $code);
|
||||
|
||||
foreach ($modules as $module) {
|
||||
if ($module['setting']) {
|
||||
$setting_info = json_decode($module['setting'], true);
|
||||
} else {
|
||||
$setting_info = [];
|
||||
}
|
||||
|
||||
$module_data[] = [
|
||||
'name' => $module['name'],
|
||||
'status' => (bool)$setting_info['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/module/' . $code, 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $module['module_id']),
|
||||
'delete' => $this->url->link('extension/module.delete', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $module['module_id'])
|
||||
];
|
||||
}
|
||||
|
||||
if ($module_data) {
|
||||
$status = '';
|
||||
} else {
|
||||
$status = $this->config->get('module_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled');
|
||||
}
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $status,
|
||||
'module' => $module_data,
|
||||
'install' => $this->url->link('extension/module.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/module.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/module/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = [];
|
||||
|
||||
foreach ($data['extensions'] as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $data['extensions']);
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/module', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/module');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/module')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/module/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('module', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/module/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/module/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/module/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/module');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/module')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('module', $this->request->get['code']);
|
||||
|
||||
$this->load->model('setting/module');
|
||||
|
||||
$this->model_setting_module->deleteModulesByCode($this->request->get['extension'] . '.' . $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/module/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function add(): void {
|
||||
$this->load->language('extension/module');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/module')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->language('extension/' . $this->request->get['extension'] . '/module/' . $this->request->get['code'], 'extension');
|
||||
|
||||
$this->load->model('setting/module');
|
||||
|
||||
$this->model_setting_module->addModule($this->request->get['extension'] . '.' . $this->request->get['code'], $this->language->get('extension_heading_title'));
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('extension/module');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['module_id'])) {
|
||||
$module_id = $this->request->get['module_id'];
|
||||
} else {
|
||||
$module_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/module')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/module');
|
||||
|
||||
$this->model_setting_module->deleteModule($module_id);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
161
admininistrator/controller/extension/other.php
Normal file
161
admininistrator/controller/extension/other.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Other
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Other extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
// Had top load again because the method is called directly.
|
||||
$this->load->language('extension/other');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/other/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('other');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('other', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/other/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $this->config->get('other_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'install' => $this->url->link('extension/other.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/other.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/other/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/other', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/other');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/other')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/other/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('other', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/other/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/other/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/other/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/other');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/other')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('other', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/other/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
170
admininistrator/controller/extension/payment.php
Normal file
170
admininistrator/controller/extension/payment.php
Normal file
@ -0,0 +1,170 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Payment
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Payment extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/payment');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/payment/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('payment');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('payment', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/payment/' . $code, $code);
|
||||
|
||||
$text_link = $this->language->get($code . '_text_' . $code);
|
||||
|
||||
if ($text_link != $code . '_text_' . $code) {
|
||||
$link = $text_link;
|
||||
} else {
|
||||
$link = '';
|
||||
}
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'link' => $link,
|
||||
'status' => $this->config->get('payment_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'sort_order' => $this->config->get('payment_' . $code . '_sort_order'),
|
||||
'install' => $this->url->link('extension/payment.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/payment.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/payment/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/payment', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/payment');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/payment')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/payment/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('payment', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/payment/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/payment/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/payment/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/payment');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/payment')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('payment', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/payment/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
161
admininistrator/controller/extension/report.php
Normal file
161
admininistrator/controller/extension/report.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Report
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Report extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/report');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/report/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('report');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('report', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/report/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $this->config->get('report_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'sort_order' => $this->config->get('report_' . $code . '_sort_order'),
|
||||
'install' => $this->url->link('extension/report.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/report.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/report/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/report', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/report');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/report')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/report/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('report', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/report/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/report/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/report/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/report');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/report')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('report', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/report/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
161
admininistrator/controller/extension/shipping.php
Normal file
161
admininistrator/controller/extension/shipping.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Shipping
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Shipping extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/shipping');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/shipping/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('shipping');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('shipping', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/shipping/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $this->config->get('shipping_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'sort_order' => $this->config->get('shipping_' . $code . '_sort_order'),
|
||||
'install' => $this->url->link('extension/shipping.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/shipping.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/shipping/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/shipping', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/shipping');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/shipping')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/shipping/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('shipping', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/shipping/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/shipping/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/shipping/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/shipping');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/shipping')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('shipping', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/shipping/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
180
admininistrator/controller/extension/theme.php
Normal file
180
admininistrator/controller/extension/theme.php
Normal file
@ -0,0 +1,180 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Theme
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Theme extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/theme');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/theme/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('theme');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('theme', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/theme/' . $code, $code);
|
||||
|
||||
$store_data = [];
|
||||
|
||||
$store_data[] = [
|
||||
'name' => $this->config->get('config_name'),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/theme/' . $code, 'user_token=' . $this->session->data['user_token'] . '&store_id=0'),
|
||||
'status' => $this->config->get('theme_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled')
|
||||
];
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$store_data[] = [
|
||||
'name' => $store['name'],
|
||||
'edit' => $this->url->link('extension/' . $extension . '/theme/' . $code, 'user_token=' . $this->session->data['user_token'] . '&store_id=' . $store['store_id']),
|
||||
'status' => $this->model_setting_setting->getValue('theme_' . $code . '_status', $store['store_id']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled')
|
||||
];
|
||||
}
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'install' => $this->url->link('extension/theme.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/theme.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'store' => $store_data
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/theme', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/theme');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/theme')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/theme/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('theme', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/theme/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/theme/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/theme/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/theme');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/theme')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('theme', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/theme/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
161
admininistrator/controller/extension/total.php
Normal file
161
admininistrator/controller/extension/total.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Extension;
|
||||
/**
|
||||
* Class Total
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Extension
|
||||
*/
|
||||
class Total extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('extension/total');
|
||||
|
||||
$available = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$results = $this->model_setting_extension->getPaths('%/admin/controller/total/%.php');
|
||||
|
||||
foreach ($results as $result) {
|
||||
$available[] = basename($result['path'], '.php');
|
||||
}
|
||||
|
||||
$installed = [];
|
||||
|
||||
$extensions = $this->model_setting_extension->getExtensionsByType('total');
|
||||
|
||||
foreach ($extensions as $extension) {
|
||||
if (in_array($extension['code'], $available)) {
|
||||
$installed[] = $extension['code'];
|
||||
} else {
|
||||
$this->model_setting_extension->uninstall('total', $extension['code']);
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if ($results) {
|
||||
foreach ($results as $result) {
|
||||
$extension = substr($result['path'], 0, strpos($result['path'], '/'));
|
||||
|
||||
$code = basename($result['path'], '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension . '/total/' . $code, $code);
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $this->language->get($code . '_heading_title'),
|
||||
'status' => $this->config->get('total_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'sort_order' => $this->config->get('total_' . $code . '_sort_order'),
|
||||
'install' => $this->url->link('extension/total.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'uninstall' => $this->url->link('extension/total.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
|
||||
'installed' => in_array($code, $installed),
|
||||
'edit' => $this->url->link('extension/' . $extension . '/total/' . $code, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['promotion'] = $this->load->controller('marketplace/promotion');
|
||||
|
||||
return $this->load->view('extension/total', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('extension/total');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension'])) {
|
||||
$extension = basename($this->request->get['extension']);
|
||||
} else {
|
||||
$extension = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['code'])) {
|
||||
$code = basename($this->request->get['code']);
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/total')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/total/' . $code . '.php')) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->install('total', $extension, $code);
|
||||
|
||||
$this->load->model('user/user_group');
|
||||
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/total/' . $code);
|
||||
$this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/total/' . $code);
|
||||
|
||||
$namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
|
||||
|
||||
// Register controllers, models and system extension folders
|
||||
$this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
|
||||
$this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
|
||||
$this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
|
||||
|
||||
// Template directory
|
||||
$this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
|
||||
|
||||
// Language directory
|
||||
$this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
|
||||
|
||||
// Config directory
|
||||
$this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
|
||||
|
||||
// Call install method if it exists
|
||||
$this->load->controller('extension/' . $extension . '/total/' . $code . '.install');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('extension/total');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'extension/total')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->uninstall('total', $this->request->get['code']);
|
||||
|
||||
// Call uninstall method if it exists
|
||||
$this->load->controller('extension/' . $this->request->get['extension'] . '/total/' . $this->request->get['code'] . '.uninstall');
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
249
admininistrator/controller/localisation/address_format.php
Normal file
249
admininistrator/controller/localisation/address_format.php
Normal file
@ -0,0 +1,249 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Address Format
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class AddressFormat extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/address_format');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/address_format', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/address_format.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/address_format.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/address_format', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/address_format');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/address_format.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['address_formats'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/address_format');
|
||||
|
||||
$address_format_total = $this->model_localisation_address_format->getTotalAddressFormats($filter_data);
|
||||
|
||||
$results = $this->model_localisation_address_format->getAddressFormats($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['address_formats'][] = [
|
||||
'address_format_id' => $result['address_format_id'],
|
||||
'name' => $result['name'] . (($result['address_format_id'] == $this->config->get('config_address_format_id')) ? $this->language->get('text_default') : ''),
|
||||
'address_format' => nl2br($result['address_format']),
|
||||
'edit' => $this->url->link('localisation/address_format.form', 'user_token=' . $this->session->data['user_token'] . '&address_format_id=' . $result['address_format_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $address_format_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/address_format.list', 'user_token=' . $this->session->data['user_token'] . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($address_format_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($address_format_total - $this->config->get('config_pagination_admin'))) ? $address_format_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $address_format_total, ceil($address_format_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
return $this->load->view('localisation/address_format_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/address_format');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['address_format_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/address_format', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/address_format.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/address_format', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['address_format_id'])) {
|
||||
$this->load->model('localisation/address_format');
|
||||
|
||||
$address_format_info = $this->model_localisation_address_format->getAddressFormat($this->request->get['address_format_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['address_format_id'])) {
|
||||
$data['address_format_id'] = (int)$this->request->get['address_format_id'];
|
||||
} else {
|
||||
$data['address_format_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($address_format_info)) {
|
||||
$data['name'] = $address_format_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($address_format_info)) {
|
||||
$data['address_format'] = $address_format_info['address_format'];
|
||||
} else {
|
||||
$data['address_format'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/address_format_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/address_format');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/address_format')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 1) || (oc_strlen($this->request->post['name']) > 128)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/address_format');
|
||||
|
||||
if (!$this->request->post['address_format_id']) {
|
||||
$json['address_format_id'] = $this->model_localisation_address_format->addAddressFormat($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_address_format->editAddressFormat($this->request->post['address_format_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/address_format');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/address_format')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
foreach ($selected as $address_format_id) {
|
||||
if ($this->config->get('config_address_format_id') == $address_format_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$country_total = $this->model_localisation_country->getTotalCountriesByAddressFormatId($address_format_id);
|
||||
|
||||
if ($country_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_country'), $country_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/address_format');
|
||||
|
||||
foreach ($selected as $address_format_id) {
|
||||
$this->model_localisation_address_format->deleteAddressFormat($address_format_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
489
admininistrator/controller/localisation/country.php
Normal file
489
admininistrator/controller/localisation/country.php
Normal file
@ -0,0 +1,489 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Country
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class Country extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/country');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$filter_name = (string)$this->request->get['filter_name'];
|
||||
} else {
|
||||
$filter_name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_2'])) {
|
||||
$filter_iso_code_2 = (string)$this->request->get['filter_iso_code_2'];
|
||||
} else {
|
||||
$filter_iso_code_2 = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_3'])) {
|
||||
$filter_iso_code_3 = (string)$this->request->get['filter_iso_code_3'];
|
||||
} else {
|
||||
$filter_iso_code_3 = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/country.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/country.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$data['filter_name'] = $filter_name;
|
||||
$data['filter_iso_code_2'] = $filter_iso_code_2;
|
||||
$data['filter_iso_code_3'] = $filter_iso_code_3;
|
||||
|
||||
$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('localisation/country', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/country');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$filter_name = (string)$this->request->get['filter_name'];
|
||||
} else {
|
||||
$filter_name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_2'])) {
|
||||
$filter_iso_code_2 = (string)$this->request->get['filter_iso_code_2'];
|
||||
} else {
|
||||
$filter_iso_code_2 = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_3'])) {
|
||||
$filter_iso_code_3 = (string)$this->request->get['filter_iso_code_3'];
|
||||
} else {
|
||||
$filter_iso_code_3 = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_2'])) {
|
||||
$url .= '&filter_iso_code_2=' . urlencode(html_entity_decode($this->request->get['filter_iso_code_2'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_3'])) {
|
||||
$url .= '&filter_iso_code_3=' . urlencode(html_entity_decode($this->request->get['filter_iso_code_3'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/country.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['countries'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => $filter_name,
|
||||
'filter_iso_code_2' => $filter_iso_code_2,
|
||||
'filter_iso_code_3' => $filter_iso_code_3,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_total = $this->model_localisation_country->getTotalCountries($filter_data);
|
||||
|
||||
$results = $this->model_localisation_country->getCountries($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['countries'][] = [
|
||||
'country_id' => $result['country_id'],
|
||||
'name' => $result['name'] . (($result['country_id'] == $this->config->get('config_country_id')) ? $this->language->get('text_default') : ''),
|
||||
'status' => $result['status'],
|
||||
'iso_code_2' => $result['iso_code_2'],
|
||||
'iso_code_3' => $result['iso_code_3'],
|
||||
'edit' => $this->url->link('localisation/country.form', 'user_token=' . $this->session->data['user_token'] . '&country_id=' . $result['country_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$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_iso_code_2'])) {
|
||||
$url .= '&filter_iso_code_2=' . urlencode(html_entity_decode($this->request->get['filter_iso_code_2'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_3'])) {
|
||||
$url .= '&filter_iso_code_3=' . urlencode(html_entity_decode($this->request->get['filter_iso_code_3'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/country.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
$data['sort_iso_code_2'] = $this->url->link('localisation/country.list', 'user_token=' . $this->session->data['user_token'] . '&sort=iso_code_2' . $url);
|
||||
$data['sort_iso_code_3'] = $this->url->link('localisation/country.list', 'user_token=' . $this->session->data['user_token'] . '&sort=iso_code_3' . $url);
|
||||
|
||||
$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_iso_code_2'])) {
|
||||
$url .= '&filter_iso_code_2=' . urlencode(html_entity_decode($this->request->get['filter_iso_code_2'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_3'])) {
|
||||
$url .= '&filter_iso_code_3=' . urlencode(html_entity_decode($this->request->get['filter_iso_code_3'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $country_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/country.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($country_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($country_total - $this->config->get('config_pagination_admin'))) ? $country_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $country_total, ceil($country_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/country_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/country');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['country_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$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_iso_code_2'])) {
|
||||
$url .= '&filter_iso_code_2=' . urlencode(html_entity_decode($this->request->get['filter_iso_code_2'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_iso_code_3'])) {
|
||||
$url .= '&filter_iso_code_3=' . urlencode(html_entity_decode($this->request->get['filter_iso_code_3'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/country.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/country', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['country_id'])) {
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_info = $this->model_localisation_country->getCountry($this->request->get['country_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['country_id'])) {
|
||||
$data['country_id'] = (int)$this->request->get['country_id'];
|
||||
} else {
|
||||
$data['country_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($country_info)) {
|
||||
$data['name'] = $country_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($country_info)) {
|
||||
$data['iso_code_2'] = $country_info['iso_code_2'];
|
||||
} else {
|
||||
$data['iso_code_2'] = '';
|
||||
}
|
||||
|
||||
if (!empty($country_info)) {
|
||||
$data['iso_code_3'] = $country_info['iso_code_3'];
|
||||
} else {
|
||||
$data['iso_code_3'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/address_format');
|
||||
|
||||
$data['address_formats'] = $this->model_localisation_address_format->getAddressFormats();
|
||||
|
||||
if (!empty($country_info)) {
|
||||
$data['address_format_id'] = $country_info['address_format_id'];
|
||||
} else {
|
||||
$data['address_format_id'] = '';
|
||||
}
|
||||
|
||||
if (!empty($country_info)) {
|
||||
$data['postcode_required'] = $country_info['postcode_required'];
|
||||
} else {
|
||||
$data['postcode_required'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($country_info)) {
|
||||
$data['status'] = $country_info['status'];
|
||||
} else {
|
||||
$data['status'] = '1';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/country_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/country');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/country')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 1) || (oc_strlen($this->request->post['name']) > 128)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
if (!$this->request->post['country_id']) {
|
||||
$json['country_id'] = $this->model_localisation_country->addCountry($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_country->editCountry($this->request->post['country_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/country');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/country')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('customer/customer');
|
||||
$this->load->model('localisation/zone');
|
||||
$this->load->model('localisation/geo_zone');
|
||||
|
||||
foreach ($selected as $country_id) {
|
||||
if ($this->config->get('config_country_id') == $country_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$store_total = $this->model_setting_store->getTotalStoresByCountryId($country_id);
|
||||
|
||||
if ($store_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_store'), $store_total);
|
||||
}
|
||||
|
||||
$address_total = $this->model_customer_customer->getTotalAddressesByCountryId($country_id);
|
||||
|
||||
if ($address_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_address'), $address_total);
|
||||
}
|
||||
|
||||
$zone_total = $this->model_localisation_zone->getTotalZonesByCountryId($country_id);
|
||||
|
||||
if ($zone_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_zone'), $zone_total);
|
||||
}
|
||||
|
||||
$zone_to_geo_zone_total = $this->model_localisation_geo_zone->getTotalZoneToGeoZoneByCountryId($country_id);
|
||||
|
||||
if ($zone_to_geo_zone_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_zone_to_geo_zone'), $zone_to_geo_zone_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
foreach ($selected as $country_id) {
|
||||
$this->model_localisation_country->deleteCountry($country_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function country(): void {
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['country_id'])) {
|
||||
$country_id = (int)$this->request->get['country_id'];
|
||||
} else {
|
||||
$country_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$country_info = $this->model_localisation_country->getCountry($country_id);
|
||||
|
||||
if ($country_info) {
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$json = [
|
||||
'country_id' => $country_info['country_id'],
|
||||
'name' => $country_info['name'],
|
||||
'iso_code_2' => $country_info['iso_code_2'],
|
||||
'iso_code_3' => $country_info['iso_code_3'],
|
||||
'address_format_id' => $country_info['address_format_id'],
|
||||
'postcode_required' => $country_info['postcode_required'],
|
||||
'zone' => $this->model_localisation_zone->getZonesByCountryId($country_id),
|
||||
'status' => $country_info['status']
|
||||
];
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
406
admininistrator/controller/localisation/currency.php
Normal file
406
admininistrator/controller/localisation/currency.php
Normal file
@ -0,0 +1,406 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Currency
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class Currency extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/currency');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['refresh'] = $this->url->link('localisation/currency.refresh', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['add'] = $this->url->link('localisation/currency.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/currency.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/currency', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/currency');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'title';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['action'] = $this->url->link('localisation/currency.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['currencies'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/currency');
|
||||
|
||||
$currency_total = $this->model_localisation_currency->getTotalCurrencies();
|
||||
|
||||
$results = $this->model_localisation_currency->getCurrencies($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['currencies'][] = [
|
||||
'currency_id' => $result['currency_id'],
|
||||
'title' => $result['title'] . (($result['code'] == $this->config->get('config_currency')) ? $this->language->get('text_default') : ''),
|
||||
'code' => $result['code'],
|
||||
'value' => $result['value'],
|
||||
'status' => $result['status'],
|
||||
'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
|
||||
'edit' => $this->url->link('localisation/currency.form', 'user_token=' . $this->session->data['user_token'] . '¤cy_id=' . $result['currency_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_title'] = $this->url->link('localisation/currency.list', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url);
|
||||
$data['sort_code'] = $this->url->link('localisation/currency.list', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url);
|
||||
$data['sort_value'] = $this->url->link('localisation/currency.list', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url);
|
||||
$data['sort_status'] = $this->url->link('localisation/currency.list', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url);
|
||||
$data['sort_date_modified'] = $this->url->link('localisation/currency.list', 'user_token=' . $this->session->data['user_token'] . '&sort=date_modified' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $currency_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/currency.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($currency_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($currency_total - $this->config->get('config_pagination_admin'))) ? $currency_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $currency_total, ceil($currency_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/currency_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/currency');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['currency_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/currency.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/currency', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['currency_id'])) {
|
||||
$this->load->model('localisation/currency');
|
||||
|
||||
$currency_info = $this->model_localisation_currency->getCurrency($this->request->get['currency_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['currency_id'])) {
|
||||
$data['currency_id'] = (int)$this->request->get['currency_id'];
|
||||
} else {
|
||||
$data['currency_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($currency_info)) {
|
||||
$data['title'] = $currency_info['title'];
|
||||
} else {
|
||||
$data['title'] = '';
|
||||
}
|
||||
|
||||
if (!empty($currency_info)) {
|
||||
$data['code'] = $currency_info['code'];
|
||||
} else {
|
||||
$data['code'] = '';
|
||||
}
|
||||
|
||||
if (!empty($currency_info)) {
|
||||
$data['symbol_left'] = $currency_info['symbol_left'];
|
||||
} else {
|
||||
$data['symbol_left'] = '';
|
||||
}
|
||||
|
||||
if (!empty($currency_info)) {
|
||||
$data['symbol_right'] = $currency_info['symbol_right'];
|
||||
} else {
|
||||
$data['symbol_right'] = '';
|
||||
}
|
||||
|
||||
if (!empty($currency_info)) {
|
||||
$data['decimal_place'] = $currency_info['decimal_place'];
|
||||
} else {
|
||||
$data['decimal_place'] = '';
|
||||
}
|
||||
|
||||
if (!empty($currency_info)) {
|
||||
$data['value'] = $currency_info['value'];
|
||||
} else {
|
||||
$data['value'] = '';
|
||||
}
|
||||
|
||||
if (!empty($currency_info)) {
|
||||
$data['status'] = $currency_info['status'];
|
||||
} else {
|
||||
$data['status'] = '';
|
||||
}
|
||||
|
||||
$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('localisation/currency_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/currency');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/currency')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['title']) < 3) || (oc_strlen($this->request->post['title']) > 32)) {
|
||||
$json['error']['title'] = $this->language->get('error_title');
|
||||
}
|
||||
|
||||
if (oc_strlen($this->request->post['code']) != 3) {
|
||||
$json['error']['code'] = $this->language->get('error_code');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/currency');
|
||||
|
||||
if (!$this->request->post['currency_id']) {
|
||||
$json['currency_id'] = $this->model_localisation_currency->addCurrency($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_currency->editCurrency($this->request->post['currency_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function refresh(): void {
|
||||
$this->load->language('localisation/currency');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/currency')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extension_info = $this->model_setting_extension->getExtensionByCode('currency', $this->config->get('config_currency_engine'));
|
||||
|
||||
if (!$extension_info) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->controller('extension/' . $extension_info['extension'] . '/currency/' . $extension_info['code'] . '.currency', $this->config->get('config_currency'));
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/currency');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/currency')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/currency');
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('sale/order');
|
||||
|
||||
foreach ($selected as $currency_id) {
|
||||
$currency_info = $this->model_localisation_currency->getCurrency($currency_id);
|
||||
|
||||
if ($currency_info) {
|
||||
if ($this->config->get('config_currency') == $currency_info['code']) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$store_total = $this->model_setting_store->getTotalStoresByCurrency($currency_info['code']);
|
||||
|
||||
if ($store_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_store'), $store_total);
|
||||
}
|
||||
}
|
||||
|
||||
$order_total = $this->model_sale_order->getTotalOrdersByCurrencyId($currency_id);
|
||||
|
||||
if ($order_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_order'), $order_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
foreach ($selected as $currency_id) {
|
||||
$this->model_localisation_currency->deleteCurrency($currency_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
323
admininistrator/controller/localisation/geo_zone.php
Normal file
323
admininistrator/controller/localisation/geo_zone.php
Normal file
@ -0,0 +1,323 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Geo Zone
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class GeoZone extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/geo_zone');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/geo_zone.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/geo_zone.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/geo_zone', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/geo_zone');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/geo_zone.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['geo_zones'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/geo_zone');
|
||||
|
||||
$geo_zone_total = $this->model_localisation_geo_zone->getTotalGeoZones();
|
||||
|
||||
$results = $this->model_localisation_geo_zone->getGeoZones($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['geo_zones'][] = [
|
||||
'geo_zone_id' => $result['geo_zone_id'],
|
||||
'name' => $result['name'],
|
||||
'description' => $result['description'],
|
||||
'edit' => $this->url->link('localisation/geo_zone.form', 'user_token=' . $this->session->data['user_token'] . '&geo_zone_id=' . $result['geo_zone_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/geo_zone.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
$data['sort_description'] = $this->url->link('localisation/geo_zone.list', 'user_token=' . $this->session->data['user_token'] . '&sort=description' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $geo_zone_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/geo_zone.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($geo_zone_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($geo_zone_total - $this->config->get('config_pagination_admin'))) ? $geo_zone_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $geo_zone_total, ceil($geo_zone_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/geo_zone_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/geo_zone');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['geo_zone_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/geo_zone.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/geo_zone', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['geo_zone_id'])) {
|
||||
$this->load->model('localisation/geo_zone');
|
||||
|
||||
$geo_zone_info = $this->model_localisation_geo_zone->getGeoZone($this->request->get['geo_zone_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['geo_zone_id'])) {
|
||||
$data['geo_zone_id'] = (int)$this->request->get['geo_zone_id'];
|
||||
} else {
|
||||
$data['geo_zone_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($geo_zone_info)) {
|
||||
$data['name'] = $geo_zone_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($geo_zone_info)) {
|
||||
$data['description'] = $geo_zone_info['description'];
|
||||
} else {
|
||||
$data['description'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
if (!empty($geo_zone_info)) {
|
||||
$data['zone_to_geo_zones'] = $this->model_localisation_geo_zone->getZoneToGeoZones($this->request->get['geo_zone_id']);
|
||||
} else {
|
||||
$data['zone_to_geo_zones'] = [];
|
||||
}
|
||||
|
||||
$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('localisation/geo_zone_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/geo_zone');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/geo_zone')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 32)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['description']) < 3) || (oc_strlen($this->request->post['description']) > 255)) {
|
||||
$json['error']['description'] = $this->language->get('error_description');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/geo_zone');
|
||||
|
||||
if (!$this->request->post['geo_zone_id']) {
|
||||
$json['geo_zone_id'] = $this->model_localisation_geo_zone->addGeoZone($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_geo_zone->editGeoZone($this->request->post['geo_zone_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/geo_zone');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/geo_zone')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/tax_rate');
|
||||
|
||||
foreach ($selected as $geo_zone_id) {
|
||||
$tax_rate_total = $this->model_localisation_tax_rate->getTotalTaxRatesByGeoZoneId($geo_zone_id);
|
||||
|
||||
if ($tax_rate_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_tax_rate'), $tax_rate_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/geo_zone');
|
||||
|
||||
foreach ($selected as $geo_zone_id) {
|
||||
$this->model_localisation_geo_zone->deleteGeoZone($geo_zone_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
373
admininistrator/controller/localisation/language.php
Normal file
373
admininistrator/controller/localisation/language.php
Normal file
@ -0,0 +1,373 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Language
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class Language extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/language');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/language.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/language.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/language', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/language');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/language.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['languages'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_total = $this->model_localisation_language->getTotalLanguages();
|
||||
|
||||
$results = $this->model_localisation_language->getLanguages($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['languages'][] = [
|
||||
'language_id' => $result['language_id'],
|
||||
'name' => $result['name'] . (($result['code'] == $this->config->get('config_language')) ? $this->language->get('text_default') : ''),
|
||||
'code' => $result['code'],
|
||||
'status' => $result['status'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('localisation/language.form', 'user_token=' . $this->session->data['user_token'] . '&language_id=' . $result['language_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/language.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
$data['sort_code'] = $this->url->link('localisation/language.list', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('localisation/language.list', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $language_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/language.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($language_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($language_total - $this->config->get('config_pagination_admin'))) ? $language_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $language_total, ceil($language_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/language_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/language');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['language_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/language.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/language', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['language_id'])) {
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($this->request->get['language_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['language_id'])) {
|
||||
$data['language_id'] = (int)$this->request->get['language_id'];
|
||||
} else {
|
||||
$data['language_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($language_info)) {
|
||||
$data['name'] = $language_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($language_info)) {
|
||||
$data['code'] = $language_info['code'];
|
||||
} else {
|
||||
$data['code'] = '';
|
||||
}
|
||||
|
||||
if (!empty($language_info)) {
|
||||
$data['locale'] = $language_info['locale'];
|
||||
} else {
|
||||
$data['locale'] = '';
|
||||
}
|
||||
|
||||
if (!empty($language_info)) {
|
||||
$data['extension'] = $language_info['extension'];
|
||||
} else {
|
||||
$data['extension'] = '';
|
||||
}
|
||||
|
||||
if (!empty($language_info)) {
|
||||
$data['sort_order'] = $language_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($language_info)) {
|
||||
$data['status'] = $language_info['status'];
|
||||
} else {
|
||||
$data['status'] = 1;
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/language_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/language');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/language')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 1) || (oc_strlen($this->request->post['name']) > 32)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['code']) < 2) || (oc_strlen($this->request->post['code']) > 5)) {
|
||||
$json['error']['code'] = $this->language->get('error_code');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['locale']) < 2) || (oc_strlen($this->request->post['locale']) > 255)) {
|
||||
$json['error']['locale'] = $this->language->get('error_locale');
|
||||
}
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguageByCode($this->request->post['code']);
|
||||
|
||||
if (!$this->request->post['language_id']) {
|
||||
if ($language_info) {
|
||||
$json['error']['warning'] = $this->language->get('error_exists');
|
||||
}
|
||||
} else {
|
||||
if ($language_info && ($this->request->post['language_id'] != $language_info['language_id'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_exists');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
if (!$this->request->post['language_id']) {
|
||||
$json['language_id'] = $this->model_localisation_language->addLanguage($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_language->editLanguage($this->request->post['language_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/language');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/language')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('sale/order');
|
||||
|
||||
foreach ($selected as $language_id) {
|
||||
$language_info = $this->model_localisation_language->getLanguage($language_id);
|
||||
|
||||
if ($language_info) {
|
||||
if ($this->config->get('config_language') == $language_info['code']) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
if ($this->config->get('config_language_admin') == $language_info['code']) {
|
||||
$json['error'] = $this->language->get('error_admin');
|
||||
}
|
||||
|
||||
$store_total = $this->model_setting_store->getTotalStoresByLanguage($language_info['code']);
|
||||
|
||||
if ($store_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_store'), $store_total);
|
||||
}
|
||||
}
|
||||
|
||||
$order_total = $this->model_sale_order->getTotalOrdersByLanguageId($language_id);
|
||||
|
||||
if ($order_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_order'), $order_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
foreach ($selected as $language_id) {
|
||||
$this->model_localisation_language->deleteLanguage($language_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
323
admininistrator/controller/localisation/length_class.php
Normal file
323
admininistrator/controller/localisation/length_class.php
Normal file
@ -0,0 +1,323 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Length Class
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class LengthClass extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/length_class');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/length_class.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/length_class.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/length_class', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/length_class');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'title';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/length_class.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['length_classes'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/length_class');
|
||||
|
||||
$length_class_total = $this->model_localisation_length_class->getTotalLengthClasses();
|
||||
|
||||
$results = $this->model_localisation_length_class->getLengthClasses($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['length_classes'][] = [
|
||||
'length_class_id' => $result['length_class_id'],
|
||||
'title' => $result['title'] . (($result['length_class_id'] == $this->config->get('config_length_class_id')) ? $this->language->get('text_default') : ''),
|
||||
'unit' => $result['unit'],
|
||||
'value' => $result['value'],
|
||||
'edit' => $this->url->link('localisation/length_class.form', 'user_token=' . $this->session->data['user_token'] . '&length_class_id=' . $result['length_class_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_title'] = $this->url->link('localisation/length_class.list', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url);
|
||||
$data['sort_unit'] = $this->url->link('localisation/length_class.list', 'user_token=' . $this->session->data['user_token'] . '&sort=unit' . $url);
|
||||
$data['sort_value'] = $this->url->link('localisation/length_class.list', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $length_class_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/length_class.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($length_class_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($length_class_total - $this->config->get('config_pagination_admin'))) ? $length_class_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $length_class_total, ceil($length_class_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/length_class_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/length_class');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['length_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/length_class.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/length_class', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['length_class_id'])) {
|
||||
$this->load->model('localisation/length_class');
|
||||
|
||||
$length_class_info = $this->model_localisation_length_class->getLengthClass($this->request->get['length_class_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['length_class_id'])) {
|
||||
$data['length_class_id'] = (int)$this->request->get['length_class_id'];
|
||||
} else {
|
||||
$data['length_class_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (!empty($length_class_info)) {
|
||||
$data['length_class_description'] = $this->model_localisation_length_class->getDescriptions($this->request->get['length_class_id']);
|
||||
} else {
|
||||
$data['length_class_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($length_class_info)) {
|
||||
$data['value'] = $length_class_info['value'];
|
||||
} else {
|
||||
$data['value'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/length_class_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/length_class');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/length_class')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['length_class_description'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['title']) < 3) || (oc_strlen($value['title']) > 32)) {
|
||||
$json['error']['title_' . $language_id] = $this->language->get('error_title');
|
||||
}
|
||||
|
||||
if (!$value['unit'] || (oc_strlen($value['unit']) > 4)) {
|
||||
$json['error']['unit_' . $language_id] = $this->language->get('error_unit');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/length_class');
|
||||
|
||||
if (!$this->request->post['length_class_id']) {
|
||||
$json['length_class_id'] = $this->model_localisation_length_class->addLengthClass($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_length_class->editLengthClass($this->request->post['length_class_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/length_class');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/length_class')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $length_class_id) {
|
||||
if ($this->config->get('config_length_class_id') == $length_class_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByLengthClassId($length_class_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/length_class');
|
||||
|
||||
foreach ($selected as $length_class_id) {
|
||||
$this->model_localisation_length_class->deleteLengthClass($length_class_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
349
admininistrator/controller/localisation/location.php
Normal file
349
admininistrator/controller/localisation/location.php
Normal file
@ -0,0 +1,349 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Location
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class Location extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/location');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/location.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/location.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/location', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/location');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/location.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['locations'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/location');
|
||||
|
||||
$location_total = $this->model_localisation_location->getTotalLocations();
|
||||
|
||||
$results = $this->model_localisation_location->getLocations($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['locations'][] = [
|
||||
'location_id' => $result['location_id'],
|
||||
'name' => $result['name'],
|
||||
'address' => $result['address'],
|
||||
'edit' => $this->url->link('localisation/location.form', 'user_token=' . $this->session->data['user_token'] . '&location_id=' . $result['location_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/location.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
$data['sort_address'] = $this->url->link('localisation/location.list', 'user_token=' . $this->session->data['user_token'] . '&sort=address' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $location_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/location.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($location_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($location_total - $this->config->get('config_pagination_admin'))) ? $location_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $location_total, ceil($location_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/location_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/location');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['location_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/location.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/location', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['location_id'])) {
|
||||
$this->load->model('localisation/location');
|
||||
|
||||
$location_info = $this->model_localisation_location->getLocation($this->request->get['location_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['location_id'])) {
|
||||
$data['location_id'] = (int)$this->request->get['location_id'];
|
||||
} else {
|
||||
$data['location_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
if (!empty($location_info)) {
|
||||
$data['name'] = $location_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($location_info)) {
|
||||
$data['address'] = $location_info['address'];
|
||||
} else {
|
||||
$data['address'] = '';
|
||||
}
|
||||
|
||||
if (!empty($location_info)) {
|
||||
$data['geocode'] = $location_info['geocode'];
|
||||
} else {
|
||||
$data['geocode'] = '';
|
||||
}
|
||||
|
||||
if (!empty($location_info)) {
|
||||
$data['telephone'] = $location_info['telephone'];
|
||||
} else {
|
||||
$data['telephone'] = '';
|
||||
}
|
||||
|
||||
if (!empty($location_info)) {
|
||||
$data['image'] = $location_info['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
if (is_file(DIR_IMAGE . html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'))) {
|
||||
$data['thumb'] = $this->model_tool_image->resize(html_entity_decode($data['image'], ENT_QUOTES, 'UTF-8'), 100, 100);
|
||||
} else {
|
||||
$data['thumb'] = $data['placeholder'];
|
||||
}
|
||||
|
||||
if (!empty($location_info)) {
|
||||
$data['open'] = $location_info['open'];
|
||||
} else {
|
||||
$data['open'] = '';
|
||||
}
|
||||
|
||||
if (!empty($location_info)) {
|
||||
$data['comment'] = $location_info['comment'];
|
||||
} else {
|
||||
$data['comment'] = '';
|
||||
}
|
||||
|
||||
$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('localisation/location_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/location');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/location')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 32)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['address']) < 3) || (oc_strlen($this->request->post['address']) > 128)) {
|
||||
$json['error']['address'] = $this->language->get('error_address');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['telephone']) < 3) || (oc_strlen($this->request->post['telephone']) > 32)) {
|
||||
$json['error']['telephone'] = $this->language->get('error_telephone');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/location');
|
||||
|
||||
if (!$this->request->post['location_id']) {
|
||||
$json['location_id'] = $this->model_localisation_location->addLocation($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_location->editLocation($this->request->post['location_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/location');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/location')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/location');
|
||||
|
||||
foreach ($selected as $location_id) {
|
||||
$this->model_localisation_location->deleteLocation($location_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
314
admininistrator/controller/localisation/order_status.php
Normal file
314
admininistrator/controller/localisation/order_status.php
Normal file
@ -0,0 +1,314 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Order Status
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class OrderStatus extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/order_status');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/order_status.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/order_status.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/order_status', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/order_status');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/order_status.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['order_statuses'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/order_status');
|
||||
|
||||
$order_status_total = $this->model_localisation_order_status->getTotalOrderStatuses();
|
||||
|
||||
$results = $this->model_localisation_order_status->getOrderStatuses($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['order_statuses'][] = [
|
||||
'order_status_id' => $result['order_status_id'],
|
||||
'name' => $result['name'] . (($result['order_status_id'] == $this->config->get('config_order_status_id')) ? $this->language->get('text_default') : ''),
|
||||
'edit' => $this->url->link('localisation/order_status.form', 'user_token=' . $this->session->data['user_token'] . '&order_status_id=' . $result['order_status_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/order_status.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $order_status_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/order_status.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($order_status_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($order_status_total - $this->config->get('config_pagination_admin'))) ? $order_status_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $order_status_total, ceil($order_status_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/order_status_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/order_status');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['order_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/order_status.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/order_status', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['order_status_id'])) {
|
||||
$data['order_status_id'] = (int)$this->request->get['order_status_id'];
|
||||
} else {
|
||||
$data['order_status_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['order_status_id'])) {
|
||||
$this->load->model('localisation/order_status');
|
||||
|
||||
$data['order_status'] = $this->model_localisation_order_status->getDescriptions($this->request->get['order_status_id']);
|
||||
} else {
|
||||
$data['order_status'] = [];
|
||||
}
|
||||
|
||||
$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('localisation/order_status_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/order_status');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/order_status')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['order_status'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['name']) < 3) || (oc_strlen($value['name']) > 32)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/order_status');
|
||||
|
||||
if (!$this->request->post['order_status_id']) {
|
||||
$json['order_status_id'] = $this->model_localisation_order_status->addOrderStatus($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_order_status->editOrderStatus($this->request->post['order_status_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/order_status');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/order_status')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('sale/order');
|
||||
|
||||
foreach ($selected as $order_status_id) {
|
||||
if ($this->config->get('config_order_status_id') == $order_status_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$order_total = $this->model_sale_order->getTotalOrdersByOrderStatusId($order_status_id);
|
||||
|
||||
if ($order_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_order'), $order_total);
|
||||
}
|
||||
|
||||
$order_total = $this->model_sale_order->getTotalHistoriesByOrderStatusId($order_status_id);
|
||||
|
||||
if ($order_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_order'), $order_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/order_status');
|
||||
|
||||
foreach ($selected as $order_status_id) {
|
||||
$this->model_localisation_order_status->deleteOrderStatus($order_status_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
302
admininistrator/controller/localisation/return_action.php
Normal file
302
admininistrator/controller/localisation/return_action.php
Normal file
@ -0,0 +1,302 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Return Action
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class ReturnAction extends \Opencart\System\Engine\Controller {
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/return_action');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/return_action.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/return_action.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/return_action', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/return_action');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/return_action.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['return_actions'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/return_action');
|
||||
|
||||
$return_action_total = $this->model_localisation_return_action->getTotalReturnActions();
|
||||
|
||||
$results = $this->model_localisation_return_action->getReturnActions($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['return_actions'][] = [
|
||||
'return_action_id' => $result['return_action_id'],
|
||||
'name' => $result['name'],
|
||||
'edit' => $this->url->link('localisation/return_action.form', 'user_token=' . $this->session->data['user_token'] . '&return_action_id=' . $result['return_action_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/return_action.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $return_action_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/return_action.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($return_action_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($return_action_total - $this->config->get('config_pagination_admin'))) ? $return_action_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $return_action_total, ceil($return_action_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/return_action_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/return_action');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['return_action_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/return_action.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/return_action', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['return_action_id'])) {
|
||||
$data['return_action_id'] = (int)$this->request->get['return_action_id'];
|
||||
} else {
|
||||
$data['return_action_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['return_action_id'])) {
|
||||
$this->load->model('localisation/return_action');
|
||||
|
||||
$data['return_action'] = $this->model_localisation_return_action->getDescriptions($this->request->get['return_action_id']);
|
||||
} else {
|
||||
$data['return_action'] = [];
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/return_action_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/return_action');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/return_action')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['return_action'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['name']) < 3) || (oc_strlen($value['name']) > 64)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/return_action');
|
||||
|
||||
if (!$this->request->post['return_action_id']) {
|
||||
$json['return_action_id'] = $this->model_localisation_return_action->addReturnAction($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_return_action->editReturnAction($this->request->post['return_action_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/return_action');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/return_action')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('sale/returns');
|
||||
|
||||
foreach ($selected as $return_action_id) {
|
||||
$return_total = $this->model_sale_returns->getTotalReturnsByReturnActionId($return_action_id);
|
||||
|
||||
if ($return_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_return'), $return_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/return_action');
|
||||
|
||||
foreach ($selected as $return_action_id) {
|
||||
$this->model_localisation_return_action->deleteReturnAction($return_action_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
301
admininistrator/controller/localisation/return_reason.php
Normal file
301
admininistrator/controller/localisation/return_reason.php
Normal file
@ -0,0 +1,301 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Return Reason
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class ReturnReason extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/return_reason');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/return_reason.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/return_reason.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/return_reason', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/return_reason');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/return_reason.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['return_reasons'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/return_reason');
|
||||
|
||||
$return_reason_total = $this->model_localisation_return_reason->getTotalReturnReasons();
|
||||
|
||||
$results = $this->model_localisation_return_reason->getReturnReasons($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['return_reasons'][] = [
|
||||
'return_reason_id' => $result['return_reason_id'],
|
||||
'name' => $result['name'],
|
||||
'edit' => $this->url->link('localisation/return_reason.form', 'user_token=' . $this->session->data['user_token'] . '&return_reason_id=' . $result['return_reason_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/return_reason.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $return_reason_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/return_reason.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($return_reason_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($return_reason_total - $this->config->get('config_pagination_admin'))) ? $return_reason_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $return_reason_total, ceil($return_reason_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/return_reason_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/return_reason');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['return_reason_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/return_reason.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/return_reason', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['return_reason_id'])) {
|
||||
$data['return_reason_id'] = (int)$this->request->get['return_reason_id'];
|
||||
} else {
|
||||
$data['return_reason_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['return_reason_id'])) {
|
||||
$this->load->model('localisation/return_reason');
|
||||
|
||||
$data['return_reason'] = $this->model_localisation_return_reason->getDescriptions($this->request->get['return_reason_id']);
|
||||
} else {
|
||||
$data['return_reason'] = [];
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/return_reason_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/return_reason');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/return_reason')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['return_reason'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['name']) < 3) || (oc_strlen($value['name']) > 128)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/return_reason');
|
||||
|
||||
if (!$this->request->post['return_reason_id']) {
|
||||
$json['return_reason_id'] = $this->model_localisation_return_reason->addReturnReason($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_return_reason->editReturnReason($this->request->post['return_reason_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/return_reason');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/return_reason')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('sale/returns');
|
||||
|
||||
foreach ($selected as $return_reason_id) {
|
||||
$return_total = $this->model_sale_returns->getTotalReturnsByReturnReasonId($return_reason_id);
|
||||
|
||||
if ($return_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_return'), $return_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/return_reason');
|
||||
|
||||
foreach ($selected as $return_reason_id) {
|
||||
$this->model_localisation_return_reason->deleteReturnReason($return_reason_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
311
admininistrator/controller/localisation/return_status.php
Normal file
311
admininistrator/controller/localisation/return_status.php
Normal file
@ -0,0 +1,311 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Return Status
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class ReturnStatus extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/return_status');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/return_status.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/return_status.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/return_status', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/return_status');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/return_status.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['return_statuses'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/return_status');
|
||||
|
||||
$return_status_total = $this->model_localisation_return_status->getTotalReturnStatuses();
|
||||
|
||||
$results = $this->model_localisation_return_status->getReturnStatuses($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['return_statuses'][] = [
|
||||
'return_status_id' => $result['return_status_id'],
|
||||
'name' => $result['name'] . (($result['return_status_id'] == $this->config->get('config_return_status_id')) ? $this->language->get('text_default') : ''),
|
||||
'edit' => $this->url->link('localisation/return_status.form', 'user_token=' . $this->session->data['user_token'] . '&return_status_id=' . $result['return_status_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/return_status.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $return_status_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/return_status.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($return_status_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($return_status_total - $this->config->get('config_pagination_admin'))) ? $return_status_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $return_status_total, ceil($return_status_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/return_status_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/return_status');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['return_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/return_status.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['return_status_id'])) {
|
||||
$data['return_status_id'] = (int)$this->request->get['return_status_id'];
|
||||
} else {
|
||||
$data['return_status_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['return_status_id'])) {
|
||||
$this->load->model('localisation/return_status');
|
||||
|
||||
$data['return_status'] = $this->model_localisation_return_status->getDescriptions($this->request->get['return_status_id']);
|
||||
} else {
|
||||
$data['return_status'] = [];
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/return_status_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/return_status');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/return_status')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['return_status'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['name']) < 3) || (oc_strlen($value['name']) > 32)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/return_status');
|
||||
|
||||
if (!$this->request->post['return_status_id']) {
|
||||
$json['return_status_id'] = $this->model_localisation_return_status->addReturnStatus($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_return_status->editReturnStatus($this->request->post['return_status_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/return_status');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/return_status')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('sale/returns');
|
||||
|
||||
foreach ($this->request->post['selected'] as $return_status_id) {
|
||||
if ($this->config->get('config_return_status_id') == $return_status_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$return_total = $this->model_sale_returns->getTotalReturnsByReturnStatusId($return_status_id);
|
||||
|
||||
if ($return_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_return'), $return_total);
|
||||
}
|
||||
|
||||
$return_total = $this->model_sale_returns->getTotalHistoriesByReturnStatusId($return_status_id);
|
||||
|
||||
if ($return_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_return'), $return_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/return_status');
|
||||
|
||||
foreach ($selected as $return_status_id) {
|
||||
$this->model_localisation_return_status->deleteReturnStatus($return_status_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
301
admininistrator/controller/localisation/stock_status.php
Normal file
301
admininistrator/controller/localisation/stock_status.php
Normal file
@ -0,0 +1,301 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Stock Status
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class StockStatus extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/stock_status');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/stock_status.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/stock_status.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/stock_status', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/stock_status');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/stock_status.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['stock_statuses'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/stock_status');
|
||||
|
||||
$stock_status_total = $this->model_localisation_stock_status->getTotalStockStatuses();
|
||||
|
||||
$results = $this->model_localisation_stock_status->getStockStatuses($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['stock_statuses'][] = [
|
||||
'stock_status_id' => $result['stock_status_id'],
|
||||
'name' => $result['name'],
|
||||
'edit' => $this->url->link('localisation/stock_status.form', 'user_token=' . $this->session->data['user_token'] . '&stock_status_id=' . $result['stock_status_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/stock_status.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $stock_status_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/stock_status.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($stock_status_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($stock_status_total - $this->config->get('config_pagination_admin'))) ? $stock_status_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $stock_status_total, ceil($stock_status_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/stock_status_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/stock_status');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['stock_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/stock_status.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/stock_status', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['stock_status_id'])) {
|
||||
$data['stock_status_id'] = (int)$this->request->get['stock_status_id'];
|
||||
} else {
|
||||
$data['stock_status_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['stock_status_id'])) {
|
||||
$this->load->model('localisation/stock_status');
|
||||
|
||||
$data['stock_status'] = $this->model_localisation_stock_status->getDescriptions($this->request->get['stock_status_id']);
|
||||
} else {
|
||||
$data['stock_status'] = [];
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/stock_status_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/stock_status');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/stock_status')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['stock_status'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['name']) < 3) || (oc_strlen($value['name']) > 32)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/stock_status');
|
||||
|
||||
if (!$this->request->post['stock_status_id']) {
|
||||
$json['stock_status_id'] = $this->model_localisation_stock_status->addStockStatus($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_stock_status->editStockStatus($this->request->post['stock_status_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/stock_status');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/stock_status')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $stock_status_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByStockStatusId($stock_status_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/stock_status');
|
||||
|
||||
foreach ($selected as $stock_status_id) {
|
||||
$this->model_localisation_stock_status->deleteStockStatus($stock_status_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
314
admininistrator/controller/localisation/subscription_status.php
Normal file
314
admininistrator/controller/localisation/subscription_status.php
Normal file
@ -0,0 +1,314 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Subscription Status
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class SubscriptionStatus extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/subscription_status');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/subscription_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/subscription_status.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/subscription_status.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/subscription_status', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/subscription_status');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/subscription_status.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['subscription_statuses'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/subscription_status');
|
||||
|
||||
$subscription_status_total = $this->model_localisation_subscription_status->getTotalSubscriptionStatuses();
|
||||
|
||||
$results = $this->model_localisation_subscription_status->getSubscriptionStatuses($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['subscription_statuses'][] = [
|
||||
'subscription_status_id' => $result['subscription_status_id'],
|
||||
'name' => $result['name'] . (($result['subscription_status_id'] == $this->config->get('config_subscription_status_id')) ? $this->language->get('text_default') : ''),
|
||||
'edit' => $this->url->link('localisation/subscription_status.form', 'user_token=' . $this->session->data['user_token'] . '&subscription_status_id=' . $result['subscription_status_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/subscription_status.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $subscription_status_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/subscription_status.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($subscription_status_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($subscription_status_total - $this->config->get('config_pagination_admin'))) ? $subscription_status_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $subscription_status_total, ceil($subscription_status_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/subscription_status_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/subscription_status');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['subscription_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/subscription_status', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/subscription_status.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/subscription_status', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['subscription_status_id'])) {
|
||||
$data['subscription_status_id'] = (int)$this->request->get['subscription_status_id'];
|
||||
} else {
|
||||
$data['subscription_status_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['subscription_status_id'])) {
|
||||
$this->load->model('localisation/subscription_status');
|
||||
|
||||
$data['subscription_status'] = $this->model_localisation_subscription_status->getDescriptions($this->request->get['subscription_status_id']);
|
||||
} else {
|
||||
$data['subscription_status'] = [];
|
||||
}
|
||||
|
||||
$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('localisation/subscription_status_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/subscription_status');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/subscription_status')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['subscription_status'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['name']) < 3) || (oc_strlen($value['name']) > 32)) {
|
||||
$json['error']['name_' . $language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/subscription_status');
|
||||
|
||||
if (!$this->request->post['subscription_status_id']) {
|
||||
$json['subscription_status_id'] = $this->model_localisation_subscription_status->addSubscriptionStatus($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_subscription_status->editSubscriptionStatus($this->request->post['subscription_status_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/subscription_status');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/subscription_status')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('sale/subscription');
|
||||
|
||||
foreach ($selected as $subscription_status_id) {
|
||||
if ($this->config->get('config_subscription_status_id') == $subscription_status_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$subscription_total = $this->model_sale_subscription->getTotalSubscriptionsBySubscriptionStatusId($subscription_status_id);
|
||||
|
||||
if ($subscription_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_subscription'), $subscription_total);
|
||||
}
|
||||
|
||||
$subscription_total = $this->model_sale_subscription->getTotalHistoriesBySubscriptionStatusId($subscription_status_id);
|
||||
|
||||
if ($subscription_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_subscription'), $subscription_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/subscription_status');
|
||||
|
||||
foreach ($selected as $subscription_status_id) {
|
||||
$this->model_localisation_subscription_status->deleteSubscriptionStatus($subscription_status_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
319
admininistrator/controller/localisation/tax_class.php
Normal file
319
admininistrator/controller/localisation/tax_class.php
Normal file
@ -0,0 +1,319 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Tax Class
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class TaxClass extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/tax_class');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/tax_class.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/tax_class.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/tax_class', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/tax_class');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'title';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/tax_class.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['tax_classes'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/tax_class');
|
||||
|
||||
$tax_class_total = $this->model_localisation_tax_class->getTotalTaxClasses();
|
||||
|
||||
$results = $this->model_localisation_tax_class->getTaxClasses($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['tax_classes'][] = [
|
||||
'tax_class_id' => $result['tax_class_id'],
|
||||
'title' => $result['title'],
|
||||
'edit' => $this->url->link('localisation/tax_class.form', 'user_token=' . $this->session->data['user_token'] . '&tax_class_id=' . $result['tax_class_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_title'] = $this->url->link('localisation/tax_class.list', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $tax_class_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/tax_class.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($tax_class_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($tax_class_total - $this->config->get('config_pagination_admin'))) ? $tax_class_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $tax_class_total, ceil($tax_class_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/tax_class_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/tax_class');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['tax_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/tax_class.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/tax_class', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['tax_class_id'])) {
|
||||
$this->load->model('localisation/tax_class');
|
||||
|
||||
$tax_class_info = $this->model_localisation_tax_class->getTaxClass($this->request->get['tax_class_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tax_class_id'])) {
|
||||
$data['tax_class_id'] = (int)$this->request->get['tax_class_id'];
|
||||
} else {
|
||||
$data['tax_class_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($tax_class_info)) {
|
||||
$data['title'] = $tax_class_info['title'];
|
||||
} else {
|
||||
$data['title'] = '';
|
||||
}
|
||||
|
||||
if (!empty($tax_class_info)) {
|
||||
$data['description'] = $tax_class_info['description'];
|
||||
} else {
|
||||
$data['description'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/tax_rate');
|
||||
|
||||
$data['tax_rates'] = $this->model_localisation_tax_rate->getTaxRates();
|
||||
|
||||
if (isset($this->request->get['tax_class_id'])) {
|
||||
$data['tax_rules'] = $this->model_localisation_tax_class->getTaxRules($this->request->get['tax_class_id']);
|
||||
} else {
|
||||
$data['tax_rules'] = [];
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/tax_class_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/tax_class');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/tax_class')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['title']) < 3) || (oc_strlen($this->request->post['title']) > 32)) {
|
||||
$json['error']['title'] = $this->language->get('error_title');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['description']) < 3) || (oc_strlen($this->request->post['description']) > 255)) {
|
||||
$json['error']['description'] = $this->language->get('error_description');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/tax_class');
|
||||
|
||||
if (!$this->request->post['tax_class_id']) {
|
||||
$json['tax_class_id'] = $this->model_localisation_tax_class->addTaxClass($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_tax_class->editTaxClass($this->request->post['tax_class_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/tax_class');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/tax_class')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $tax_class_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByTaxClassId($tax_class_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/tax_class');
|
||||
|
||||
foreach ($selected as $tax_class_id) {
|
||||
$this->model_localisation_tax_class->deleteTaxClass($tax_class_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
345
admininistrator/controller/localisation/tax_rate.php
Normal file
345
admininistrator/controller/localisation/tax_rate.php
Normal file
@ -0,0 +1,345 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Tax Rate
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class TaxRate extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/tax_rate');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/tax_rate.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/tax_rate.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/tax_rate', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/tax_rate');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'tr.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/tax_rate.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['tax_rates'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/tax_rate');
|
||||
|
||||
$tax_rate_total = $this->model_localisation_tax_rate->getTotalTaxRates();
|
||||
|
||||
$results = $this->model_localisation_tax_rate->getTaxRates($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['tax_rates'][] = [
|
||||
'tax_rate_id' => $result['tax_rate_id'],
|
||||
'name' => $result['name'],
|
||||
'rate' => $result['rate'],
|
||||
'type' => ($result['type'] == 'F' ? $this->language->get('text_amount') : $this->language->get('text_percent')),
|
||||
'geo_zone' => $result['geo_zone'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
|
||||
'edit' => $this->url->link('localisation/tax_rate.form', 'user_token=' . $this->session->data['user_token'] . '&tax_rate_id=' . $result['tax_rate_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('localisation/tax_rate.list', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.name' . $url);
|
||||
$data['sort_rate'] = $this->url->link('localisation/tax_rate.list', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.rate' . $url);
|
||||
$data['sort_type'] = $this->url->link('localisation/tax_rate.list', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.type' . $url);
|
||||
$data['sort_geo_zone'] = $this->url->link('localisation/tax_rate.list', 'user_token=' . $this->session->data['user_token'] . '&sort=gz.name' . $url);
|
||||
$data['sort_date_added'] = $this->url->link('localisation/tax_rate.list', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.date_added' . $url);
|
||||
$data['sort_date_modified'] = $this->url->link('localisation/tax_rate.list', 'user_token=' . $this->session->data['user_token'] . '&sort=tr.date_modified' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $tax_rate_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/tax_rate.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($tax_rate_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($tax_rate_total - $this->config->get('config_pagination_admin'))) ? $tax_rate_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $tax_rate_total, ceil($tax_rate_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/tax_rate_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/tax_rate');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['tax_rate_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/tax_rate.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/tax_rate', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['tax_rate_id'])) {
|
||||
$this->load->model('localisation/tax_rate');
|
||||
|
||||
$tax_rate_info = $this->model_localisation_tax_rate->getTaxRate($this->request->get['tax_rate_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['tax_rate_id'])) {
|
||||
$data['tax_rate_id'] = (int)$this->request->get['tax_rate_id'];
|
||||
} else {
|
||||
$data['tax_rate_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($tax_rate_info)) {
|
||||
$data['name'] = $tax_rate_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($tax_rate_info)) {
|
||||
$data['rate'] = $tax_rate_info['rate'];
|
||||
} else {
|
||||
$data['rate'] = '';
|
||||
}
|
||||
|
||||
if (!empty($tax_rate_info)) {
|
||||
$data['type'] = $tax_rate_info['type'];
|
||||
} else {
|
||||
$data['type'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer_group');
|
||||
|
||||
$data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();
|
||||
|
||||
if (isset($this->request->get['tax_rate_id'])) {
|
||||
$data['tax_rate_customer_group'] = $this->model_localisation_tax_rate->getCustomerGroups($this->request->get['tax_rate_id']);
|
||||
} else {
|
||||
$data['tax_rate_customer_group'] = [$this->config->get('config_customer_group_id')];
|
||||
}
|
||||
|
||||
$this->load->model('localisation/geo_zone');
|
||||
|
||||
$data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones();
|
||||
|
||||
if (!empty($tax_rate_info)) {
|
||||
$data['geo_zone_id'] = $tax_rate_info['geo_zone_id'];
|
||||
} else {
|
||||
$data['geo_zone_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('localisation/tax_rate_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/tax_rate');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/tax_rate')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 32)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if (!$this->request->post['rate']) {
|
||||
$json['error']['rate'] = $this->language->get('error_rate');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/tax_rate');
|
||||
|
||||
if (!$this->request->post['tax_rate_id']) {
|
||||
$json['tax_rate_id'] = $this->model_localisation_tax_rate->addTaxRate($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_tax_rate->editTaxRate($this->request->post['tax_rate_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/tax_rate');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/tax_rate')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/tax_class');
|
||||
|
||||
foreach ($this->request->post['selected'] as $tax_rate_id) {
|
||||
$tax_rule_total = $this->model_localisation_tax_class->getTotalTaxRulesByTaxRateId($tax_rate_id);
|
||||
|
||||
if ($tax_rule_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_tax_rule'), $tax_rule_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/tax_rate');
|
||||
|
||||
foreach ($selected as $tax_rate_id) {
|
||||
$this->model_localisation_tax_rate->deleteTaxRate($tax_rate_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
321
admininistrator/controller/localisation/weight_class.php
Normal file
321
admininistrator/controller/localisation/weight_class.php
Normal file
@ -0,0 +1,321 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Weight Class
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class WeightClass extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/weight_class');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/weight_class.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/weight_class.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('localisation/weight_class', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/weight_class');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'title';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/weight_class.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['weight_classes'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/weight_class');
|
||||
|
||||
$weight_class_total = $this->model_localisation_weight_class->getTotalWeightClasses();
|
||||
|
||||
$results = $this->model_localisation_weight_class->getWeightClasses($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['weight_classes'][] = [
|
||||
'weight_class_id' => $result['weight_class_id'],
|
||||
'title' => $result['title'] . (($result['weight_class_id'] == $this->config->get('config_weight_class_id')) ? $this->language->get('text_default') : ''),
|
||||
'unit' => $result['unit'],
|
||||
'value' => $result['value'],
|
||||
'edit' => $this->url->link('localisation/weight_class.form', 'user_token=' . $this->session->data['user_token'] . '&weight_class_id=' . $result['weight_class_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_title'] = $this->url->link('localisation/weight_class.list', 'user_token=' . $this->session->data['user_token'] . '&sort=title' . $url);
|
||||
$data['sort_unit'] = $this->url->link('localisation/weight_class.list', 'user_token=' . $this->session->data['user_token'] . '&sort=unit' . $url);
|
||||
$data['sort_value'] = $this->url->link('localisation/weight_class.list', 'user_token=' . $this->session->data['user_token'] . '&sort=value' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $weight_class_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/weight_class.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($weight_class_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($weight_class_total - $this->config->get('config_pagination_admin'))) ? $weight_class_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $weight_class_total, ceil($weight_class_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/weight_class_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/weight_class');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['weight_class_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/weight_class.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/weight_class', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['weight_class_id'])) {
|
||||
$this->load->model('localisation/weight_class');
|
||||
|
||||
$weight_class_info = $this->model_localisation_weight_class->getWeightClass($this->request->get['weight_class_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['weight_class_id'])) {
|
||||
$data['weight_class_id'] = (int)$this->request->get['weight_class_id'];
|
||||
} else {
|
||||
$data['weight_class_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['weight_class_id'])) {
|
||||
$data['weight_class_description'] = $this->model_localisation_weight_class->getDescriptions($this->request->get['weight_class_id']);
|
||||
} else {
|
||||
$data['weight_class_description'] = [];
|
||||
}
|
||||
|
||||
if (!empty($weight_class_info)) {
|
||||
$data['value'] = $weight_class_info['value'];
|
||||
} else {
|
||||
$data['value'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('localisation/weight_class_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/weight_class');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/weight_class')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['weight_class_description'] as $language_id => $value) {
|
||||
if ((oc_strlen($value['title']) < 3) || (oc_strlen($value['title']) > 32)) {
|
||||
$json['error']['title_' . $language_id] = $this->language->get('error_title');
|
||||
}
|
||||
|
||||
if (!$value['unit'] || (oc_strlen($value['unit']) > 4)) {
|
||||
$json['error']['unit_' . $language_id] = $this->language->get('error_unit');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/weight_class');
|
||||
|
||||
if (!$this->request->post['weight_class_id']) {
|
||||
$json['weight_class_id'] = $this->model_localisation_weight_class->addWeightClass($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_weight_class->editWeightClass($this->request->post['weight_class_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/weight_class');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/weight_class')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($selected as $weight_class_id) {
|
||||
if ($this->config->get('config_weight_class_id') == $weight_class_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByWeightClassId($weight_class_id);
|
||||
|
||||
if ($product_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/weight_class');
|
||||
|
||||
foreach ($selected as $weight_class_id) {
|
||||
$this->model_localisation_weight_class->deleteWeightClass($weight_class_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
435
admininistrator/controller/localisation/zone.php
Normal file
435
admininistrator/controller/localisation/zone.php
Normal file
@ -0,0 +1,435 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Localisation;
|
||||
/**
|
||||
* Class Zone
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Localisation
|
||||
*/
|
||||
class Zone extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('localisation/zone');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$filter_name = (string)$this->request->get['filter_name'];
|
||||
} else {
|
||||
$filter_name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_country'])) {
|
||||
$filter_country = (string)$this->request->get['filter_country'];
|
||||
} else {
|
||||
$filter_country = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$filter_code = (string)$this->request->get['filter_code'];
|
||||
} else {
|
||||
$filter_code = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('localisation/zone.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('localisation/zone.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$data['filter_name'] = $filter_name;
|
||||
$data['filter_country'] = $filter_country;
|
||||
$data['filter_code'] = $filter_code;
|
||||
|
||||
$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('localisation/zone', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('localisation/zone');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$filter_name = (string)$this->request->get['filter_name'];
|
||||
} else {
|
||||
$filter_name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_country'])) {
|
||||
$filter_country = (string)$this->request->get['filter_country'];
|
||||
} else {
|
||||
$filter_country = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$filter_code = (string)$this->request->get['filter_code'];
|
||||
} else {
|
||||
$filter_code = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'c.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_country'])) {
|
||||
$url .= '&filter_country=' . urlencode(html_entity_decode($this->request->get['filter_country'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . urlencode(html_entity_decode($this->request->get['filter_code'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('localisation/zone.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['zones'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => $filter_name,
|
||||
'filter_country' => $filter_country,
|
||||
'filter_code' => $filter_code,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone_total = $this->model_localisation_zone->getTotalZones($filter_data);
|
||||
|
||||
$results = $this->model_localisation_zone->getZones($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['zones'][] = [
|
||||
'zone_id' => $result['zone_id'],
|
||||
'country' => $result['country'],
|
||||
'name' => $result['name'] . (($result['zone_id'] == $this->config->get('config_zone_id')) ? $this->language->get('text_default') : ''),
|
||||
'code' => $result['code'],
|
||||
'status' => $result['status'],
|
||||
'edit' => $this->url->link('localisation/zone.form', 'user_token=' . $this->session->data['user_token'] . '&zone_id=' . $result['zone_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$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_country'])) {
|
||||
$url .= '&filter_country=' . urlencode(html_entity_decode($this->request->get['filter_country'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . urlencode(html_entity_decode($this->request->get['filter_code'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_country'] = $this->url->link('localisation/zone.list', 'user_token=' . $this->session->data['user_token'] . '&sort=c.name' . $url);
|
||||
$data['sort_name'] = $this->url->link('localisation/zone.list', 'user_token=' . $this->session->data['user_token'] . '&sort=z.name' . $url);
|
||||
$data['sort_code'] = $this->url->link('localisation/zone.list', 'user_token=' . $this->session->data['user_token'] . '&sort=z.code' . $url);
|
||||
|
||||
$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_country'])) {
|
||||
$url .= '&filter_country=' . urlencode(html_entity_decode($this->request->get['filter_country'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . urlencode(html_entity_decode($this->request->get['filter_code'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $zone_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('localisation/zone.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($zone_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($zone_total - $this->config->get('config_pagination_admin'))) ? $zone_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $zone_total, ceil($zone_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('localisation/zone_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('localisation/zone');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['zone_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$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_country'])) {
|
||||
$url .= '&filter_country=' . urlencode(html_entity_decode($this->request->get['filter_country'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . urlencode(html_entity_decode($this->request->get['filter_code'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('localisation/zone.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['zone_id'])) {
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
$zone_info = $this->model_localisation_zone->getZone($this->request->get['zone_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['zone_id'])) {
|
||||
$data['zone_id'] = (int)$this->request->get['zone_id'];
|
||||
} else {
|
||||
$data['zone_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($zone_info)) {
|
||||
$data['status'] = $zone_info['status'];
|
||||
} else {
|
||||
$data['status'] = '1';
|
||||
}
|
||||
|
||||
if (!empty($zone_info)) {
|
||||
$data['name'] = $zone_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($zone_info)) {
|
||||
$data['code'] = $zone_info['code'];
|
||||
} else {
|
||||
$data['code'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('localisation/country');
|
||||
|
||||
$data['countries'] = $this->model_localisation_country->getCountries();
|
||||
|
||||
if (!empty($zone_info)) {
|
||||
$data['country_id'] = $zone_info['country_id'];
|
||||
} else {
|
||||
$data['country_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('localisation/zone_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('localisation/zone');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/zone')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 1) || (oc_strlen($this->request->post['name']) > 64)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
if (!$this->request->post['zone_id']) {
|
||||
$json['zone_id'] = $this->model_localisation_zone->addZone($this->request->post);
|
||||
} else {
|
||||
$this->model_localisation_zone->editZone($this->request->post['zone_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('localisation/zone');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'localisation/zone')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('customer/customer');
|
||||
$this->load->model('localisation/geo_zone');
|
||||
|
||||
foreach ($selected as $zone_id) {
|
||||
if ($this->config->get('config_zone_id') == $zone_id) {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
$store_total = $this->model_setting_store->getTotalStoresByZoneId($zone_id);
|
||||
|
||||
if ($store_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_store'), $store_total);
|
||||
}
|
||||
|
||||
$address_total = $this->model_customer_customer->getTotalAddressesByZoneId($zone_id);
|
||||
|
||||
if ($address_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_address'), $address_total);
|
||||
}
|
||||
|
||||
$zone_to_geo_zone_total = $this->model_localisation_geo_zone->getTotalZoneToGeoZoneByZoneId($zone_id);
|
||||
|
||||
if ($zone_to_geo_zone_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_zone_to_geo_zone'), $zone_to_geo_zone_total);
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('localisation/zone');
|
||||
|
||||
foreach ($selected as $zone_id) {
|
||||
$this->model_localisation_zone->deleteZone($zone_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
174
admininistrator/controller/mail/affiliate.php
Normal file
174
admininistrator/controller/mail/affiliate.php
Normal file
@ -0,0 +1,174 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Affiliate
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Affiliate extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function approve(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$customer_id = (int)$args[0];
|
||||
} else {
|
||||
$customer_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/affiliate_approve', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
|
||||
|
||||
$data['login'] = $store_url . 'index.php?route=affiliate/login';
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($customer_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/affiliate_approve', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deny(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$customer_id = (int)$args[0];
|
||||
} else {
|
||||
$customer_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/affiliate_deny', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
|
||||
|
||||
$data['contact'] = $store_url . 'index.php?route=information/contact';
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($customer_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/affiliate_deny', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
119
admininistrator/controller/mail/authorize.php
Normal file
119
admininistrator/controller/mail/authorize.php
Normal file
@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Authorize
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Authorize extends \Opencart\System\Engine\Controller {
|
||||
// admin/model/user/user/editCode/after
|
||||
/**
|
||||
* @param $route
|
||||
* @param $args
|
||||
* @param $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(&$route, &$args, &$output) {
|
||||
if (isset($this->request->get['route'])) {
|
||||
$route = (string)$this->request->get['route'];
|
||||
} else {
|
||||
$route = '';
|
||||
}
|
||||
|
||||
$email = $this->user->getEmail();
|
||||
|
||||
if (isset($this->session->data['code'])) {
|
||||
$code = $this->session->data['code'];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if ($email && $code && ($route == 'common/authorize.send') && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$this->load->language('mail/authorize');
|
||||
|
||||
$data['username'] = $this->user->getUsername();
|
||||
$data['code'] = $code;
|
||||
$data['ip'] = $this->request->server['REMOTE_ADDR'];
|
||||
$data['store'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($email);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($this->config->get('config_name'));
|
||||
$mail->setSubject($this->language->get('text_subject'));
|
||||
$mail->setText($this->load->view('mail/authorize', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// admin/model/user/user/editCode/after
|
||||
|
||||
/**
|
||||
* @param $route
|
||||
* @param $args
|
||||
* @param $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function reset(&$route, &$args, &$output) {
|
||||
if (isset($this->request->get['route'])) {
|
||||
$route = $this->request->get['route'];
|
||||
} else {
|
||||
$route = '';
|
||||
}
|
||||
|
||||
if (isset($args[0])) {
|
||||
$email = (string)$args[0];
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$code = (string)$args[1];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if ($email && $code && ($route == 'common/authorize.confirm') && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$this->load->language('mail/authorize_reset');
|
||||
|
||||
$data['username'] = $this->user->getUsername();
|
||||
$data['reset'] = $this->url->link('common/authorize.reset', 'email=' . $email . '&code=' . $code, true);
|
||||
$data['ip'] = $this->request->server['REMOTE_ADDR'];
|
||||
$data['store'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($email);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($this->config->get('config_name'));
|
||||
$mail->setSubject($this->language->get('text_subject'));
|
||||
$mail->setText($this->load->view('mail/authorize_reset', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
198
admininistrator/controller/mail/customer.php
Normal file
198
admininistrator/controller/mail/customer.php
Normal file
@ -0,0 +1,198 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Customer
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Customer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function approve(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$customer_id = (int)$args[0];
|
||||
} else {
|
||||
$customer_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/customer_approve', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . $store_logo)) {
|
||||
$data['logo'] = $store_url . 'image/' . $store_logo;
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
|
||||
|
||||
$data['login'] = $store_url . 'index.php?route=account/login';
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($customer_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/customer_approve', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deny(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$customer_id = (int)$args[0];
|
||||
} else {
|
||||
$customer_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $customer_info['store_id']), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/customer_deny', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . $store_logo)) {
|
||||
$data['logo'] = $store_url . 'image/' . $store_logo;
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$data['text_welcome'] = sprintf($this->language->get('mail_text_welcome'), $store_name);
|
||||
|
||||
$data['contact'] = $store_url . 'index.php?route=information/contact';
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($customer_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/customer_deny', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
74
admininistrator/controller/mail/forgotten.php
Normal file
74
admininistrator/controller/mail/forgotten.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Forgotten
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Forgotten extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
*
|
||||
* admin/model/user/user/editCode/after
|
||||
*
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($this->request->get['route'])) {
|
||||
$route = (string)$this->request->get['route'];
|
||||
} else {
|
||||
$route = '';
|
||||
}
|
||||
|
||||
if (isset($args[0])) {
|
||||
$email = urldecode((string)$args[0]);
|
||||
} else {
|
||||
$email = '';
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$code = (string)$args[1];
|
||||
} else {
|
||||
$code = '';
|
||||
}
|
||||
|
||||
if ($email && $code && ($route == 'common/forgotten.confirm') && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$this->load->language('mail/forgotten');
|
||||
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$subject = sprintf($this->language->get('text_subject'), $store_name);
|
||||
|
||||
$data['text_greeting'] = sprintf($this->language->get('text_greeting'), $store_name);
|
||||
|
||||
$data['reset'] = $this->url->link('common/forgotten.reset', 'email=' . $email . '&code=' . $code, true);
|
||||
$data['ip'] = $this->request->server['REMOTE_ADDR'];
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $this->config->get('config_store_url');
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($email);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/forgotten', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
493
admininistrator/controller/mail/gdpr.php
Normal file
493
admininistrator/controller/mail/gdpr.php
Normal file
@ -0,0 +1,493 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Gdpr
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Gdpr extends \Opencart\System\Engine\Controller {
|
||||
// admin/model/customer/gdpr/editStatus
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(string &$route, array &$args, mixed &$output): void {
|
||||
$this->load->model('customer/gdpr');
|
||||
|
||||
$gdpr_info = $this->model_customer_gdpr->getGdpr($args[0]);
|
||||
|
||||
if ($gdpr_info) {
|
||||
// Choose which mail to send
|
||||
|
||||
// Export plus complete
|
||||
if ($gdpr_info['action'] == 'export' && (int)$args[1] == 3) {
|
||||
$this->export($gdpr_info);
|
||||
}
|
||||
|
||||
// Approve plus processing
|
||||
if ($gdpr_info['action'] == 'approve' && (int)$args[1] == 2) {
|
||||
$this->approve($gdpr_info);
|
||||
}
|
||||
|
||||
// Remove plus complete
|
||||
if ($gdpr_info['action'] == 'remove' && (int)$args[1] == 3) {
|
||||
$this->remove($gdpr_info);
|
||||
}
|
||||
|
||||
// Deny
|
||||
if ($args[1] == -1) {
|
||||
$this->deny($gdpr_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $gdpr_info
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function export(array $gdpr_info): void {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
// Send the email in the correct language
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/gdpr_export', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
if (is_file(DIR_IMAGE . $store_logo)) {
|
||||
$data['logo'] = $store_url . 'image/' . $store_logo;
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
|
||||
|
||||
if ($customer_info) {
|
||||
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
|
||||
}
|
||||
|
||||
// Personal info
|
||||
if ($customer_info) {
|
||||
$data['customer_id'] = $customer_info['customer_id'];
|
||||
$data['firstname'] = $customer_info['firstname'];
|
||||
$data['lastname'] = $customer_info['lastname'];
|
||||
$data['email'] = $customer_info['email'];
|
||||
$data['telephone'] = $customer_info['telephone'];
|
||||
}
|
||||
|
||||
// Addresses
|
||||
$data['addresses'] = [];
|
||||
|
||||
if ($customer_info) {
|
||||
$results = $this->model_customer_customer->getAddresses($customer_info['customer_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$address = [
|
||||
'firstname' => $result['firstname'],
|
||||
'lastname' => $result['lastname'],
|
||||
'address_1' => $result['address_1'],
|
||||
'address_2' => $result['address_2'],
|
||||
'city' => $result['city'],
|
||||
'postcode' => $result['postcode'],
|
||||
'country' => $result['country'],
|
||||
'zone' => $result['zone']
|
||||
];
|
||||
|
||||
if (!in_array($address, $data['addresses'])) {
|
||||
$data['addresses'][] = $address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Order Addresses
|
||||
$this->load->model('sale/order');
|
||||
|
||||
$results = $this->model_sale_order->getOrders(['filter_email' => $gdpr_info['email']]);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$order_info = $this->model_sale_order->getOrder($result['order_id']);
|
||||
|
||||
if ($order_info['payment_country_id']) {
|
||||
$address = [
|
||||
'firstname' => $order_info['payment_firstname'],
|
||||
'lastname' => $order_info['payment_lastname'],
|
||||
'address_1' => $order_info['payment_address_1'],
|
||||
'address_2' => $order_info['payment_address_2'],
|
||||
'city' => $order_info['payment_city'],
|
||||
'postcode' => $order_info['payment_postcode'],
|
||||
'country' => $order_info['payment_country'],
|
||||
'zone' => $order_info['payment_zone']
|
||||
];
|
||||
|
||||
if (!in_array($address, $data['addresses'])) {
|
||||
$data['addresses'][] = $address;
|
||||
}
|
||||
}
|
||||
|
||||
if ($order_info['shipping_country_id']) {
|
||||
$address = [
|
||||
'firstname' => $order_info['shipping_firstname'],
|
||||
'lastname' => $order_info['shipping_lastname'],
|
||||
'address_1' => $order_info['shipping_address_1'],
|
||||
'address_2' => $order_info['shipping_address_2'],
|
||||
'city' => $order_info['shipping_city'],
|
||||
'postcode' => $order_info['shipping_postcode'],
|
||||
'country' => $order_info['shipping_country'],
|
||||
'zone' => $order_info['shipping_zone']
|
||||
];
|
||||
|
||||
if (!in_array($address, $data['addresses'])) {
|
||||
$data['addresses'][] = $address;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ip's
|
||||
$data['ips'] = [];
|
||||
|
||||
if ($customer_info) {
|
||||
$results = $this->model_customer_customer->getIps($customer_info['customer_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['ips'][] = [
|
||||
'ip' => $result['ip'],
|
||||
'date_added' => date($this->language->get('mail_datetime_format'), strtotime($result['date_added']))
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data['store_name'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($gdpr_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/gdpr_export', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $gdpr_info
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function approve(array $gdpr_info): void {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
// Send the email in the correct language
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/gdpr_approve', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . $store_logo)) {
|
||||
$data['logo'] = $store_url . 'image/' . $store_logo;
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
|
||||
|
||||
if ($customer_info) {
|
||||
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
|
||||
}
|
||||
|
||||
$data['text_gdpr'] = sprintf($this->language->get('mail_text_gdpr'), $this->config->get('config_gdpr_limit'));
|
||||
$data['text_a'] = sprintf($this->language->get('mail_text_a'), $this->config->get('config_gdpr_limit'));
|
||||
|
||||
$data['store_name'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($gdpr_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/gdpr_approve', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $gdpr_info
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function deny(array $gdpr_info): void {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
// Send the email in the correct language
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/gdpr_deny', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . $store_logo)) {
|
||||
$data['logo'] = $store_url . 'image/' . $store_logo;
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$data['text_request'] = $this->language->get('mail_text_' . $gdpr_info['action']);
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
|
||||
|
||||
if ($customer_info) {
|
||||
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
|
||||
}
|
||||
|
||||
$data['store_name'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
$data['contact'] = $store_url . 'index.php?route=information/contact';
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($gdpr_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/gdpr_deny', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $gdpr_info
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function remove(array $gdpr_info): void {
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
// Send the email in the correct language
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/gdpr_delete', 'mail', $language_code);
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (is_file(DIR_IMAGE . $store_logo)) {
|
||||
$data['logo'] = $store_url . 'image/' . $store_logo;
|
||||
} else {
|
||||
$data['logo'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
|
||||
|
||||
if ($customer_info) {
|
||||
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
|
||||
} else {
|
||||
$data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
|
||||
}
|
||||
|
||||
$data['store_name'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
$data['contact'] = $store_url . 'index.php?route=information/contact';
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($gdpr_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/gdpr_delete', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
104
admininistrator/controller/mail/returns.php
Normal file
104
admininistrator/controller/mail/returns.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Returns
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Returns extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$return_id = $args[0];
|
||||
} else {
|
||||
$return_id = '';
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$return_status_id = $args[1];
|
||||
} else {
|
||||
$return_status_id = '';
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$comment = $args[2];
|
||||
} else {
|
||||
$comment = '';
|
||||
}
|
||||
|
||||
if (isset($args[3])) {
|
||||
$notify = $args[3];
|
||||
} else {
|
||||
$notify = '';
|
||||
}
|
||||
|
||||
if ($notify) {
|
||||
$this->load->model('sale/returns');
|
||||
|
||||
$return_info = $this->model_sale_returns->getReturn($return_id);
|
||||
|
||||
if ($return_info) {
|
||||
$this->load->model('sale/order');
|
||||
|
||||
$order_info = $this->model_sale_order->getOrder($return_info['order_id']);
|
||||
|
||||
if ($order_info) {
|
||||
$store_name = html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $order_info['store_url'];
|
||||
} else {
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($return_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/returns', 'mail', $language_code);
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name, $return_id);
|
||||
|
||||
$data['return_id'] = $return_id;
|
||||
$data['date_added'] = date($this->language->get('date_format_short'), strtotime($return_info['date_modified']));
|
||||
$data['return_status'] = $return_info['return_status'];
|
||||
$data['comment'] = nl2br($comment);
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($return_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/returns', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
102
admininistrator/controller/mail/reward.php
Normal file
102
admininistrator/controller/mail/reward.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Reward
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Reward extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(string $route, array $args, mixed $output): void {
|
||||
if (isset($args[0])) {
|
||||
$customer_id = (int)$args[0];
|
||||
} else {
|
||||
$customer_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$description = (string)$args[1];
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$points = (int)$args[2];
|
||||
} else {
|
||||
$points = 0;
|
||||
}
|
||||
|
||||
if (isset($args[3])) {
|
||||
$order_id = (int)$args[3];
|
||||
} else {
|
||||
$order_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->language('mail/reward');
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['url'];
|
||||
} else {
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/reward', 'mail', $language_code);
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$data['text_received'] = sprintf($this->language->get('mail_text_received'), $points);
|
||||
$data['text_total'] = sprintf($this->language->get('mail_text_total'), $this->model_customer_customer->getRewardTotal($customer_id));
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($customer_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/reward', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
284
admininistrator/controller/mail/subscription.php
Normal file
284
admininistrator/controller/mail/subscription.php
Normal file
@ -0,0 +1,284 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Subscription
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Subscription extends \Opencart\System\Engine\Controller {
|
||||
// admin/controller/sale/subscription/addHistory/after
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function history(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$subscription_id = $args[0];
|
||||
} else {
|
||||
$subscription_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$subscription_status_id = $args[1];
|
||||
} else {
|
||||
$subscription_status_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$comment = $args[2];
|
||||
} else {
|
||||
$comment = '';
|
||||
}
|
||||
|
||||
if (isset($args[3])) {
|
||||
$notify = $args[3];
|
||||
} else {
|
||||
$notify = '';
|
||||
}
|
||||
|
||||
// Subscription
|
||||
$this->load->model('sale/subscription');
|
||||
|
||||
$filter_data = [
|
||||
'filter_subscription_id' => $subscription_id,
|
||||
'filter_subscription_status_id' => $subscription_status_id,
|
||||
'filter_date_next' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$subscriptions = $this->model_checkout_subscription->getSubscriptions($filter_data);
|
||||
|
||||
if ($subscriptions) {
|
||||
foreach ($subscriptions as $subscription) {
|
||||
// Subscription histories
|
||||
$history_total = $this->model_sale_subscription->getTotalHistoriesBySubscriptionStatusId($subscription_status_id);
|
||||
|
||||
// The charge() method handles the subscription statuses in the cron/subscription
|
||||
// controller from the catalog whereas an extension needs to return the active subscription status
|
||||
if ($history_total && $subscription['subscription_status_id'] == $subscription_status_id) {
|
||||
// Subscription Statuses
|
||||
$this->load->model('localisation/subscription_status');
|
||||
|
||||
$subscription_status_info = $this->model_localisation_subscription_status->getSubscriptionStatus($subscription_status_id);
|
||||
|
||||
if ($subscription_status_info) {
|
||||
// Customers
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
// Customer payment
|
||||
$customer_payment_info = $this->model_customer_customer->getPaymentMehod($subscription['customer_id'], $subscription['customer_payment_id']);
|
||||
|
||||
if ($customer_payment_info) {
|
||||
// Since the customer payment is integrated into the customer/customer page,
|
||||
// we need to gather the customer's information rather than the order
|
||||
$customer_info = $this->model_customer_customer->getCustomer($subscription['customer_id']);
|
||||
|
||||
if ($customer_info) {
|
||||
// Settings
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
// Store
|
||||
$store_info = $this->model_setting_setting->getSetting('config', $customer_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$from = $store_info['config_email'];
|
||||
$store_name = $store_info['config_name'];
|
||||
$store_url = $store_info['config_url'];
|
||||
$alert_email = $store_info['config_mail_alert_email'];
|
||||
} else {
|
||||
$from = $this->config->get('config_email');
|
||||
$store_name = $this->config->get('config_name');
|
||||
$store_url = HTTP_CATALOG;
|
||||
$alert_email = $this->config->get('config_mail_alert_email');
|
||||
}
|
||||
|
||||
// Languages
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
if ($comment && $notify) {
|
||||
$data['comment'] = nl2br($comment);
|
||||
} else {
|
||||
$data['comment'] = '';
|
||||
}
|
||||
|
||||
$data['subscription_status'] = $subscription_status_info['name'];
|
||||
|
||||
// Languages
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
// Load the language for any mails using a different country code and prefixing it so it does not pollute the main data pool.
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/subscription', 'mail', $language_code);
|
||||
|
||||
$data['date_added'] = date($this->language->get('mail_date_format_short'), $subscription['date_added']);
|
||||
|
||||
// Text
|
||||
$data['text_comment'] = $this->language->get('mail_text_comment');
|
||||
$data['text_date_added'] = $this->language->get('mail_text_date_added');
|
||||
$data['text_footer'] = $this->language->get('mail_text_footer');
|
||||
$data['text_subscription_status'] = $this->language->get('mail_text_subscription_status');
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'));
|
||||
$mail->parameter = $this->config->get('config_mail_parameter');
|
||||
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
|
||||
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
|
||||
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
|
||||
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
|
||||
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
|
||||
|
||||
$mail->setTo($customer_info['email']);
|
||||
$mail->setFrom($from);
|
||||
$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setSubject(html_entity_decode(sprintf($this->language->get('mail_text_subject'), $store_name), ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setText($this->load->view('mail/subscription_history', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// admin/controller/sale/subscription/addTransaction/after
|
||||
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function transaction(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$subscription_id = $args[0];
|
||||
} else {
|
||||
$subscription_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$order_id = $args[1];
|
||||
} else {
|
||||
$order_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$comment = $args[2];
|
||||
} else {
|
||||
$comment = '';
|
||||
}
|
||||
|
||||
if (isset($args[3])) {
|
||||
$amount = $args[3];
|
||||
} else {
|
||||
$amount = '';
|
||||
}
|
||||
|
||||
if (isset($args[4])) {
|
||||
$type = $args[4];
|
||||
} else {
|
||||
$type = '';
|
||||
}
|
||||
|
||||
if (isset($args[5])) {
|
||||
$payment_method = $args[5];
|
||||
} else {
|
||||
$payment_method = '';
|
||||
}
|
||||
|
||||
if (isset($args[6])) {
|
||||
$payment_code = $args[6];
|
||||
} else {
|
||||
$payment_code = '';
|
||||
}
|
||||
|
||||
// Subscription
|
||||
$this->load->model('sale/subscription');
|
||||
|
||||
$filter_data = [
|
||||
'filter_subscription_id' => $subscription_id,
|
||||
'filter_subscription_status_id' => $this->config->get('config_subscription_canceled_status_id'),
|
||||
'filter_date_next' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
$subscriptions = $this->model_checkout_subscription->getSubscriptions($filter_data);
|
||||
|
||||
if ($subscriptions) {
|
||||
foreach ($subscriptions as $subscription) {
|
||||
$transaction_total = $this->model_sale_subscription->getTotalTransactions($subscription_id);
|
||||
|
||||
if ($transaction_total) {
|
||||
// Orders
|
||||
$this->load->model('sale/order');
|
||||
|
||||
$order_info = $this->model_sale_order->getOrder($order_id);
|
||||
|
||||
// In this case, since we're canceling a subscription,
|
||||
// the order ID needs to be identical
|
||||
if ($order_info && $subscription['order_id'] == $order_info['order_id']) {
|
||||
// Same for the payment method
|
||||
if ($order_info['payment_method'] == $subscription['payment_method'] && $subscription['payment_method'] == $payment_method) {
|
||||
// Same for the payment code
|
||||
if ($order_info['payment_code'] == $subscription['payment_code'] && $subscription['payment_code'] == $payment_code) {
|
||||
$this->load->language('mail/subscription');
|
||||
|
||||
// Store
|
||||
$from = $this->config->get('config_email');
|
||||
$store_name = $this->config->get('config_name');
|
||||
$store_url = HTTP_CATALOG;
|
||||
$alert_email = $this->config->get('config_mail_alert_email');
|
||||
|
||||
if ($comment) {
|
||||
$data['comment'] = nl2br($comment);
|
||||
} else {
|
||||
$data['comment'] = '';
|
||||
}
|
||||
|
||||
$data['subscription_id'] = $subscription_id;
|
||||
$data['payment_method'] = $payment_method;
|
||||
$data['payment_code'] = $payment_code;
|
||||
|
||||
$data['date_added'] = date($this->language->get('date_format_short'), $subscription['date_added']);
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'));
|
||||
$mail->parameter = $this->config->get('config_mail_parameter');
|
||||
$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
|
||||
$mail->smtp_username = $this->config->get('config_mail_smtp_username');
|
||||
$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
|
||||
$mail->smtp_port = $this->config->get('config_mail_smtp_port');
|
||||
$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
|
||||
|
||||
$mail->setTo($from);
|
||||
$mail->setFrom($from);
|
||||
$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setSubject(html_entity_decode(sprintf($this->language->get('text_subject'), $store_name), ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setText($this->load->view('mail/subscription_canceled', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
102
admininistrator/controller/mail/transaction.php
Normal file
102
admininistrator/controller/mail/transaction.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Transaction
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Transaction extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param string $route
|
||||
* @param array $args
|
||||
* @param mixed $output
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(string &$route, array &$args, mixed &$output): void {
|
||||
if (isset($args[0])) {
|
||||
$customer_id = $args[0];
|
||||
} else {
|
||||
$customer_id = 0;
|
||||
}
|
||||
|
||||
if (isset($args[1])) {
|
||||
$description = $args[1];
|
||||
} else {
|
||||
$description = '';
|
||||
}
|
||||
|
||||
if (isset($args[2])) {
|
||||
$amount = $args[2];
|
||||
} else {
|
||||
$amount = 0;
|
||||
}
|
||||
|
||||
if (isset($args[3])) {
|
||||
$order_id = $args[3];
|
||||
} else {
|
||||
$order_id = 0;
|
||||
}
|
||||
|
||||
$this->load->model('customer/customer');
|
||||
|
||||
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
|
||||
|
||||
if ($customer_info) {
|
||||
$this->load->language('mail/transaction');
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($customer_info['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $store_info['store_url'];
|
||||
} else {
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
$store_url = $this->config->get('config_url');
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($customer_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/transaction', 'mail', $language_code);
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
||||
|
||||
$data['text_received'] = sprintf($this->language->get('mail_text_received'), $this->currency->format($amount, $this->config->get('config_currency')));
|
||||
$data['text_total'] = sprintf($this->language->get('mail_text_total'), $this->currency->format($this->model_customer_customer->getTransactionTotal($customer_id), $this->config->get('config_currency')));
|
||||
|
||||
$data['store'] = $store_name;
|
||||
$data['store_url'] = $store_url;
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($customer_info['email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/transaction', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
130
admininistrator/controller/mail/voucher.php
Normal file
130
admininistrator/controller/mail/voucher.php
Normal file
@ -0,0 +1,130 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Mail;
|
||||
/**
|
||||
* Class Voucher
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Mail
|
||||
*/
|
||||
class Voucher extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @param int $voucher_id
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function index(int $voucher_id): void {
|
||||
$this->load->model('sale/order');
|
||||
|
||||
$voucher_info = $this->model_sale_voucher->getVoucher($voucher_id);
|
||||
|
||||
if ($voucher_info) {
|
||||
// If voucher does not belong to an order
|
||||
$this->load->language('mail/voucher');
|
||||
|
||||
if ($voucher_info['order_id']) {
|
||||
$order_id = $voucher_info['order_id'];
|
||||
} else {
|
||||
$order_id = 0;
|
||||
}
|
||||
|
||||
$order_info = $this->model_sale_order->getOrder($order_id);
|
||||
|
||||
// If voucher belongs to an order
|
||||
if ($order_info) {
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$language_info = $this->model_localisation_language->getLanguage($order_info['language_id']);
|
||||
|
||||
if ($language_info) {
|
||||
$language_code = $language_info['code'];
|
||||
} else {
|
||||
$language_code = $this->config->get('config_language');
|
||||
}
|
||||
|
||||
$this->load->language('default', 'mail', $language_code);
|
||||
$this->load->language('mail/voucher', 'mail', $language_code);
|
||||
|
||||
$store_name = html_entity_decode($order_info['store_name'], ENT_QUOTES, 'UTF-8');
|
||||
|
||||
// Add language vars to the template folder
|
||||
$results = $this->language->all('mail');
|
||||
|
||||
foreach ($results as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
|
||||
$from_name = html_entity_decode($voucher_info['from_name'], ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$subject = sprintf($this->language->get('mail_text_subject'), $from_name);
|
||||
|
||||
// HTML Mail
|
||||
$data['title'] = sprintf($this->language->get('mail_text_subject'), $from_name);
|
||||
|
||||
$data['text_greeting'] = sprintf($this->language->get('mail_text_greeting'), $this->currency->format($voucher_info['amount'], (!empty($order_info['currency_code']) ? $order_info['currency_code'] : $this->config->get('config_currency')), (!empty($order_info['currency_value']) ? $order_info['currency_value'] : $this->currency->getValue($this->config->get('config_currency')))));
|
||||
$data['text_from'] = sprintf($this->language->get('mail_text_from'), $from_name);
|
||||
$data['text_redeem'] = sprintf($this->language->get('mail_text_redeem'), $voucher_info['code']);
|
||||
|
||||
$this->load->model('sale/voucher_theme');
|
||||
|
||||
$voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']);
|
||||
|
||||
if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) {
|
||||
$data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$data['message'] = nl2br($voucher_info['message']);
|
||||
|
||||
$data['store_name'] = $store_name;
|
||||
$data['store_url'] = $order_info['store_url'];
|
||||
} else {
|
||||
$store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$from_name = html_entity_decode($voucher_info['from_name'], ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$subject = html_entity_decode(sprintf($this->language->get('text_subject'), $from_name), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
$data['title'] = sprintf($this->language->get('text_subject'), $from_name);
|
||||
|
||||
$data['text_greeting'] = sprintf($this->language->get('text_greeting'), $this->currency->format($voucher_info['amount'], $this->config->get('config_currency')));
|
||||
$data['text_from'] = sprintf($this->language->get('text_from'), $from_name);
|
||||
$data['text_redeem'] = sprintf($this->language->get('text_redeem'), $voucher_info['code']);
|
||||
|
||||
$this->load->model('sale/voucher_theme');
|
||||
|
||||
$voucher_theme_info = $this->model_sale_voucher_theme->getVoucherTheme($voucher_info['voucher_theme_id']);
|
||||
|
||||
if ($voucher_theme_info && is_file(DIR_IMAGE . $voucher_theme_info['image'])) {
|
||||
$data['image'] = HTTP_CATALOG . 'image/' . $voucher_theme_info['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$data['message'] = nl2br($voucher_info['message']);
|
||||
|
||||
$data['store_name'] = $store_name;
|
||||
$data['store_url'] = HTTP_CATALOG;
|
||||
}
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
$mail->setTo($voucher_info['to_email']);
|
||||
$mail->setFrom($this->config->get('config_email'));
|
||||
$mail->setSender($store_name);
|
||||
$mail->setSubject($subject);
|
||||
$mail->setHtml($this->load->view('mail/voucher', $data));
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1059
admininistrator/controller/marketing/affiliate.php
Normal file
1059
admininistrator/controller/marketing/affiliate.php
Normal file
File diff suppressed because it is too large
Load Diff
256
admininistrator/controller/marketing/contact.php
Normal file
256
admininistrator/controller/marketing/contact.php
Normal file
@ -0,0 +1,256 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketing;
|
||||
/**
|
||||
* Class Contact
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketing
|
||||
*/
|
||||
class Contact extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('marketing/contact');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->document->addScript('view/javascript/ckeditor/ckeditor.js');
|
||||
$this->document->addScript('view/javascript/ckeditor/adapters/jquery.js');
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$data['stores'] = $this->model_setting_store->getStores();
|
||||
|
||||
$this->load->model('customer/customer_group');
|
||||
|
||||
$data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();
|
||||
|
||||
$data['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('marketing/contact', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function send(): void {
|
||||
$this->load->language('marketing/contact');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketing/contact')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$this->request->post['subject']) {
|
||||
$json['error']['subject'] = $this->language->get('error_subject');
|
||||
}
|
||||
|
||||
if (!$this->request->post['message']) {
|
||||
$json['error']['message'] = $this->language->get('error_message');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/store');
|
||||
$this->load->model('setting/setting');
|
||||
$this->load->model('customer/customer');
|
||||
$this->load->model('sale/order');
|
||||
|
||||
$store_info = $this->model_setting_store->getStore($this->request->post['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store_name = $store_info['name'];
|
||||
} else {
|
||||
$store_name = $this->config->get('config_name');
|
||||
}
|
||||
|
||||
$setting = $this->model_setting_setting->getSetting('config', $this->request->post['store_id']);
|
||||
|
||||
$store_email = isset($setting['config_email']) ? $setting['config_email'] : $this->config->get('config_email');
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$limit = 10;
|
||||
|
||||
$email_total = 0;
|
||||
|
||||
$emails = [];
|
||||
|
||||
switch ($this->request->post['to']) {
|
||||
case 'newsletter':
|
||||
$customer_data = [
|
||||
'filter_newsletter' => 1,
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$email_total = $this->model_customer_customer->getTotalCustomers($customer_data);
|
||||
|
||||
$results = $this->model_customer_customer->getCustomers($customer_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$emails[] = $result['email'];
|
||||
}
|
||||
break;
|
||||
case 'customer_all':
|
||||
$customer_data = [
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$email_total = $this->model_customer_customer->getTotalCustomers($customer_data);
|
||||
|
||||
$results = $this->model_customer_customer->getCustomers($customer_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$emails[] = $result['email'];
|
||||
}
|
||||
break;
|
||||
case 'customer_group':
|
||||
$customer_data = [
|
||||
'filter_customer_group_id' => $this->request->post['customer_group_id'],
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$email_total = $this->model_customer_customer->getTotalCustomers($customer_data);
|
||||
|
||||
$results = $this->model_customer_customer->getCustomers($customer_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$emails[$result['customer_id']] = $result['email'];
|
||||
}
|
||||
break;
|
||||
case 'customer':
|
||||
if (!empty($this->request->post['customer'])) {
|
||||
$email_total = count($this->request->post['customer']);
|
||||
|
||||
$customers = array_slice($this->request->post['customer'], ($page - 1) * $limit, $limit);
|
||||
|
||||
foreach ($customers as $customer_id) {
|
||||
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
|
||||
|
||||
if ($customer_info) {
|
||||
$emails[] = $customer_info['email'];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'affiliate_all':
|
||||
$affiliate_data = [
|
||||
'filter_affiliate' => 1,
|
||||
'start' => ($page - 1) * $limit,
|
||||
'limit' => $limit
|
||||
];
|
||||
|
||||
$email_total = $this->model_customer_customer->getTotalCustomers($affiliate_data);
|
||||
|
||||
$results = $this->model_customer_customer->getCustomers($affiliate_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$emails[] = $result['email'];
|
||||
}
|
||||
break;
|
||||
case 'affiliate':
|
||||
if (!empty($this->request->post['affiliate'])) {
|
||||
$affiliates = array_slice($this->request->post['affiliate'], ($page - 1) * $limit, $limit);
|
||||
|
||||
foreach ($affiliates as $affiliate_id) {
|
||||
$affiliate_info = $this->model_customer_customer->getCustomer($affiliate_id);
|
||||
|
||||
if ($affiliate_info) {
|
||||
$emails[] = $affiliate_info['email'];
|
||||
}
|
||||
}
|
||||
|
||||
$email_total = count($this->request->post['affiliate']);
|
||||
}
|
||||
break;
|
||||
case 'product':
|
||||
if (isset($this->request->post['product'])) {
|
||||
$email_total = $this->model_sale_order->getTotalEmailsByProductsOrdered($this->request->post['product']);
|
||||
|
||||
$results = $this->model_sale_order->getEmailsByProductsOrdered($this->request->post['product'], ($page - 1) * $limit, $limit);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$emails[] = $result['email'];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if ($emails) {
|
||||
$start = ($page - 1) * $limit;
|
||||
$end = $start + $limit;
|
||||
|
||||
if ($end < $email_total) {
|
||||
$json['text'] = sprintf($this->language->get('text_sent'), $start ? $start : 1, $email_total);
|
||||
|
||||
$json['next'] = $this->url->link('marketing/contact.send', 'user_token=' . $this->session->data['user_token'] . '&page=' . ($page + 1), true);
|
||||
} else {
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
|
||||
$json['next'] = '';
|
||||
}
|
||||
|
||||
$message = '<html dir="ltr" lang="' . $this->language->get('code') . '">' . "\n";
|
||||
$message .= ' <head>' . "\n";
|
||||
$message .= ' <title>' . $this->request->post['subject'] . '</title>' . "\n";
|
||||
$message .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
|
||||
$message .= ' </head>' . "\n";
|
||||
$message .= ' <body>' . html_entity_decode($this->request->post['message'], ENT_QUOTES, 'UTF-8') . '</body>' . "\n";
|
||||
$message .= '</html>' . "\n";
|
||||
|
||||
if ($this->config->get('config_mail_engine')) {
|
||||
$mail_option = [
|
||||
'parameter' => $this->config->get('config_mail_parameter'),
|
||||
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
||||
'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
||||
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
||||
'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
||||
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
||||
];
|
||||
|
||||
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
||||
|
||||
foreach ($emails as $email) {
|
||||
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
$mail->setTo(trim($email));
|
||||
$mail->setFrom($store_email);
|
||||
$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setSubject(html_entity_decode($this->request->post['subject'], ENT_QUOTES, 'UTF-8'));
|
||||
$mail->setHtml($message);
|
||||
$mail->send();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$json['error']['warning'] = $this->language->get('error_email');
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
481
admininistrator/controller/marketing/coupon.php
Normal file
481
admininistrator/controller/marketing/coupon.php
Normal file
@ -0,0 +1,481 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketing;
|
||||
/**
|
||||
* Class Coupon
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketing
|
||||
*/
|
||||
class Coupon extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('marketing/coupon');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('marketing/coupon.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('marketing/coupon.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$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('marketing/coupon', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('marketing/coupon');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['coupons'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
$coupon_total = $this->model_marketing_coupon->getTotalCoupons();
|
||||
|
||||
$results = $this->model_marketing_coupon->getCoupons($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['coupons'][] = [
|
||||
'coupon_id' => $result['coupon_id'],
|
||||
'name' => $result['name'],
|
||||
'code' => $result['code'],
|
||||
'discount' => $result['discount'],
|
||||
'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])),
|
||||
'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])),
|
||||
'status' => $result['status'],
|
||||
'edit' => $this->url->link('marketing/coupon.form', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $result['coupon_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
$data['sort_code'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url);
|
||||
$data['sort_discount'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=discount' . $url);
|
||||
$data['sort_date_start'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=date_start' . $url);
|
||||
$data['sort_date_end'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=date_end' . $url);
|
||||
$data['sort_status'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $coupon_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($coupon_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($coupon_total - $this->config->get('config_pagination_admin'))) ? $coupon_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $coupon_total, ceil($coupon_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('marketing/coupon_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('marketing/coupon');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['coupon_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('marketing/coupon.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['coupon_id'])) {
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
$coupon_info = $this->model_marketing_coupon->getCoupon($this->request->get['coupon_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['coupon_id'])) {
|
||||
$data['coupon_id'] = (int)$this->request->get['coupon_id'];
|
||||
} else {
|
||||
$data['coupon_id'] = 0;
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['name'] = $coupon_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['code'] = $coupon_info['code'];
|
||||
} else {
|
||||
$data['code'] = '';
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['type'] = $coupon_info['type'];
|
||||
} else {
|
||||
$data['type'] = '';
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['discount'] = $coupon_info['discount'];
|
||||
} else {
|
||||
$data['discount'] = '';
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['logged'] = $coupon_info['logged'];
|
||||
} else {
|
||||
$data['logged'] = '';
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['shipping'] = $coupon_info['shipping'];
|
||||
} else {
|
||||
$data['shipping'] = '';
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['total'] = $coupon_info['total'];
|
||||
} else {
|
||||
$data['total'] = '';
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$products = $this->model_marketing_coupon->getProducts($this->request->get['coupon_id']);
|
||||
} else {
|
||||
$products = [];
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
$data['coupon_products'] = [];
|
||||
|
||||
foreach ($products as $product_id) {
|
||||
$product_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if ($product_info) {
|
||||
$data['coupon_products'][] = [
|
||||
'product_id' => $product_info['product_id'],
|
||||
'name' => $product_info['name']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$categories = $this->model_marketing_coupon->getCategories($this->request->get['coupon_id']);
|
||||
} else {
|
||||
$categories = [];
|
||||
}
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$data['coupon_categories'] = [];
|
||||
|
||||
foreach ($categories as $category_id) {
|
||||
$category_info = $this->model_catalog_category->getCategory($category_id);
|
||||
|
||||
if ($category_info) {
|
||||
$data['coupon_categories'][] = [
|
||||
'category_id' => $category_info['category_id'],
|
||||
'name' => ($category_info['path'] ? $category_info['path'] . ' > ' : '') . $category_info['name']
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['date_start'] = ($coupon_info['date_start'] != '0000-00-00' ? $coupon_info['date_start'] : '');
|
||||
} else {
|
||||
$data['date_start'] = date('Y-m-d', time());
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['date_end'] = ($coupon_info['date_end'] != '0000-00-00' ? $coupon_info['date_end'] : '');
|
||||
} else {
|
||||
$data['date_end'] = date('Y-m-d', strtotime('+1 month'));
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['uses_total'] = $coupon_info['uses_total'];
|
||||
} else {
|
||||
$data['uses_total'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['uses_customer'] = $coupon_info['uses_customer'];
|
||||
} else {
|
||||
$data['uses_customer'] = 1;
|
||||
}
|
||||
|
||||
if (!empty($coupon_info)) {
|
||||
$data['status'] = $coupon_info['status'];
|
||||
} else {
|
||||
$data['status'] = true;
|
||||
}
|
||||
|
||||
$data['history'] = $this->getHistory();
|
||||
|
||||
$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('marketing/coupon_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('marketing/coupon');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketing/coupon')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 128)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['code']) < 3) || (oc_strlen($this->request->post['code']) > 20)) {
|
||||
$json['error']['code'] = $this->language->get('error_code');
|
||||
}
|
||||
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
$coupon_info = $this->model_marketing_coupon->getCouponByCode($this->request->post['code']);
|
||||
|
||||
if ($coupon_info) {
|
||||
if (!isset($this->request->post['coupon_id'])) {
|
||||
$json['error']['warning'] = $this->language->get('error_exists');
|
||||
} elseif ($coupon_info['coupon_id'] != (int)$this->request->post['coupon_id']) {
|
||||
$json['error']['warning'] = $this->language->get('error_exists');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if (!$this->request->post['coupon_id']) {
|
||||
$json['coupon_id'] = $this->model_marketing_coupon->addCoupon($this->request->post);
|
||||
} else {
|
||||
$this->model_marketing_coupon->editCoupon($this->request->post['coupon_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('marketing/coupon');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketing/coupon')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
foreach ($selected as $coupon_id) {
|
||||
$this->model_marketing_coupon->deleteCoupon($coupon_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function history(): void {
|
||||
$this->load->language('marketing/coupon');
|
||||
|
||||
$this->response->setOutput($this->getHistory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getHistory(): string {
|
||||
if (isset($this->request->get['coupon_id'])) {
|
||||
$coupon_id = (int)$this->request->get['coupon_id'];
|
||||
} else {
|
||||
$coupon_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page']) && $this->request->get['route'] == 'marketing/coupon.history') {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$limit = 10;
|
||||
|
||||
$this->load->model('marketing/coupon');
|
||||
|
||||
$data['histories'] = [];
|
||||
|
||||
$results = $this->model_marketing_coupon->getHistories($coupon_id, ($page - 1) * $limit, $limit);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['histories'][] = [
|
||||
'order_id' => $result['order_id'],
|
||||
'customer' => $result['customer'],
|
||||
'amount' => $result['amount'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
|
||||
];
|
||||
}
|
||||
|
||||
$history_total = $this->model_marketing_coupon->getTotalHistories($coupon_id);
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $history_total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('marketing/coupon.history', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $coupon_id . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($history_total - $limit)) ? $history_total : ((($page - 1) * $limit) + $limit), $history_total, ceil($history_total / $limit));
|
||||
|
||||
return $this->load->view('marketing/coupon_history', $data);
|
||||
}
|
||||
}
|
530
admininistrator/controller/marketing/marketing.php
Normal file
530
admininistrator/controller/marketing/marketing.php
Normal file
@ -0,0 +1,530 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketing;
|
||||
/**
|
||||
* Class Marketing
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketing
|
||||
*/
|
||||
class Marketing extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('marketing/marketing');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$filter_name = $this->request->get['filter_name'];
|
||||
} else {
|
||||
$filter_name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$filter_code = $this->request->get['filter_code'];
|
||||
} else {
|
||||
$filter_code = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$filter_date_from = $this->request->get['filter_date_from'];
|
||||
} else {
|
||||
$filter_date_from = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$filter_date_to = $this->request->get['filter_date_to'];
|
||||
} else {
|
||||
$filter_date_to = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . $this->request->get['filter_code'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['add'] = $this->url->link('marketing/marketing.form', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
$data['delete'] = $this->url->link('marketing/marketing.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$data['filter_name'] = $filter_name;
|
||||
$data['filter_code'] = $filter_code;
|
||||
$data['filter_date_from'] = $filter_date_from;
|
||||
$data['filter_date_to'] = $filter_date_to;
|
||||
|
||||
$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('marketing/marketing', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('marketing/marketing');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getList(): string {
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$filter_name = $this->request->get['filter_name'];
|
||||
} else {
|
||||
$filter_name = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$filter_code = $this->request->get['filter_code'];
|
||||
} else {
|
||||
$filter_code = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$filter_date_from = (string)$this->request->get['filter_date_from'];
|
||||
} else {
|
||||
$filter_date_from = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$filter_date_to = (string)$this->request->get['filter_date_to'];
|
||||
} else {
|
||||
$filter_date_to = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'm.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . $this->request->get['filter_code'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['marketings'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_name' => $filter_name,
|
||||
'filter_code' => $filter_code,
|
||||
'filter_date_from' => $filter_date_from,
|
||||
'filter_date_to' => $filter_date_to,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('marketing/marketing');
|
||||
|
||||
$marketing_total = $this->model_marketing_marketing->getTotalMarketings($filter_data);
|
||||
|
||||
$results = $this->model_marketing_marketing->getMarketings($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['marketings'][] = [
|
||||
'marketing_id' => $result['marketing_id'],
|
||||
'name' => $result['name'],
|
||||
'code' => $result['code'],
|
||||
'clicks' => $result['clicks'],
|
||||
'orders' => $result['orders'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'edit' => $this->url->link('marketing/marketing.form', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $result['marketing_id'] . $url)
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . $this->request->get['filter_code'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . '&sort=m.name' . $url);
|
||||
$data['sort_code'] = $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . '&sort=m.code' . $url);
|
||||
$data['sort_date_added'] = $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . '&sort=m.date_added' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . $this->request->get['filter_code'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $marketing_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($marketing_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($marketing_total - $this->config->get('config_pagination_admin'))) ? $marketing_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $marketing_total, ceil($marketing_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('marketing/marketing_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function form(): void {
|
||||
$this->load->language('marketing/marketing');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['text_form'] = !isset($this->request->get['marketing_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_code'])) {
|
||||
$url .= '&filter_code=' . $this->request->get['filter_code'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_from'])) {
|
||||
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_to'])) {
|
||||
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['save'] = $this->url->link('marketing/marketing.save', 'user_token=' . $this->session->data['user_token']);
|
||||
$data['back'] = $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
if (isset($this->request->get['marketing_id'])) {
|
||||
$this->load->model('marketing/marketing');
|
||||
|
||||
$marketing_info = $this->model_marketing_marketing->getMarketing($this->request->get['marketing_id']);
|
||||
}
|
||||
|
||||
if (isset($this->request->get['marketing_id'])) {
|
||||
$data['marketing_id'] = (int)$this->request->get['marketing_id'];
|
||||
} else {
|
||||
$data['marketing_id'] = 0;
|
||||
}
|
||||
|
||||
$data['store'] = HTTP_CATALOG;
|
||||
|
||||
if (!empty($marketing_info)) {
|
||||
$data['name'] = $marketing_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($marketing_info)) {
|
||||
$data['description'] = $marketing_info['description'];
|
||||
} else {
|
||||
$data['description'] = '';
|
||||
}
|
||||
|
||||
if (!empty($marketing_info)) {
|
||||
$data['code'] = $marketing_info['code'];
|
||||
} else {
|
||||
$data['code'] = uniqid();
|
||||
}
|
||||
|
||||
$data['report'] = $this->getReport();
|
||||
|
||||
$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('marketing/marketing_form', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('marketing/marketing');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketing/marketing')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((oc_strlen($this->request->post['name']) < 1) || (oc_strlen($this->request->post['name']) > 32)) {
|
||||
$json['error']['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if (!$this->request->post['code']) {
|
||||
$json['error']['code'] = $this->language->get('error_code');
|
||||
}
|
||||
|
||||
$this->load->model('marketing/marketing');
|
||||
|
||||
$marketing_info = $this->model_marketing_marketing->getMarketingByCode($this->request->post['code']);
|
||||
|
||||
if ($marketing_info && (!isset($this->request->post['marketing_id']) || ($this->request->post['marketing_id'] != $marketing_info['marketing_id']))) {
|
||||
$json['error']['code'] = $this->language->get('error_exists');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if (!$this->request->post['marketing_id']) {
|
||||
$json['marketing_id'] = $this->model_marketing_marketing->addMarketing($this->request->post);
|
||||
} else {
|
||||
$this->model_marketing_marketing->editMarketing($this->request->post['marketing_id'], $this->request->post);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('marketing/marketing');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = $this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketing/marketing')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('marketing/marketing');
|
||||
|
||||
foreach ($selected as $marketing_id) {
|
||||
$this->model_marketing_marketing->deleteMarketing($marketing_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function report(): void {
|
||||
$this->load->language('marketing/marketing');
|
||||
|
||||
$this->response->setOutput($this->getReport());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReport(): string {
|
||||
if (isset($this->request->get['marketing_id'])) {
|
||||
$marketing_id = (int)$this->request->get['marketing_id'];
|
||||
} else {
|
||||
$marketing_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page']) && $this->request->get['route'] == 'marketing/marketing.report') {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$limit = 10;
|
||||
|
||||
$data['reports'] = [];
|
||||
|
||||
$this->load->model('marketing/marketing');
|
||||
$this->load->model('customer/customer');
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$results = $this->model_marketing_marketing->getReports($marketing_id, ($page - 1) * $limit, $limit);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$store_info = $this->model_setting_store->getStore($result['store_id']);
|
||||
|
||||
if ($store_info) {
|
||||
$store = $store_info['name'];
|
||||
} elseif (!$result['store_id']) {
|
||||
$store = $this->config->get('config_name');
|
||||
} else {
|
||||
$store = '';
|
||||
}
|
||||
|
||||
$data['reports'][] = [
|
||||
'ip' => $result['ip'],
|
||||
'account' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']),
|
||||
'store' => $store,
|
||||
'country' => $result['country'],
|
||||
'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])),
|
||||
'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip'])
|
||||
];
|
||||
}
|
||||
|
||||
$report_total = $this->model_marketing_marketing->getTotalReports($marketing_id);
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $report_total,
|
||||
'page' => $page,
|
||||
'limit' => $limit,
|
||||
'url' => $this->url->link('marketing/marketing.report', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $marketing_id . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($report_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($report_total - $limit)) ? $report_total : ((($page - 1) * $limit) + $limit), $report_total, ceil($report_total / $limit));
|
||||
|
||||
return $this->load->view('marketing/marketing_report', $data);
|
||||
}
|
||||
}
|
51
admininistrator/controller/marketplace/api.php
Normal file
51
admininistrator/controller/marketplace/api.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketplace;
|
||||
/**
|
||||
* Class API
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketplace
|
||||
*/
|
||||
class Api extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('marketplace/api');
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->response->setOutput($this->load->view('marketplace/api', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function save(): void {
|
||||
$this->load->language('marketplace/api');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/api')) {
|
||||
$json['error']['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$this->request->post['opencart_username']) {
|
||||
$json['error']['username'] = $this->language->get('error_username');
|
||||
}
|
||||
|
||||
if (!$this->request->post['opencart_secret']) {
|
||||
$json['error']['secret'] = $this->language->get('error_secret');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/setting');
|
||||
|
||||
$this->model_setting_setting->editSetting('opencart', $this->request->post);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
310
admininistrator/controller/marketplace/cron.php
Normal file
310
admininistrator/controller/marketplace/cron.php
Normal file
@ -0,0 +1,310 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketplace;
|
||||
/**
|
||||
* Class Cron
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketplace
|
||||
*/
|
||||
class Cron extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('marketplace/cron');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketplace/cron', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['delete'] = $this->url->link('marketplace/cron.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
// Example cron URL
|
||||
$data['cron'] = HTTP_CATALOG . 'index.php?route=cron/cron';
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('marketplace/cron', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('marketplace/cron');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'code';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('marketplace/cron.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['crons'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('setting/cron');
|
||||
|
||||
$cron_total = $this->model_setting_cron->getTotalCrons();
|
||||
|
||||
$results = $this->model_setting_cron->getCrons($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['crons'][] = [
|
||||
'cron_id' => $result['cron_id'],
|
||||
'code' => $result['code'],
|
||||
'description' => $result['description'],
|
||||
'cycle' => $this->language->get('text_' . $result['cycle']),
|
||||
'action' => $result['action'],
|
||||
'status' => $result['status'],
|
||||
'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])),
|
||||
'date_modified' => date($this->language->get('datetime_format'), strtotime($result['date_modified'])),
|
||||
'run' => $this->url->link('marketplace/cron.run', 'user_token=' . $this->session->data['user_token'] . '&cron_id=' . $result['cron_id']),
|
||||
'enable' => $this->url->link('marketplace/cron.enable', 'user_token=' . $this->session->data['user_token'] . '&cron_id=' . $result['cron_id']),
|
||||
'disable' => $this->url->link('marketplace/cron.disable', 'user_token=' . $this->session->data['user_token'] . '&cron_id=' . $result['cron_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_code'] = $this->url->link('marketplace/cron.list', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url);
|
||||
$data['sort_cycle'] = $this->url->link('marketplace/cron.list', 'user_token=' . $this->session->data['user_token'] . '&sort=cycle' . $url);
|
||||
$data['sort_action'] = $this->url->link('marketplace/cron.list', 'user_token=' . $this->session->data['user_token'] . '&sort=action' . $url);
|
||||
$data['sort_date_added'] = $this->url->link('marketplace/cron.list', 'user_token=' . $this->session->data['user_token'] . '&sort=date_added' . $url);
|
||||
$data['sort_date_modified'] = $this->url->link('marketplace/cron.list', 'user_token=' . $this->session->data['user_token'] . '&sort=date_modified' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $cron_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('marketplace/cron.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($cron_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($cron_total - $this->config->get('config_pagination_admin'))) ? $cron_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $cron_total, ceil($cron_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('marketplace/cron_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function run(): void {
|
||||
$this->load->language('marketplace/cron');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['cron_id'])) {
|
||||
$cron_id = (int)$this->request->get['cron_id'];
|
||||
} else {
|
||||
$cron_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/cron')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/cron');
|
||||
|
||||
$cron_info = $this->model_setting_cron->getCron($cron_id);
|
||||
|
||||
if ($cron_info) {
|
||||
// Create a store instance using loader class to call controllers, models, views, libraries
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$store = $this->model_setting_store->createStoreInstance(0, $this->config->get('config_language'));
|
||||
|
||||
$store->load->controller($cron_info['action'], $cron_id, $cron_info['code'], $cron_info['cycle'], $cron_info['date_added'], $cron_info['date_modified']);
|
||||
|
||||
$store->session->destroy($store->session->getId());
|
||||
|
||||
$this->model_setting_cron->editCron($cron_info['cron_id']);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function enable(): void {
|
||||
$this->load->language('marketplace/cron');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['cron_id'])) {
|
||||
$cron_id = (int)$this->request->get['cron_id'];
|
||||
} else {
|
||||
$cron_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/cron')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/cron');
|
||||
|
||||
$this->model_setting_cron->editStatus($cron_id, 1);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function disable(): void {
|
||||
$this->load->language('marketplace/cron');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['cron_id'])) {
|
||||
$cron_id = (int)$this->request->get['cron_id'];
|
||||
} else {
|
||||
$cron_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/cron')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/cron');
|
||||
|
||||
$this->model_setting_cron->editStatus($cron_id, 0);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('marketplace/cron');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/event')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/cron');
|
||||
|
||||
foreach ($selected as $cron_id) {
|
||||
$this->model_setting_cron->deleteCron($cron_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
259
admininistrator/controller/marketplace/event.php
Normal file
259
admininistrator/controller/marketplace/event.php
Normal file
@ -0,0 +1,259 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketplace;
|
||||
/**
|
||||
* Class Event
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketplace
|
||||
*/
|
||||
class Event extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('marketplace/event');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketplace/event', 'user_token=' . $this->session->data['user_token'] . $url)
|
||||
];
|
||||
|
||||
$data['delete'] = $this->url->link('marketplace/event.delete', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('marketplace/event', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('marketplace/event');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'code';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['action'] = $this->url->link('marketplace/event.list', 'user_token=' . $this->session->data['user_token'] . $url);
|
||||
|
||||
$data['events'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$this->load->model('setting/event');
|
||||
|
||||
$event_total = $this->model_setting_event->getTotalEvents();
|
||||
|
||||
$results = $this->model_setting_event->getEvents($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['events'][] = [
|
||||
'event_id' => $result['event_id'],
|
||||
'code' => $result['code'],
|
||||
'description' => $result['description'],
|
||||
'trigger' => $result['trigger'],
|
||||
'action' => $result['action'],
|
||||
'status' => $result['status'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'enable' => $this->url->link('marketplace/event.enable', 'user_token=' . $this->session->data['user_token'] . '&event_id=' . $result['event_id']),
|
||||
'disable' => $this->url->link('marketplace/event.disable', 'user_token=' . $this->session->data['user_token'] . '&event_id=' . $result['event_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_code'] = $this->url->link('marketplace/event.list', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url);
|
||||
$data['sort_sort_order'] = $this->url->link('marketplace/event.list', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $event_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('marketplace/event.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($event_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($event_total - $this->config->get('config_pagination_admin'))) ? $event_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $event_total, ceil($event_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('marketplace/event_list', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function enable(): void {
|
||||
$this->load->language('marketplace/event');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['event_id'])) {
|
||||
$event_id = (int)$this->request->get['event_id'];
|
||||
} else {
|
||||
$event_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/event')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/event');
|
||||
|
||||
$this->model_setting_event->editStatus($event_id, 1);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function disable(): void {
|
||||
$this->load->language('marketplace/event');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['event_id'])) {
|
||||
$event_id = (int)$this->request->get['event_id'];
|
||||
} else {
|
||||
$event_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/event')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/event');
|
||||
|
||||
$this->model_setting_event->editStatus($event_id, 0);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('marketplace/event');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$selected = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$selected = [];
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/event')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$this->load->model('setting/event');
|
||||
|
||||
foreach ($selected as $event_id) {
|
||||
$this->model_setting_event->deleteEvent($event_id);
|
||||
}
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
73
admininistrator/controller/marketplace/extension.php
Normal file
73
admininistrator/controller/marketplace/extension.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketplace;
|
||||
/**
|
||||
* Class Extension
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketplace
|
||||
*/
|
||||
class Extension extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('marketplace/extension');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
if (isset($this->request->get['type'])) {
|
||||
$data['type'] = $this->request->get['type'];
|
||||
} else {
|
||||
$data['type'] = '';
|
||||
}
|
||||
|
||||
$data['categories'] = [];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$files = glob(DIR_APPLICATION . 'controller/extension/*.php');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$extension = basename($file, '.php');
|
||||
|
||||
$this->load->language('extension/' . $extension, $extension);
|
||||
|
||||
if ($this->user->hasPermission('access', 'extension/' . $extension)) {
|
||||
$extensions = $this->model_setting_extension->getPaths('%/admin/controller/' . $extension . '/%.php');
|
||||
|
||||
$data['categories'][] = [
|
||||
'code' => $extension,
|
||||
'text' => $this->language->get($extension . '_heading_title') . ' (' . count($extensions) . ')',
|
||||
'href' => $this->url->link('extension/' . $extension, 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->get['type'])) {
|
||||
$data['extension'] = $this->load->controller('extension/' . basename($this->request->get['type']) . '.getList');
|
||||
} elseif ($data['categories']) {
|
||||
$data['extension'] = $this->load->controller('extension/' . $data['categories'][0]['code'] . '.getList');
|
||||
} else {
|
||||
$data['extension'] = '';
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('marketplace/extension', $data));
|
||||
}
|
||||
}
|
715
admininistrator/controller/marketplace/installer.php
Normal file
715
admininistrator/controller/marketplace/installer.php
Normal file
@ -0,0 +1,715 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketplace;
|
||||
/**
|
||||
* Class Installer
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketplace
|
||||
*/
|
||||
class Installer extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function index(): void {
|
||||
$this->load->language('marketplace/installer');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$data['breadcrumbs'] = [];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
$data['breadcrumbs'][] = [
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('marketplace/installer', 'user_token=' . $this->session->data['user_token'])
|
||||
];
|
||||
|
||||
// Use the for the max file size
|
||||
$data['error_upload_size'] = sprintf($this->language->get('error_file_size'), ini_get('upload_max_filesize'));
|
||||
|
||||
$data['config_file_max_size'] = ((int)preg_filter('/[^0-9]/', '', ini_get('upload_max_filesize')) * 1024 * 1024);
|
||||
|
||||
$data['upload'] = $this->url->link('tool/installer.upload', 'user_token=' . $this->session->data['user_token']);
|
||||
|
||||
$data['list'] = $this->getList();
|
||||
|
||||
if (isset($this->request->get['filter_extension_id'])) {
|
||||
$data['filter_extension_download_id'] = (int)$this->request->get['filter_extension_download_id'];
|
||||
} else {
|
||||
$data['filter_extension_download_id'] = '';
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('marketplace/installer', $data));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function list(): void {
|
||||
$this->load->language('marketplace/cron');
|
||||
|
||||
$this->response->setOutput($this->getList());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getList(): string {
|
||||
$this->load->language('marketplace/installer');
|
||||
|
||||
if (isset($this->request->get['filter_extension_download_id'])) {
|
||||
$filter_extension_download_id = (int)$this->request->get['filter_extension_download_id'];
|
||||
} else {
|
||||
$filter_extension_download_id = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = (string)$this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = (string)$this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
// Look for any new extensions
|
||||
$files = glob(DIR_STORAGE . 'marketplace/*.ocmod.zip');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$code = basename($file, '.ocmod.zip');
|
||||
|
||||
$install_info = $this->model_setting_extension->getInstallByCode($code);
|
||||
|
||||
if (!$install_info) {
|
||||
// Unzip the files
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
if ($zip->open($file, \ZipArchive::RDONLY)) {
|
||||
$install_info = json_decode($zip->getFromName('install.json'), true);
|
||||
|
||||
if ($install_info) {
|
||||
$extension_data = [
|
||||
'extension_id' => 0,
|
||||
'extension_download_id' => 0,
|
||||
'name' => $install_info['name'],
|
||||
'code' => $code,
|
||||
'version' => $install_info['version'],
|
||||
'author' => $install_info['author'],
|
||||
'link' => $install_info['link']
|
||||
];
|
||||
|
||||
$this->model_setting_extension->addInstall($extension_data);
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
$filter_data = [
|
||||
'filter_extension_download_id' => $filter_extension_download_id,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
||||
'limit' => $this->config->get('config_pagination_admin')
|
||||
];
|
||||
|
||||
$extension_total = $this->model_setting_extension->getTotalInstalls($filter_data);
|
||||
|
||||
$results = $this->model_setting_extension->getInstalls($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($result['extension_id']) {
|
||||
$link = $this->url->link('marketplace/marketplace.info', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id']);
|
||||
} elseif ($result['link']) {
|
||||
$link = $result['link'];
|
||||
} else {
|
||||
$link = '';
|
||||
}
|
||||
|
||||
$data['extensions'][] = [
|
||||
'name' => $result['name'],
|
||||
'version' => $result['version'],
|
||||
'author' => $result['author'],
|
||||
'status' => $result['status'],
|
||||
'link' => $link,
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'install' => $this->url->link('marketplace/installer.install', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $result['extension_install_id']),
|
||||
'uninstall' => $this->url->link('marketplace/installer.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $result['extension_install_id']),
|
||||
'delete' => $this->url->link('marketplace/installer.delete', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $result['extension_install_id'])
|
||||
];
|
||||
}
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($extension_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($extension_total - $this->config->get('config_pagination_admin'))) ? $extension_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $extension_total, ceil($extension_total / $this->config->get('config_pagination_admin')));
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_extension_id'])) {
|
||||
$url .= '&filter_extension_id=' . $this->request->get['filter_extension_id'];
|
||||
}
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('marketplace/installer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
|
||||
$data['sort_version'] = $this->url->link('marketplace/installer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=version' . $url);
|
||||
$data['sort_date_added'] = $this->url->link('marketplace/installer.list', 'user_token=' . $this->session->data['user_token'] . '&sort=date_added' . $url);
|
||||
|
||||
$data['pagination'] = $this->load->controller('common/pagination', [
|
||||
'total' => $extension_total,
|
||||
'page' => $page,
|
||||
'limit' => $this->config->get('config_pagination_admin'),
|
||||
'url' => $this->url->link('marketplace/installer.list', 'user_token=' . $this->session->data['user_token'] . '&page={page}')
|
||||
]);
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
return $this->load->view('marketplace/installer_extension', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function upload(): void {
|
||||
$this->load->language('marketplace/installer');
|
||||
|
||||
$json = [];
|
||||
|
||||
// 1. Validate the file uploaded.
|
||||
if (isset($this->request->files['file']['name'])) {
|
||||
$filename = basename($this->request->files['file']['name']);
|
||||
|
||||
// 2. Validate the filename.
|
||||
if ((oc_strlen($filename) < 1) || (oc_strlen($filename) > 128)) {
|
||||
$json['error'] = $this->language->get('error_filename');
|
||||
}
|
||||
|
||||
// 3. Validate is ocmod file.
|
||||
if (substr($filename, -10) != '.ocmod.zip') {
|
||||
$json['error'] = $this->language->get('error_file_type');
|
||||
}
|
||||
|
||||
// 4. check if there is already a file
|
||||
$file = DIR_STORAGE . 'marketplace/' . $filename;
|
||||
|
||||
if (is_file($file)) {
|
||||
$json['error'] = $this->language->get('error_file_exists');
|
||||
|
||||
unlink($this->request->files['file']['tmp_name']);
|
||||
}
|
||||
|
||||
if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
|
||||
$json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
|
||||
}
|
||||
|
||||
if ($this->model_setting_extension->getInstallByCode(basename($filename, '.ocmod.zip'))) {
|
||||
$json['error'] = $this->language->get('error_installed');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_upload');
|
||||
}
|
||||
|
||||
// 5. Validate if the file can be opened and there is install.json that can be read.
|
||||
if (!$json) {
|
||||
move_uploaded_file($this->request->files['file']['tmp_name'], $file);
|
||||
|
||||
// Unzip the files
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
if ($zip->open($file, \ZipArchive::RDONLY)) {
|
||||
$install_info = json_decode($zip->getFromName('install.json'), true);
|
||||
|
||||
if ($install_info) {
|
||||
if (!$install_info['name']) {
|
||||
$json['error'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if (!$install_info['version']) {
|
||||
$json['error'] = $this->language->get('error_version');
|
||||
}
|
||||
|
||||
if (!$install_info['author']) {
|
||||
$json['error'] = $this->language->get('error_author');
|
||||
}
|
||||
|
||||
if (!$install_info['link']) {
|
||||
$json['error'] = $this->language->get('error_link');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_install');
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_unzip');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$extension_data = [
|
||||
'extension_id' => 0,
|
||||
'extension_download_id' => 0,
|
||||
'name' => $install_info['name'],
|
||||
'code' => basename($filename, '.ocmod.zip'),
|
||||
'version' => $install_info['version'],
|
||||
'author' => $install_info['author'],
|
||||
'link' => $install_info['link']
|
||||
];
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$this->model_setting_extension->addInstall($extension_data);
|
||||
|
||||
$json['success'] = $this->language->get('text_upload');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function install(): void {
|
||||
$this->load->language('marketplace/installer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension_install_id'])) {
|
||||
$extension_install_id = (int)$this->request->get['extension_install_id'];
|
||||
} else {
|
||||
$extension_install_id = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/installer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extension_install_info = $this->model_setting_extension->getInstall($extension_install_id);
|
||||
|
||||
if ($extension_install_info) {
|
||||
$file = DIR_STORAGE . 'marketplace/' . $extension_install_info['code'] . '.ocmod.zip';
|
||||
|
||||
if (!is_file($file)) {
|
||||
$json['error'] = sprintf($this->language->get('error_file'), $extension_install_info['code'] . '.ocmod.zip');
|
||||
}
|
||||
|
||||
if ($page == 1 && is_dir(DIR_EXTENSION . $extension_install_info['code'] . '/')) {
|
||||
$json['error'] = sprintf($this->language->get('error_directory_exists'), $extension_install_info['code'] . '/');
|
||||
}
|
||||
|
||||
if ($page > 1 && !is_dir(DIR_EXTENSION . $extension_install_info['code'] . '/')) {
|
||||
$json['error'] = sprintf($this->language->get('error_directory'), $extension_install_info['code'] . '/');
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Unzip the files
|
||||
$zip = new \ZipArchive();
|
||||
|
||||
if ($zip->open($file)) {
|
||||
$total = $zip->numFiles;
|
||||
$limit = 200;
|
||||
|
||||
$start = ($page - 1) * $limit;
|
||||
$end = $start > ($total - $limit) ? $total : ($start + $limit);
|
||||
|
||||
// Check if any of the files already exist.
|
||||
for ($i = $start; $i < $end; $i++) {
|
||||
$source = $zip->getNameIndex($i);
|
||||
|
||||
$destination = str_replace('\\', '/', $source);
|
||||
|
||||
// Only extract the contents of the upload folder
|
||||
$path = $extension_install_info['code'] . '/' . $destination;
|
||||
$base = DIR_EXTENSION;
|
||||
$prefix = '';
|
||||
|
||||
// image > image
|
||||
if (substr($destination, 0, 6) == 'image/') {
|
||||
$path = $destination;
|
||||
$base = substr(DIR_IMAGE, 0, -6);
|
||||
}
|
||||
|
||||
// We need to store the path differently for vendor folders.
|
||||
if (substr($destination, 0, 15) == 'system/storage/') {
|
||||
$path = substr($destination, 15);
|
||||
$base = DIR_STORAGE;
|
||||
$prefix = 'system/storage/';
|
||||
}
|
||||
|
||||
// Must not have a path before files and directories can be moved
|
||||
$path_new = '';
|
||||
|
||||
$directories = explode('/', dirname($path));
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
if (!$path_new) {
|
||||
$path_new = $directory;
|
||||
} else {
|
||||
$path_new = $path_new . '/' . $directory;
|
||||
}
|
||||
|
||||
// To fix storage location
|
||||
if (!is_dir($base . $path_new . '/') && mkdir($base . $path_new . '/', 0777)) {
|
||||
$this->model_setting_extension->addPath($extension_install_id, $prefix . $path_new);
|
||||
}
|
||||
}
|
||||
|
||||
// If check if the path is not directory and check there is no existing file
|
||||
if (substr($source, -1) != '/') {
|
||||
if (!is_file($base . $path) && copy('zip://' . $file . '#' . $source, $base . $path)) {
|
||||
$this->model_setting_extension->addPath($extension_install_id, $prefix . $path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
$this->model_setting_extension->editStatus($extension_install_id, 1);
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_unzip');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$json['text'] = sprintf($this->language->get('text_progress'), 2, $total);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['extension_install_id'])) {
|
||||
$url .= '&extension_install_id=' . $this->request->get['extension_install_id'];
|
||||
}
|
||||
|
||||
if ($end < $total) {
|
||||
$json['next'] = $this->url->link('marketplace/installer.install', 'user_token=' . $this->session->data['user_token'] . $url . '&page=' . ($page + 1), true);
|
||||
} else {
|
||||
$json['next'] = $this->url->link('marketplace/installer.vendor', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
}
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function uninstall(): void {
|
||||
$this->load->language('marketplace/installer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension_install_id'])) {
|
||||
$extension_install_id = (int)$this->request->get['extension_install_id'];
|
||||
} else {
|
||||
$extension_install_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/installer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extension_install_info = $this->model_setting_extension->getInstall($extension_install_id);
|
||||
|
||||
if ($extension_install_info) {
|
||||
if ($extension_install_info['code'] == 'opencart') {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
// Validate if extension being uninstalled
|
||||
$extension_total = $this->model_setting_extension->getTotalExtensionsByExtension($extension_install_info['code']);
|
||||
|
||||
if ($extension_total) {
|
||||
$json['error'] = sprintf($this->language->get('error_uninstall'), $extension_total);
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$files = [];
|
||||
|
||||
// Make path into an array
|
||||
$directory = [DIR_EXTENSION . $extension_install_info['code'] . '/'];
|
||||
|
||||
// While the path array is still populated keep looping through
|
||||
while (count($directory) != 0) {
|
||||
$next = array_shift($directory);
|
||||
|
||||
if (is_dir($next)) {
|
||||
foreach (glob(rtrim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
// If directory add to path array
|
||||
$directory[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the file to the files to be deleted array
|
||||
$files[] = $next;
|
||||
}
|
||||
|
||||
// Reverse sort the file array
|
||||
rsort($files);
|
||||
|
||||
foreach ($files as $file) {
|
||||
// If file just delete
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
// If directory use the remove directory function
|
||||
if (is_dir($file)) {
|
||||
rmdir($file);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove extension directory and files
|
||||
$results = $this->model_setting_extension->getPathsByExtensionInstallId($extension_install_id);
|
||||
|
||||
rsort($results);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$path = '';
|
||||
|
||||
// Remove images
|
||||
if (substr($result['path'], 0, 6) == 'image/') {
|
||||
$path = DIR_IMAGE . substr($result['path'], 6);
|
||||
}
|
||||
|
||||
// Remove vendor files or any connected extensions that was also installed.
|
||||
if (substr($result['path'], 0, 15) == 'system/storage/') {
|
||||
$path = DIR_STORAGE . substr($result['path'], 15);
|
||||
}
|
||||
|
||||
// Check if the location exists or not
|
||||
$path_total = $this->model_setting_extension->getTotalPaths($result['path']);
|
||||
|
||||
if ($path_total < 2) {
|
||||
if (is_file($path)) {
|
||||
unlink($path);
|
||||
}
|
||||
|
||||
if (is_dir($path)) {
|
||||
rmdir($path);
|
||||
}
|
||||
}
|
||||
|
||||
$this->model_setting_extension->deletePath($result['extension_path_id']);
|
||||
}
|
||||
|
||||
// Remove extension directory
|
||||
$this->model_setting_extension->editStatus($extension_install_id, 0);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['extension_install_id'])) {
|
||||
$url .= '&extension_install_id=' . $this->request->get['extension_install_id'];
|
||||
}
|
||||
|
||||
$json['next'] = $this->url->link('marketplace/installer.vendor', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/* Generate new autoloader file */
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function vendor(): void {
|
||||
$this->load->language('marketplace/installer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/installer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
// Generate php autoload file
|
||||
$code = '<?php' . "\n";
|
||||
|
||||
$files = glob(DIR_STORAGE . 'vendor/*/*/composer.json');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$output = json_decode(file_get_contents($file), true);
|
||||
|
||||
$code .= '// ' . $output['name'] . "\n";
|
||||
|
||||
if (isset($output['autoload'])) {
|
||||
$directory = substr(dirname($file), strlen(DIR_STORAGE . 'vendor/'));
|
||||
|
||||
// Autoload psr-4 files
|
||||
if (isset($output['autoload']['psr-4'])) {
|
||||
$autoload = $output['autoload']['psr-4'];
|
||||
|
||||
foreach ($autoload as $namespace => $path) {
|
||||
if (!is_array($path)) {
|
||||
$code .= '$autoloader->register(\'' . rtrim($namespace, '\\') . '\', DIR_STORAGE . \'vendor/' . $directory . '/' . rtrim($path, '/') . '/' . '\', true);' . "\n";
|
||||
} else {
|
||||
foreach ($path as $value) {
|
||||
$code .= '$autoloader->register(\'' . rtrim($namespace, '\\') . '\', DIR_STORAGE . \'vendor/' . $directory . '/' . rtrim($value, '/') . '/' . '\', true);' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Autoload psr-0 files
|
||||
if (isset($output['autoload']['psr-0'])) {
|
||||
$autoload = $output['autoload']['psr-0'];
|
||||
|
||||
foreach ($autoload as $namespace => $path) {
|
||||
if (!is_array($path)) {
|
||||
$code .= '$autoloader->register(\'' . rtrim($namespace, '\\') . '\', DIR_STORAGE . \'vendor/' . $directory . '/' . rtrim($path, '/') . '/' . '\', true);' . "\n";
|
||||
} else {
|
||||
foreach ($path as $value) {
|
||||
$code .= '$autoloader->register(\'' . rtrim($namespace, '\\') . '\', DIR_STORAGE . \'vendor/' . $directory . '/' . rtrim($value, '/') . '/' . '\', true);' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Autoload classmap
|
||||
if (isset($output['autoload']['classmap'])) {
|
||||
$autoload = [];
|
||||
|
||||
$classmaps = $output['autoload']['classmap'];
|
||||
|
||||
foreach ($classmaps as $classmap) {
|
||||
$directories = [dirname($file) . '/' . $classmap];
|
||||
|
||||
while (count($directories) != 0) {
|
||||
$next = array_shift($directories);
|
||||
|
||||
if (is_dir($next)) {
|
||||
foreach (glob(trim($next, '/') . '/{*,.[!.]*,..?*}', GLOB_BRACE) as $file) {
|
||||
if (is_dir($file)) {
|
||||
$directories[] = $file . '/';
|
||||
}
|
||||
|
||||
if (is_file($file)) {
|
||||
$namespace = substr(dirname($file), strlen(DIR_STORAGE . 'vendor/' . $directory . $classmap) + 1);
|
||||
|
||||
if ($namespace) {
|
||||
$autoload[$namespace] = substr(dirname($file), strlen(DIR_STORAGE . 'vendor/'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($autoload as $namespace => $path) {
|
||||
$code .= '$autoloader->register(\'' . rtrim($namespace, '\\') . '\', DIR_STORAGE . \'vendor/' . rtrim($path, '/') . '/' . '\', true);' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Autoload files
|
||||
if (isset($output['autoload']['files'])) {
|
||||
$files = $output['autoload']['files'];
|
||||
|
||||
foreach ($files as $file) {
|
||||
$code .= 'require_once(DIR_STORAGE . \'vendor/' . $directory . '/' . $file . '\');' . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$code .= "\n";
|
||||
}
|
||||
|
||||
file_put_contents(DIR_SYSTEM . 'vendor.php', trim($code));
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function delete(): void {
|
||||
$this->load->language('marketplace/installer');
|
||||
|
||||
$json = [];
|
||||
|
||||
if (isset($this->request->get['extension_install_id'])) {
|
||||
$extension_install_id = (int)$this->request->get['extension_install_id'];
|
||||
} else {
|
||||
$extension_install_id = 0;
|
||||
}
|
||||
|
||||
if (!$this->user->hasPermission('modify', 'marketplace/installer')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
$extension_install_info = $this->model_setting_extension->getInstall($extension_install_id);
|
||||
|
||||
if ($extension_install_info && $extension_install_info['code'] == 'opencart') {
|
||||
$json['error'] = $this->language->get('error_default');
|
||||
}
|
||||
|
||||
if (!$extension_install_info) {
|
||||
$json['error'] = $this->language->get('error_extension');
|
||||
}
|
||||
|
||||
$extension_install_info = $this->model_setting_extension->getInstall($extension_install_id);
|
||||
|
||||
if (!$json) {
|
||||
$file = DIR_STORAGE . 'marketplace/' . $extension_install_info['code'] . '.ocmod.zip';
|
||||
|
||||
// Remove file
|
||||
if (is_file($file)) {
|
||||
unlink($file);
|
||||
}
|
||||
|
||||
$this->model_setting_extension->deleteInstall($extension_install_id);
|
||||
|
||||
$json['success'] = $this->language->get('text_success');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
1168
admininistrator/controller/marketplace/marketplace.php
Normal file
1168
admininistrator/controller/marketplace/marketplace.php
Normal file
File diff suppressed because it is too large
Load Diff
104
admininistrator/controller/marketplace/promotion.php
Normal file
104
admininistrator/controller/marketplace/promotion.php
Normal file
@ -0,0 +1,104 @@
|
||||
<?php
|
||||
namespace Opencart\Admin\Controller\Marketplace;
|
||||
/**
|
||||
* Class Promotion
|
||||
*
|
||||
* @package Opencart\Admin\Controller\Marketplace
|
||||
*/
|
||||
class Promotion extends \Opencart\System\Engine\Controller {
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function index(): string {
|
||||
$this->load->language('marketplace/promotion');
|
||||
|
||||
if (isset($this->request->get['type'])) {
|
||||
$type = $this->request->get['type'];
|
||||
} else {
|
||||
// Just in case there are any direct calls to methods we need to remove them to get the extension type
|
||||
$pos = strrpos($this->request->get['route'], '.');
|
||||
|
||||
if ($pos !== false) {
|
||||
$route = substr($this->request->get['route'], 0, $pos);
|
||||
} else {
|
||||
$route = $this->request->get['route'];
|
||||
}
|
||||
|
||||
$type = substr($route, strrpos($route, '/') + 1);
|
||||
}
|
||||
|
||||
$promotion = $this->cache->get('promotion.' . $type);
|
||||
|
||||
if (!$promotion) {
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt($curl, CURLOPT_URL, OPENCART_SERVER . 'index.php?route=api/recommended&type=' . $type . '&version=' . VERSION);
|
||||
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) {
|
||||
$promotion = json_decode($response, true);
|
||||
} else {
|
||||
$promotion = '';
|
||||
}
|
||||
|
||||
$this->cache->set('promotion.' . $type, $promotion, 3600 * 24);
|
||||
}
|
||||
|
||||
if (isset($promotion['banner'])) {
|
||||
$data['banner'] = $promotion['banner'];
|
||||
} else {
|
||||
$data['banner'] = '';
|
||||
}
|
||||
|
||||
$data['extensions'] = [];
|
||||
|
||||
if (isset($promotion['extensions'])) {
|
||||
$this->load->model('setting/extension');
|
||||
|
||||
foreach ($promotion['extensions'] as $result) {
|
||||
$extension_install_info = $this->model_setting_extension->getInstallByExtensionDownloadId($result['extension_download_id']);
|
||||
|
||||
// Download
|
||||
if (!$extension_install_info) {
|
||||
$download = $this->url->link('marketplace/marketplace.download', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id'] . '&extension_download_id=' . $result['extension_download_id']);
|
||||
} else {
|
||||
$download = '';
|
||||
}
|
||||
|
||||
// Install
|
||||
if ($extension_install_info && !$extension_install_info['status']) {
|
||||
$install = $this->url->link('marketplace/installer.install', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_info['extension_install_id']);
|
||||
} else {
|
||||
$install = '';
|
||||
}
|
||||
|
||||
// Delete
|
||||
if ($extension_install_info && !$extension_install_info['status']) {
|
||||
$delete = $this->url->link('marketplace/installer.delete', 'user_token=' . $this->session->data['user_token'] . '&extension_install_id=' . $extension_install_info['extension_install_id']);
|
||||
} else {
|
||||
$delete = '';
|
||||
}
|
||||
|
||||
if (!$extension_install_info || !$extension_install_info['status']) {
|
||||
$data['extensions'][] = [
|
||||
'name' => $result['name'],
|
||||
'href' => $this->url->link('marketplace/marketplace.info', 'user_token=' . $this->session->data['user_token'] . '&extension_id=' . $result['extension_id']),
|
||||
'download' => $download,
|
||||
'install' => $install,
|
||||
'delete' => $delete
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->load->view('marketplace/promotion', $data);
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user