first commit
This commit is contained in:
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));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user