first commit
This commit is contained in:
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
class ControllerCatalogAttribute extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_attribute->addAttribute($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_attribute->editAttribute($this->request->get['attribute_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/attribute');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $attribute_id) {
|
||||
$this->model_catalog_attribute->deleteAttribute($attribute_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'ad.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/attribute/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/attribute/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['attributes'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$attribute_total = $this->model_catalog_attribute->getTotalAttributes();
|
||||
|
||||
$results = $this->model_catalog_attribute->getAttributes($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['attributes'][] = array(
|
||||
'attribute_id' => $result['attribute_id'],
|
||||
'name' => $result['name'],
|
||||
'attribute_group' => $result['attribute_group'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/attribute/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_id=' . $result['attribute_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . '&sort=ad.name' . $url, true);
|
||||
$data['sort_attribute_group'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . '&sort=attribute_group' . $url, true);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . '&sort=a.sort_order' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $attribute_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($attribute_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($attribute_total - $this->config->get('config_limit_admin'))) ? $attribute_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $attribute_total, ceil($attribute_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/attribute_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['attribute_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['name'])) {
|
||||
$data['error_name'] = $this->error['name'];
|
||||
} else {
|
||||
$data['error_name'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['attribute_group'])) {
|
||||
$data['error_attribute_group'] = $this->error['attribute_group'];
|
||||
} else {
|
||||
$data['error_attribute_group'] = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['attribute_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/attribute/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/attribute/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_id=' . $this->request->get['attribute_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/attribute', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['attribute_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$attribute_info = $this->model_catalog_attribute->getAttribute($this->request->get['attribute_id']);
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->post['attribute_description'])) {
|
||||
$data['attribute_description'] = $this->request->post['attribute_description'];
|
||||
} elseif (isset($this->request->get['attribute_id'])) {
|
||||
$data['attribute_description'] = $this->model_catalog_attribute->getAttributeDescriptions($this->request->get['attribute_id']);
|
||||
} else {
|
||||
$data['attribute_description'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['attribute_group_id'])) {
|
||||
$data['attribute_group_id'] = $this->request->post['attribute_group_id'];
|
||||
} elseif (!empty($attribute_info)) {
|
||||
$data['attribute_group_id'] = $attribute_info['attribute_group_id'];
|
||||
} else {
|
||||
$data['attribute_group_id'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
$data['attribute_groups'] = $this->model_catalog_attribute_group->getAttributeGroups();
|
||||
|
||||
if (isset($this->request->post['sort_order'])) {
|
||||
$data['sort_order'] = $this->request->post['sort_order'];
|
||||
} elseif (!empty($attribute_info)) {
|
||||
$data['sort_order'] = $attribute_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/attribute_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/attribute')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$this->request->post['attribute_group_id']) {
|
||||
$this->error['attribute_group'] = $this->language->get('error_attribute_group');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['attribute_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 64)) {
|
||||
$this->error['name'][$language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/attribute')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($this->request->post['selected'] as $attribute_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByAttributeId($attribute_id);
|
||||
|
||||
if ($product_total) {
|
||||
$this->error['warning'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function autocomplete() {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
$filter_data = array(
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => $this->config->get('config_limit_autocomplete')
|
||||
);
|
||||
|
||||
$results = $this->model_catalog_attribute->getAttributes($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$json[] = array(
|
||||
'attribute_id' => $result['attribute_id'],
|
||||
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
|
||||
'attribute_group' => $result['attribute_group']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($json as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $json);
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,359 @@
|
||||
<?php
|
||||
class ControllerCatalogAttributeGroup extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_attribute_group->addAttributeGroup($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_attribute_group->editAttributeGroup($this->request->get['attribute_group_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/attribute_group');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/attribute_group');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $attribute_group_id) {
|
||||
$this->model_catalog_attribute_group->deleteAttributeGroup($attribute_group_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'agd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/attribute_group/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/attribute_group/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['attribute_groups'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$attribute_group_total = $this->model_catalog_attribute_group->getTotalAttributeGroups();
|
||||
|
||||
$results = $this->model_catalog_attribute_group->getAttributeGroups($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['attribute_groups'][] = array(
|
||||
'attribute_group_id' => $result['attribute_group_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/attribute_group/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_group_id=' . $result['attribute_group_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . '&sort=agd.name' . $url, true);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . '&sort=ag.sort_order' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $attribute_group_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($attribute_group_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($attribute_group_total - $this->config->get('config_limit_admin'))) ? $attribute_group_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $attribute_group_total, ceil($attribute_group_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/attribute_group_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['attribute_group_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['name'])) {
|
||||
$data['error_name'] = $this->error['name'];
|
||||
} else {
|
||||
$data['error_name'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['attribute_group_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/attribute_group/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/attribute_group/edit', 'user_token=' . $this->session->data['user_token'] . '&attribute_group_id=' . $this->request->get['attribute_group_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/attribute_group', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['attribute_group_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$attribute_group_info = $this->model_catalog_attribute_group->getAttributeGroup($this->request->get['attribute_group_id']);
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->post['attribute_group_description'])) {
|
||||
$data['attribute_group_description'] = $this->request->post['attribute_group_description'];
|
||||
} elseif (isset($this->request->get['attribute_group_id'])) {
|
||||
$data['attribute_group_description'] = $this->model_catalog_attribute_group->getAttributeGroupDescriptions($this->request->get['attribute_group_id']);
|
||||
} else {
|
||||
$data['attribute_group_description'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['sort_order'])) {
|
||||
$data['sort_order'] = $this->request->post['sort_order'];
|
||||
} elseif (!empty($attribute_group_info)) {
|
||||
$data['sort_order'] = $attribute_group_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/attribute_group_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['attribute_group_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 64)) {
|
||||
$this->error['name'][$language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/attribute_group')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/attribute');
|
||||
|
||||
foreach ($this->request->post['selected'] as $attribute_group_id) {
|
||||
$attribute_total = $this->model_catalog_attribute->getTotalAttributesByAttributeGroupId($attribute_group_id);
|
||||
|
||||
if ($attribute_total) {
|
||||
$this->error['warning'] = sprintf($this->language->get('error_attribute'), $attribute_total);
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,802 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerCatalogCategory extends Controller {
|
||||
private $error = array();
|
||||
private $category_id = 0;
|
||||
private $path = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_category->addCategory($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_category->editCategory($this->request->get['category_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $category_id) {
|
||||
$this->model_catalog_category->deleteCategory($category_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function repair() {
|
||||
$this->load->language('catalog/category');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
if ($this->validateRepair()) {
|
||||
$this->model_catalog_category->repairCategories();
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
$data['add'] = $this->url->link('catalog/category/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/category/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['repair'] = $this->url->link('catalog/category/repair', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['enabled'] = $this->url->link('catalog/category/enable', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['disabled'] = $this->url->link('catalog/category/disable', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['path'])) {
|
||||
if ($this->request->get['path'] != '') {
|
||||
$this->path = explode('_', $this->request->get['path']);
|
||||
$this->category_id = end($this->path);
|
||||
$this->session->data['path'] = $this->request->get['path'];
|
||||
} else {
|
||||
unset($this->session->data['path']);
|
||||
}
|
||||
} elseif (isset($this->session->data['path'])) {
|
||||
$this->path = explode('_', $this->session->data['path']);
|
||||
$this->category_id = end($this->path);
|
||||
}
|
||||
|
||||
$data['categories'] = $this->getCategories(0);
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
$category_total = $this->model_catalog_category->getTotalCategories();
|
||||
|
||||
$data['results'] = $this->language->get('text_category_total') . ($category_total);
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/category_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['category_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['name'])) {
|
||||
$data['error_name'] = $this->error['name'];
|
||||
} else {
|
||||
$data['error_name'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['meta_title'])) {
|
||||
$data['error_meta_title'] = $this->error['meta_title'];
|
||||
} else {
|
||||
$data['error_meta_title'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['meta_h1'])) {
|
||||
$data['error_meta_h1'] = $this->error['meta_h1'];
|
||||
} else {
|
||||
$data['error_meta_h1'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['keyword'])) {
|
||||
$data['error_keyword'] = $this->error['keyword'];
|
||||
} else {
|
||||
$data['error_keyword'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['parent'])) {
|
||||
$data['error_parent'] = $this->error['parent'];
|
||||
} else {
|
||||
$data['error_parent'] = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['category_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/category/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/category/edit', 'user_token=' . $this->session->data['user_token'] . '&category_id=' . $this->request->get['category_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['category_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$category_info = $this->model_catalog_category->getCategory($this->request->get['category_id']);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->post['category_description'])) {
|
||||
$data['category_description'] = $this->request->post['category_description'];
|
||||
} elseif (isset($this->request->get['category_id'])) {
|
||||
$data['category_description'] = $this->model_catalog_category->getCategoryDescriptions($this->request->get['category_id']);
|
||||
} else {
|
||||
$data['category_description'] = array();
|
||||
}
|
||||
|
||||
$language_id = $this->config->get('config_language_id');
|
||||
if (isset($data['category_description'][$language_id]['name'])) {
|
||||
$data['heading_title'] = $data['category_description'][$language_id]['name'];
|
||||
}
|
||||
|
||||
if (isset($this->request->post['path'])) {
|
||||
$data['path'] = $this->request->post['path'];
|
||||
} elseif (!empty($category_info)) {
|
||||
$data['path'] = $category_info['path'];
|
||||
} else {
|
||||
$data['path'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['parent_id'])) {
|
||||
$data['parent_id'] = $this->request->post['parent_id'];
|
||||
} elseif (!empty($category_info)) {
|
||||
$data['parent_id'] = $category_info['parent_id'];
|
||||
} else {
|
||||
$data['parent_id'] = 0;
|
||||
}
|
||||
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
if (isset($this->request->post['category_filter'])) {
|
||||
$filters = $this->request->post['category_filter'];
|
||||
} elseif (isset($this->request->get['category_id'])) {
|
||||
$filters = $this->model_catalog_category->getCategoryFilters($this->request->get['category_id']);
|
||||
} else {
|
||||
$filters = array();
|
||||
}
|
||||
|
||||
$data['category_filters'] = array();
|
||||
|
||||
foreach ($filters as $filter_id) {
|
||||
$filter_info = $this->model_catalog_filter->getFilter($filter_id);
|
||||
|
||||
if ($filter_info) {
|
||||
$data['category_filters'][] = array(
|
||||
'filter_id' => $filter_info['filter_id'],
|
||||
'name' => $filter_info['group'] . ' > ' . $filter_info['name']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$data['stores'] = array();
|
||||
|
||||
$data['stores'][] = array(
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
);
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = array(
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->request->post['category_store'])) {
|
||||
$data['category_store'] = $this->request->post['category_store'];
|
||||
} elseif (isset($this->request->get['category_id'])) {
|
||||
$data['category_store'] = $this->model_catalog_category->getCategoryStores($this->request->get['category_id']);
|
||||
} else {
|
||||
$data['category_store'] = array(0);
|
||||
}
|
||||
|
||||
if (isset($this->request->post['image'])) {
|
||||
$data['image'] = $this->request->post['image'];
|
||||
} elseif (!empty($category_info)) {
|
||||
$data['image'] = $category_info['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) {
|
||||
$data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100);
|
||||
} elseif (!empty($category_info) && is_file(DIR_IMAGE . $category_info['image'])) {
|
||||
$data['thumb'] = $this->model_tool_image->resize($category_info['image'], 100, 100);
|
||||
} else {
|
||||
$data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
}
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
if (isset($this->request->post['top'])) {
|
||||
$data['top'] = $this->request->post['top'];
|
||||
} elseif (!empty($category_info)) {
|
||||
$data['top'] = $category_info['top'];
|
||||
} else {
|
||||
$data['top'] = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['column'])) {
|
||||
$data['column'] = $this->request->post['column'];
|
||||
} elseif (!empty($category_info)) {
|
||||
$data['column'] = $category_info['column'];
|
||||
} else {
|
||||
$data['column'] = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['sort_order'])) {
|
||||
$data['sort_order'] = $this->request->post['sort_order'];
|
||||
} elseif (!empty($category_info)) {
|
||||
$data['sort_order'] = $category_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['product_related'])) {
|
||||
$products = $this->request->post['product_related'];
|
||||
} elseif (isset($category_info)) {
|
||||
$products = $this->model_catalog_category->getProductRelated($this->request->get['category_id']);
|
||||
} else {
|
||||
$products = array();
|
||||
}
|
||||
|
||||
$data['product_related'] = array();
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($products as $product_id) {
|
||||
$related_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if ($related_info) {
|
||||
$data['product_related'][] = array(
|
||||
'product_id' => $related_info['product_id'],
|
||||
'name' => $related_info['name']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['article_related'])) {
|
||||
$articles = $this->request->post['article_related'];
|
||||
} elseif (isset($category_info)) {
|
||||
$articles = $this->model_catalog_category->getArticleRelated($this->request->get['category_id']);
|
||||
} else {
|
||||
$articles = array();
|
||||
}
|
||||
|
||||
$data['article_related'] = array();
|
||||
|
||||
$this->load->model('blog/article');
|
||||
|
||||
foreach ($articles as $article_id) {
|
||||
$related_info = $this->model_blog_article->getArticle($article_id);
|
||||
|
||||
if ($related_info) {
|
||||
$data['article_related'][] = array(
|
||||
'article_id' => $related_info['article_id'],
|
||||
'name' => $related_info['name']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['status'])) {
|
||||
$data['status'] = $this->request->post['status'];
|
||||
} elseif (!empty($category_info)) {
|
||||
$data['status'] = $category_info['status'];
|
||||
} else {
|
||||
$data['status'] = true;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['category_seo_url'])) {
|
||||
$data['category_seo_url'] = $this->request->post['category_seo_url'];
|
||||
} elseif (isset($this->request->get['category_id'])) {
|
||||
$data['category_seo_url'] = $this->model_catalog_category->getCategorySeoUrls($this->request->get['category_id']);
|
||||
} else {
|
||||
$data['category_seo_url'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['noindex'])) {
|
||||
$data['noindex'] = $this->request->post['noindex'];
|
||||
} elseif (!empty($category_info)) {
|
||||
$data['noindex'] = $category_info['noindex'];
|
||||
} else {
|
||||
$data['noindex'] = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['category_layout'])) {
|
||||
$data['category_layout'] = $this->request->post['category_layout'];
|
||||
} elseif (isset($this->request->get['category_id'])) {
|
||||
$data['category_layout'] = $this->model_catalog_category->getCategoryLayouts($this->request->get['category_id']);
|
||||
} else {
|
||||
$data['category_layout'] = array();
|
||||
}
|
||||
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/category_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/category')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['category_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 255)) {
|
||||
$this->error['name'][$language_id] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
if ((utf8_strlen($value['meta_title']) < 0) || (utf8_strlen($value['meta_title']) > 255)) {
|
||||
$this->error['meta_title'][$language_id] = $this->language->get('error_meta_title');
|
||||
}
|
||||
|
||||
if ((utf8_strlen($value['meta_h1']) < 0) || (utf8_strlen($value['meta_h1']) > 255)) {
|
||||
$this->error['meta_h1'][$language_id] = $this->language->get('error_meta_h1');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->get['category_id']) && $this->request->post['parent_id']) {
|
||||
$results = $this->model_catalog_category->getCategoryPath($this->request->post['parent_id']);
|
||||
|
||||
foreach ($results as $result) {
|
||||
if ($result['path_id'] == $this->request->get['category_id']) {
|
||||
$this->error['parent'] = $this->language->get('error_parent');
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['category_seo_url']) && is_array($this->request->post['category_seo_url'])) {
|
||||
foreach ($this->request->post['category_seo_url'] as $store_id => &$languages) {
|
||||
foreach ($languages as $language_id => &$keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$keyword = translit($keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['category_description'])) {
|
||||
foreach ($this->request->post['category_description'] as $language_id => $value) {
|
||||
if (!empty($value['name'])) {
|
||||
if (!isset($this->request->post['category_seo_url'][0][$language_id]) || trim($this->request->post['category_seo_url'][0][$language_id]) === '') {
|
||||
$this->request->post['category_seo_url'][0][$language_id] = translit($value['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->post['category_seo_url']) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($this->request->post['category_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
if (count(array_keys($language, $keyword)) > 1) {
|
||||
$this->error['keyword'][$store_id][$language_id] = $this->language->get('error_unique');
|
||||
}
|
||||
|
||||
$seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($keyword);
|
||||
|
||||
foreach ($seo_urls as $seo_url) {
|
||||
if (($seo_url['store_id'] == $store_id) && (!isset($this->request->get['category_id']) || ($seo_url['query'] != 'category_id=' . $this->request->get['category_id']))) {
|
||||
$this->error['keyword'][$store_id][$language_id] = $this->language->get('error_keyword');
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->error && !isset($this->error['warning'])) {
|
||||
$this->error['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function enable() {
|
||||
$this->load->language('catalog/category');
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
$this->load->model('catalog/category');
|
||||
if (isset($this->request->post['selected']) && $this->validateEnable()) {
|
||||
foreach ($this->request->post['selected'] as $category_id) {
|
||||
$this->model_catalog_category->editCategoryStatus($category_id, 1);
|
||||
}
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
$url = '';
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
$this->response->redirect($this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function disable() {
|
||||
$this->load->language('catalog/category');
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
$this->load->model('catalog/category');
|
||||
if (isset($this->request->post['selected']) && $this->validateDisable()) {
|
||||
foreach ($this->request->post['selected'] as $category_id) {
|
||||
$this->model_catalog_category->editCategoryStatus($category_id, 0);
|
||||
}
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
$url = '';
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
$this->response->redirect($this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function validateEnable() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/category')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDisable() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/category')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/category')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateRepair() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/category')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function autocomplete() {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/category');
|
||||
|
||||
$filter_data = array(
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'sort' => 'name',
|
||||
'order' => 'ASC',
|
||||
'start' => 0,
|
||||
'limit' => $this->config->get('config_limit_autocomplete')
|
||||
);
|
||||
|
||||
$results = $this->model_catalog_category->getCategories($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$json[] = array(
|
||||
'category_id' => $result['category_id'],
|
||||
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($json as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $json);
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
private function getCategories($parent_id, $parent_path = '', $indent = '') {
|
||||
$category_id = array_shift($this->path);
|
||||
$output = array();
|
||||
static $href_category = null;
|
||||
static $href_action = null;
|
||||
if ($href_category === null) {
|
||||
$href_category = $this->url->link('catalog/category', 'user_token=' . $this->session->data['user_token'] . '&path=', true);
|
||||
$href_action = $this->url->link('catalog/category/update', 'user_token=' . $this->session->data['user_token'] . '&category_id=', true);
|
||||
}
|
||||
$results = $this->model_catalog_category->getCategoriesByParentId($parent_id);
|
||||
foreach ($results as $result) {
|
||||
$path = $parent_path . $result['category_id'];
|
||||
$href = ($result['children']) ? $href_category . $path : '';
|
||||
$name = $result['name'];
|
||||
if ($category_id == $result['category_id']) {
|
||||
$name = '<b>' . $name . '</b>';
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $result['name'],
|
||||
'href' => $href,
|
||||
'separator' => ' :: '
|
||||
);
|
||||
$href = '';
|
||||
}
|
||||
$selected = isset($this->request->post['selected']) && in_array($result['category_id'], $this->request->post['selected']);
|
||||
$action = array();
|
||||
$action[] = array(
|
||||
'text' => $this->language->get('text_edit'),
|
||||
'href' => $href_action . $result['category_id']
|
||||
);
|
||||
$output[$result['category_id']] = array(
|
||||
'category_id' => $result['category_id'],
|
||||
'name' => $name,
|
||||
'sort_order' => $result['sort_order'],
|
||||
'noindex' => $result['noindex'],
|
||||
'edit' => $this->url->link('catalog/category/edit', 'user_token=' . $this->session->data['user_token'] . '&category_id=' . $result['category_id'], true),
|
||||
'selected' => $selected,
|
||||
'action' => $action,
|
||||
'href' => $href,
|
||||
'href_shop' => HTTP_CATALOG . 'index.php?route=product/category&path=' . ($result['category_id']),
|
||||
'indent' => $indent
|
||||
);
|
||||
if ($category_id == $result['category_id']) {
|
||||
$output += $this->getCategories($result['category_id'], $path . '_', $indent . str_repeat(' ', 8));
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
private function getAllCategories($categories, $parent_id = 0, $parent_name = '') {
|
||||
$output = array();
|
||||
if (array_key_exists($parent_id, $categories)) {
|
||||
if ($parent_name != '') {
|
||||
$parent_name .= $this->language->get('text_separator');
|
||||
}
|
||||
foreach ($categories[$parent_id] as $category) {
|
||||
$output[$category['category_id']] = array(
|
||||
'category_id' => $category['category_id'],
|
||||
'name' => $parent_name . $category['name']
|
||||
);
|
||||
$output += $this->getAllCategories($categories, $category['category_id'], $parent_name . $category['name']);
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,514 @@
|
||||
<?php
|
||||
class ControllerCatalogDownload extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_download->addDownload($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_download->editDownload($this->request->get['download_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $download_id) {
|
||||
$this->model_catalog_download->deleteDownload($download_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'dd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/download/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/download/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['downloads'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$download_total = $this->model_catalog_download->getTotalDownloads();
|
||||
|
||||
$results = $this->model_catalog_download->getDownloads($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['downloads'][] = array(
|
||||
'download_id' => $result['download_id'],
|
||||
'name' => $result['name'],
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'edit' => $this->url->link('catalog/download/edit', 'user_token=' . $this->session->data['user_token'] . '&download_id=' . $result['download_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . '&sort=dd.name' . $url, true);
|
||||
$data['sort_date_added'] = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . '&sort=d.date_added' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $download_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($download_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($download_total - $this->config->get('config_limit_admin'))) ? $download_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $download_total, ceil($download_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/download_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['download_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['name'])) {
|
||||
$data['error_name'] = $this->error['name'];
|
||||
} else {
|
||||
$data['error_name'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['filename'])) {
|
||||
$data['error_filename'] = $this->error['filename'];
|
||||
} else {
|
||||
$data['error_filename'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['mask'])) {
|
||||
$data['error_mask'] = $this->error['mask'];
|
||||
} else {
|
||||
$data['error_mask'] = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['download_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/download/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/download/edit', 'user_token=' . $this->session->data['user_token'] . '&download_id=' . $this->request->get['download_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/download', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->get['download_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$download_info = $this->model_catalog_download->getDownload($this->request->get['download_id']);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
if (isset($this->request->get['download_id'])) {
|
||||
$data['download_id'] = (int)$this->request->get['download_id'];
|
||||
} else {
|
||||
$data['download_id'] = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['download_description'])) {
|
||||
$data['download_description'] = $this->request->post['download_description'];
|
||||
} elseif (isset($this->request->get['download_id'])) {
|
||||
$data['download_description'] = $this->model_catalog_download->getDownloadDescriptions($this->request->get['download_id']);
|
||||
} else {
|
||||
$data['download_description'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['filename'])) {
|
||||
$data['filename'] = $this->request->post['filename'];
|
||||
} elseif (!empty($download_info)) {
|
||||
$data['filename'] = $download_info['filename'];
|
||||
} else {
|
||||
$data['filename'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['mask'])) {
|
||||
$data['mask'] = $this->request->post['mask'];
|
||||
} elseif (!empty($download_info)) {
|
||||
$data['mask'] = $download_info['mask'];
|
||||
} else {
|
||||
$data['mask'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/download_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/download')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['download_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 64)) {
|
||||
$this->error['name'][$language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if ((utf8_strlen($this->request->post['filename']) < 3) || (utf8_strlen($this->request->post['filename']) > 128)) {
|
||||
$this->error['filename'] = $this->language->get('error_filename');
|
||||
}
|
||||
|
||||
if (!is_file(DIR_DOWNLOAD . $this->request->post['filename'])) {
|
||||
$this->error['filename'] = $this->language->get('error_exists');
|
||||
}
|
||||
|
||||
if ((utf8_strlen($this->request->post['mask']) < 3) || (utf8_strlen($this->request->post['mask']) > 128)) {
|
||||
$this->error['mask'] = $this->language->get('error_mask');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/download')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($this->request->post['selected'] as $download_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByDownloadId($download_id);
|
||||
|
||||
if ($product_total) {
|
||||
$this->error['warning'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function upload() {
|
||||
$this->load->language('catalog/download');
|
||||
|
||||
$json = array();
|
||||
|
||||
// Check user has permission
|
||||
if (!$this->user->hasPermission('modify', 'catalog/download')) {
|
||||
$json['error'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
if (!empty($this->request->files['file']['name']) && is_file($this->request->files['file']['tmp_name'])) {
|
||||
// Sanitize the filename
|
||||
$filename = basename(html_entity_decode($this->request->files['file']['name'], ENT_QUOTES, 'UTF-8'));
|
||||
|
||||
// Validate the filename length
|
||||
if ((utf8_strlen($filename) < 3) || (utf8_strlen($filename) > 128)) {
|
||||
$json['error'] = $this->language->get('error_filename');
|
||||
}
|
||||
|
||||
// Allowed file extension types
|
||||
$allowed = array();
|
||||
|
||||
$extension_allowed = preg_replace('~\r?\n~', "\n", $this->config->get('config_file_ext_allowed'));
|
||||
|
||||
$filetypes = explode("\n", $extension_allowed);
|
||||
|
||||
foreach ($filetypes as $filetype) {
|
||||
$allowed[] = trim($filetype);
|
||||
}
|
||||
|
||||
if (!in_array(strtolower(substr(strrchr($filename, '.'), 1)), $allowed)) {
|
||||
$json['error'] = $this->language->get('error_filetype');
|
||||
}
|
||||
|
||||
// Allowed file mime types
|
||||
$allowed = array();
|
||||
|
||||
$mime_allowed = preg_replace('~\r?\n~', "\n", $this->config->get('config_file_mime_allowed'));
|
||||
|
||||
$filetypes = explode("\n", $mime_allowed);
|
||||
|
||||
foreach ($filetypes as $filetype) {
|
||||
$allowed[] = trim($filetype);
|
||||
}
|
||||
|
||||
if (!in_array($this->request->files['file']['type'], $allowed)) {
|
||||
$json['error'] = $this->language->get('error_filetype');
|
||||
}
|
||||
|
||||
// Check to see if any PHP files are trying to be uploaded
|
||||
$content = file_get_contents($this->request->files['file']['tmp_name']);
|
||||
|
||||
if (preg_match('/\<\?php/i', $content)) {
|
||||
$json['error'] = $this->language->get('error_filetype');
|
||||
}
|
||||
|
||||
// Return any upload error
|
||||
if ($this->request->files['file']['error'] != UPLOAD_ERR_OK) {
|
||||
$json['error'] = $this->language->get('error_upload_' . $this->request->files['file']['error']);
|
||||
}
|
||||
} else {
|
||||
$json['error'] = $this->language->get('error_upload');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$json) {
|
||||
$file = $filename . '.' . token(32);
|
||||
|
||||
move_uploaded_file($this->request->files['file']['tmp_name'], DIR_DOWNLOAD . $file);
|
||||
|
||||
$json['filename'] = $file;
|
||||
$json['mask'] = $filename;
|
||||
|
||||
$json['success'] = $this->language->get('text_upload');
|
||||
}
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
|
||||
public function autocomplete() {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/download');
|
||||
|
||||
$filter_data = array(
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => $this->config->get('config_limit_autocomplete')
|
||||
);
|
||||
|
||||
$results = $this->model_catalog_download->getDownloads($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$json[] = array(
|
||||
'download_id' => $result['download_id'],
|
||||
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($json as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $json);
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
<?php
|
||||
class ControllerCatalogFilter extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_filter->addFilter($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_filter->editFilter($this->request->get['filter_group_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/filter');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $filter_group_id) {
|
||||
$this->model_catalog_filter->deleteFilter($filter_group_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'fgd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/filter/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/filter/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['filters'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$filter_total = $this->model_catalog_filter->getTotalFilterGroups();
|
||||
|
||||
$results = $this->model_catalog_filter->getFilterGroups($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['filters'][] = array(
|
||||
'filter_group_id' => $result['filter_group_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/filter/edit', 'user_token=' . $this->session->data['user_token'] . '&filter_group_id=' . $result['filter_group_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . '&sort=fgd.name' . $url, true);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . '&sort=fg.sort_order' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $filter_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($filter_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($filter_total - $this->config->get('config_limit_admin'))) ? $filter_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $filter_total, ceil($filter_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/filter_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['filter_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['group'])) {
|
||||
$data['error_group'] = $this->error['group'];
|
||||
} else {
|
||||
$data['error_group'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['filter'])) {
|
||||
$data['error_filter'] = $this->error['filter'];
|
||||
} else {
|
||||
$data['error_filter'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['filter_group_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/filter/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/filter/edit', 'user_token=' . $this->session->data['user_token'] . '&filter_group_id=' . $this->request->get['filter_group_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/filter', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['filter_group_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$filter_group_info = $this->model_catalog_filter->getFilterGroup($this->request->get['filter_group_id']);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->post['filter_group_description'])) {
|
||||
$data['filter_group_description'] = $this->request->post['filter_group_description'];
|
||||
} elseif (isset($this->request->get['filter_group_id'])) {
|
||||
$data['filter_group_description'] = $this->model_catalog_filter->getFilterGroupDescriptions($this->request->get['filter_group_id']);
|
||||
} else {
|
||||
$data['filter_group_description'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['sort_order'])) {
|
||||
$data['sort_order'] = $this->request->post['sort_order'];
|
||||
} elseif (!empty($filter_group_info)) {
|
||||
$data['sort_order'] = $filter_group_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['filter'])) {
|
||||
$data['filters'] = $this->request->post['filter'];
|
||||
} elseif (isset($this->request->get['filter_group_id'])) {
|
||||
$data['filters'] = $this->model_catalog_filter->getFilterDescriptions($this->request->get['filter_group_id']);
|
||||
} else {
|
||||
$data['filters'] = array();
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/filter_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/filter')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['filter_group_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 64)) {
|
||||
$this->error['group'][$language_id] = $this->language->get('error_group');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['filter'])) {
|
||||
foreach ($this->request->post['filter'] as $filter_id => $filter) {
|
||||
foreach ($filter['filter_description'] as $language_id => $filter_description) {
|
||||
if ((utf8_strlen($filter_description['name']) < 1) || (utf8_strlen($filter_description['name']) > 64)) {
|
||||
$this->error['filter'][$filter_id][$language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/filter')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function autocomplete() {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/filter');
|
||||
|
||||
$filter_data = array(
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => $this->config->get('config_limit_autocomplete')
|
||||
);
|
||||
|
||||
$filters = $this->model_catalog_filter->getFilters($filter_data);
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
$json[] = array(
|
||||
'filter_id' => $filter['filter_id'],
|
||||
'name' => strip_tags(html_entity_decode($filter['group'] . ' > ' . $filter['name'], ENT_QUOTES, 'UTF-8'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($json as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $json);
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,606 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerCatalogInformation extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_information->addInformation($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_information->editInformation($this->request->get['information_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/information');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/information');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $information_id) {
|
||||
$this->model_catalog_information->deleteInformation($information_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'id.title';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/information/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/information/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['enabled'] = $this->url->link('catalog/information/enable', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['disabled'] = $this->url->link('catalog/information/disable', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['informations'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$information_total = $this->model_catalog_information->getTotalInformations();
|
||||
|
||||
$results = $this->model_catalog_information->getInformations($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['informations'][] = array(
|
||||
'information_id' => $result['information_id'],
|
||||
'title' => $result['title'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'noindex' => $result['noindex'],
|
||||
'href_shop' => HTTP_CATALOG . 'index.php?route=information/information&information_id=' . ($result['information_id']),
|
||||
'edit' => $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $result['information_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_title'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . '&sort=id.title' . $url, true);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . '&sort=i.sort_order' . $url, true);
|
||||
$data['sort_noindex'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . '&sort=i.noindex' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $information_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($information_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($information_total - $this->config->get('config_limit_admin'))) ? $information_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $information_total, ceil($information_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/information_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['information_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['title'])) {
|
||||
$data['error_title'] = $this->error['title'];
|
||||
} else {
|
||||
$data['error_title'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['description'])) {
|
||||
$data['error_description'] = $this->error['description'];
|
||||
} else {
|
||||
$data['error_description'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['meta_title'])) {
|
||||
$data['error_meta_title'] = $this->error['meta_title'];
|
||||
} else {
|
||||
$data['error_meta_title'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['meta_h1'])) {
|
||||
$data['error_meta_h1'] = $this->error['meta_h1'];
|
||||
} else {
|
||||
$data['error_meta_h1'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['keyword'])) {
|
||||
$data['error_keyword'] = $this->error['keyword'];
|
||||
} else {
|
||||
$data['error_keyword'] = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['information_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/information/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $this->request->get['information_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['information_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$information_info = $this->model_catalog_information->getInformation($this->request->get['information_id']);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->post['information_description'])) {
|
||||
$data['information_description'] = $this->request->post['information_description'];
|
||||
} elseif (isset($this->request->get['information_id'])) {
|
||||
$data['information_description'] = $this->model_catalog_information->getInformationDescriptions($this->request->get['information_id']);
|
||||
} else {
|
||||
$data['information_description'] = array();
|
||||
}
|
||||
|
||||
$language_id = $this->config->get('config_language_id');
|
||||
if (isset($data['information_description'][$language_id]['title'])) {
|
||||
$data['heading_title'] = $data['information_description'][$language_id]['title'];
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$data['stores'] = array();
|
||||
|
||||
$data['stores'][] = array(
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
);
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = array(
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->request->post['information_store'])) {
|
||||
$data['information_store'] = $this->request->post['information_store'];
|
||||
} elseif (isset($this->request->get['information_id'])) {
|
||||
$data['information_store'] = $this->model_catalog_information->getInformationStores($this->request->get['information_id']);
|
||||
} else {
|
||||
$data['information_store'] = array(0);
|
||||
}
|
||||
|
||||
if (isset($this->request->post['bottom'])) {
|
||||
$data['bottom'] = $this->request->post['bottom'];
|
||||
} elseif (!empty($information_info)) {
|
||||
$data['bottom'] = $information_info['bottom'];
|
||||
} else {
|
||||
$data['bottom'] = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['status'])) {
|
||||
$data['status'] = $this->request->post['status'];
|
||||
} elseif (!empty($information_info)) {
|
||||
$data['status'] = $information_info['status'];
|
||||
} else {
|
||||
$data['status'] = true;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['noindex'])) {
|
||||
$data['noindex'] = $this->request->post['noindex'];
|
||||
} elseif (!empty($information_info)) {
|
||||
$data['noindex'] = $information_info['noindex'];
|
||||
} else {
|
||||
$data['noindex'] = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['sort_order'])) {
|
||||
$data['sort_order'] = $this->request->post['sort_order'];
|
||||
} elseif (!empty($information_info)) {
|
||||
$data['sort_order'] = $information_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['information_seo_url'])) {
|
||||
$data['information_seo_url'] = $this->request->post['information_seo_url'];
|
||||
} elseif (isset($this->request->get['information_id'])) {
|
||||
$data['information_seo_url'] = $this->model_catalog_information->getInformationSeoUrls($this->request->get['information_id']);
|
||||
} else {
|
||||
$data['information_seo_url'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['information_layout'])) {
|
||||
$data['information_layout'] = $this->request->post['information_layout'];
|
||||
} elseif (isset($this->request->get['information_id'])) {
|
||||
$data['information_layout'] = $this->model_catalog_information->getInformationLayouts($this->request->get['information_id']);
|
||||
} else {
|
||||
$data['information_layout'] = array();
|
||||
}
|
||||
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/information_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/information')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['information_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['title']) < 1) || (utf8_strlen($value['title']) > 64)) {
|
||||
$this->error['title'][$language_id] = $this->language->get('error_title');
|
||||
}
|
||||
|
||||
if (utf8_strlen($value['description']) < 3) {
|
||||
$this->error['description'][$language_id] = $this->language->get('error_description');
|
||||
}
|
||||
|
||||
if ((utf8_strlen($value['meta_title']) < 0) || (utf8_strlen($value['meta_title']) > 255)) {
|
||||
$this->error['meta_title'][$language_id] = $this->language->get('error_meta_title');
|
||||
}
|
||||
|
||||
if ((utf8_strlen($value['meta_h1']) < 0) || (utf8_strlen($value['meta_h1']) > 255)) {
|
||||
$this->error['meta_h1'][$language_id] = $this->language->get('error_meta_h1');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['information_seo_url']) && is_array($this->request->post['information_seo_url'])) {
|
||||
foreach ($this->request->post['information_seo_url'] as $store_id => &$languages) {
|
||||
foreach ($languages as $language_id => &$keyword) {
|
||||
if (!empty($keyword)) {
|
||||
$keyword = translit($keyword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['information_description'])) {
|
||||
foreach ($this->request->post['information_description'] as $language_id => $value) {
|
||||
if (!empty($value['title'])) {
|
||||
if (!isset($this->request->post['information_seo_url'][0][$language_id]) || trim($this->request->post['information_seo_url'][0][$language_id]) === '') {
|
||||
$this->request->post['information_seo_url'][0][$language_id] = translit($value['title']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->post['information_seo_url']) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($this->request->post['information_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
if (count(array_keys($language, $keyword)) > 1) {
|
||||
$this->error['keyword'][$store_id][$language_id] = $this->language->get('error_unique');
|
||||
}
|
||||
|
||||
$seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($keyword);
|
||||
|
||||
foreach ($seo_urls as $seo_url) {
|
||||
if (($seo_url['store_id'] == $store_id) && (!isset($this->request->get['information_id']) || ($seo_url['query'] != 'information_id=' . $this->request->get['information_id']))) {
|
||||
$this->error['keyword'][$store_id][$language_id] = $this->language->get('error_keyword');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->error && !isset($this->error['warning'])) {
|
||||
$this->error['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function enable() {
|
||||
$this->load->language('catalog/information');
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
$this->load->model('catalog/information');
|
||||
if (isset($this->request->post['selected']) && $this->validateEnable()) {
|
||||
foreach ($this->request->post['selected'] as $information_id) {
|
||||
$this->model_catalog_information->editInformationStatus($information_id, 1);
|
||||
}
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
$url = '';
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
$this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function disable() {
|
||||
$this->load->language('catalog/information');
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
$this->load->model('catalog/information');
|
||||
if (isset($this->request->post['selected']) && $this->validateDisable()) {
|
||||
foreach ($this->request->post['selected'] as $information_id) {
|
||||
$this->model_catalog_information->editInformationStatus($information_id, 0);
|
||||
}
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
$url = '';
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
$this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function validateEnable() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/information')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDisable() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/information')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/information')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
foreach ($this->request->post['selected'] as $information_id) {
|
||||
if ($this->config->get('config_account_id') == $information_id) {
|
||||
$this->error['warning'] = $this->language->get('error_account');
|
||||
}
|
||||
|
||||
if ($this->config->get('config_checkout_id') == $information_id) {
|
||||
$this->error['warning'] = $this->language->get('error_checkout');
|
||||
}
|
||||
|
||||
if ($this->config->get('config_affiliate_id') == $information_id) {
|
||||
$this->error['warning'] = $this->language->get('error_affiliate');
|
||||
}
|
||||
|
||||
if ($this->config->get('config_return_id') == $information_id) {
|
||||
$this->error['warning'] = $this->language->get('error_return');
|
||||
}
|
||||
|
||||
$store_total = $this->model_setting_store->getTotalStoresByInformationId($information_id);
|
||||
|
||||
if ($store_total) {
|
||||
$this->error['warning'] = sprintf($this->language->get('error_store'), $store_total);
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,584 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerCatalogManufacturer extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_manufacturer->addManufacturer($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_manufacturer->editManufacturer($this->request->get['manufacturer_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/manufacturer');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $manufacturer_id) {
|
||||
$this->model_catalog_manufacturer->deleteManufacturer($manufacturer_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/manufacturer/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/manufacturer/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['manufacturers'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$manufacturer_total = $this->model_catalog_manufacturer->getTotalManufacturers();
|
||||
|
||||
$results = $this->model_catalog_manufacturer->getManufacturers($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['manufacturers'][] = array(
|
||||
'manufacturer_id' => $result['manufacturer_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'noindex' => $result['noindex'],
|
||||
'href_shop' => HTTP_CATALOG . 'index.php?route=product/manufacturer/info&manufacturer_id=' . ($result['manufacturer_id']),
|
||||
'edit' => $this->url->link('catalog/manufacturer/edit', 'user_token=' . $this->session->data['user_token'] . '&manufacturer_id=' . $result['manufacturer_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . '&sort=sort_order' . $url, true);
|
||||
$data['sort_noindex'] = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . '&sort=noindex' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $manufacturer_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($manufacturer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($manufacturer_total - $this->config->get('config_limit_admin'))) ? $manufacturer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $manufacturer_total, ceil($manufacturer_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/manufacturer_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['manufacturer_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['name'])) {
|
||||
$data['error_name'] = $this->error['name'];
|
||||
} else {
|
||||
$data['error_name'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['meta_title'])) {
|
||||
$data['error_meta_title'] = $this->error['meta_title'];
|
||||
} else {
|
||||
$data['error_meta_title'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['meta_h1'])) {
|
||||
$data['error_meta_h1'] = $this->error['meta_h1'];
|
||||
} else {
|
||||
$data['error_meta_h1'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['keyword'])) {
|
||||
$data['error_keyword'] = $this->error['keyword'];
|
||||
} else {
|
||||
$data['error_keyword'] = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['manufacturer_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/manufacturer/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/manufacturer/edit', 'user_token=' . $this->session->data['user_token'] . '&manufacturer_id=' . $this->request->get['manufacturer_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/manufacturer', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['manufacturer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$manufacturer_info = $this->model_catalog_manufacturer->getManufacturer($this->request->get['manufacturer_id']);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
if (isset($this->request->post['manufacturer_description'])) {
|
||||
$data['manufacturer_description'] = $this->request->post['manufacturer_description'];
|
||||
} elseif (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['manufacturer_description'] = $this->model_catalog_manufacturer->getManufacturerDescriptions($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$data['manufacturer_description'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['name'])) {
|
||||
$data['name'] = $this->request->post['name'];
|
||||
} elseif (!empty($manufacturer_info)) {
|
||||
$data['name'] = $manufacturer_info['name'];
|
||||
} else {
|
||||
$data['name'] = '';
|
||||
}
|
||||
|
||||
if (!empty($manufacturer_info)) {
|
||||
$data['heading_title'] = $data['name'] = $manufacturer_info['name'];
|
||||
} else {
|
||||
$data['heading_title'] = $this->language->get('heading_title');
|
||||
}
|
||||
|
||||
$this->load->model('setting/store');
|
||||
|
||||
$data['stores'] = array();
|
||||
|
||||
$data['stores'][] = array(
|
||||
'store_id' => 0,
|
||||
'name' => $this->language->get('text_default')
|
||||
);
|
||||
|
||||
$stores = $this->model_setting_store->getStores();
|
||||
|
||||
foreach ($stores as $store) {
|
||||
$data['stores'][] = array(
|
||||
'store_id' => $store['store_id'],
|
||||
'name' => $store['name']
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->request->post['manufacturer_store'])) {
|
||||
$data['manufacturer_store'] = $this->request->post['manufacturer_store'];
|
||||
} elseif (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['manufacturer_store'] = $this->model_catalog_manufacturer->getManufacturerStores($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$data['manufacturer_store'] = array(0);
|
||||
}
|
||||
|
||||
if (isset($this->request->post['image'])) {
|
||||
$data['image'] = $this->request->post['image'];
|
||||
} elseif (!empty($manufacturer_info)) {
|
||||
$data['image'] = $manufacturer_info['image'];
|
||||
} else {
|
||||
$data['image'] = '';
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) {
|
||||
$data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100);
|
||||
} elseif (!empty($manufacturer_info) && is_file(DIR_IMAGE . $manufacturer_info['image'])) {
|
||||
$data['thumb'] = $this->model_tool_image->resize($manufacturer_info['image'], 100, 100);
|
||||
} else {
|
||||
$data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
}
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
if (isset($this->request->post['noindex'])) {
|
||||
$data['noindex'] = $this->request->post['noindex'];
|
||||
} elseif (!empty($manufacturer_info)) {
|
||||
$data['noindex'] = $manufacturer_info['noindex'];
|
||||
} else {
|
||||
$data['noindex'] = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['manufacturer_layout'])) {
|
||||
$data['manufacturer_layout'] = $this->request->post['manufacturer_layout'];
|
||||
} elseif (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['manufacturer_layout'] = $this->model_catalog_manufacturer->getManufacturerLayouts($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$data['manufacturer_layout'] = array();
|
||||
}
|
||||
$this->load->model('design/layout');
|
||||
|
||||
$data['layouts'] = $this->model_design_layout->getLayouts();
|
||||
|
||||
if (isset($this->request->post['sort_order'])) {
|
||||
$data['sort_order'] = $this->request->post['sort_order'];
|
||||
} elseif (!empty($manufacturer_info)) {
|
||||
$data['sort_order'] = $manufacturer_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['product_related'])) {
|
||||
$products = $this->request->post['product_related'];
|
||||
} elseif (isset($manufacturer_info)) {
|
||||
$products = $this->model_catalog_manufacturer->getProductRelated($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$products = array();
|
||||
}
|
||||
|
||||
$data['product_related'] = array();
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($products as $product_id) {
|
||||
$related_info = $this->model_catalog_product->getProduct($product_id);
|
||||
|
||||
if ($related_info) {
|
||||
$data['product_related'][] = array(
|
||||
'product_id' => $related_info['product_id'],
|
||||
'name' => $related_info['name']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($this->request->post['article_related'])) {
|
||||
$articles = $this->request->post['article_related'];
|
||||
} elseif (isset($manufacturer_info)) {
|
||||
$articles = $this->model_catalog_manufacturer->getArticleRelated($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$articles = array();
|
||||
}
|
||||
|
||||
$data['article_related'] = array();
|
||||
|
||||
$this->load->model('blog/article');
|
||||
|
||||
foreach ($articles as $article_id) {
|
||||
$related_info = $this->model_blog_article->getArticle($article_id);
|
||||
|
||||
if ($related_info) {
|
||||
$data['article_related'][] = array(
|
||||
'article_id' => $related_info['article_id'],
|
||||
'name' => $related_info['name']
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->post['manufacturer_seo_url'])) {
|
||||
$data['manufacturer_seo_url'] = $this->request->post['manufacturer_seo_url'];
|
||||
} elseif (isset($this->request->get['manufacturer_id'])) {
|
||||
$data['manufacturer_seo_url'] = $this->model_catalog_manufacturer->getManufacturerSeoUrls($this->request->get['manufacturer_id']);
|
||||
} else {
|
||||
$data['manufacturer_seo_url'] = array();
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/manufacturer_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/manufacturer')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if ((utf8_strlen($this->request->post['name']) < 1) || (utf8_strlen($this->request->post['name']) > 64)) {
|
||||
$this->error['name'] = $this->language->get('error_name');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['manufacturer_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['meta_title']) < 0) || (utf8_strlen($value['meta_title']) > 255)) {
|
||||
$this->error['meta_title'][$language_id] = $this->language->get('error_meta_title');
|
||||
}
|
||||
|
||||
if ((utf8_strlen($value['meta_h1']) < 0) || (utf8_strlen($value['meta_h1']) > 255)) {
|
||||
$this->error['meta_h1'][$language_id] = $this->language->get('error_meta_h1');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->post['manufacturer_seo_url']) {
|
||||
$this->load->model('design/seo_url');
|
||||
|
||||
foreach ($this->request->post['manufacturer_seo_url'] as $store_id => $language) {
|
||||
foreach ($language as $language_id => $keyword) {
|
||||
if (!empty($keyword)) {
|
||||
if (count(array_keys($language, $keyword)) > 1) {
|
||||
$this->error['keyword'][$store_id][$language_id] = $this->language->get('error_unique');
|
||||
}
|
||||
|
||||
$seo_urls = $this->model_design_seo_url->getSeoUrlsByKeyword($keyword);
|
||||
|
||||
foreach ($seo_urls as $seo_url) {
|
||||
if (($seo_url['store_id'] == $store_id) && (!isset($this->request->get['manufacturer_id']) || (($seo_url['query'] != 'manufacturer_id=' . $this->request->get['manufacturer_id'])))) {
|
||||
$this->error['keyword'][$store_id][$language_id] = $this->language->get('error_keyword');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/manufacturer')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($this->request->post['selected'] as $manufacturer_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByManufacturerId($manufacturer_id);
|
||||
|
||||
if ($product_total) {
|
||||
$this->error['warning'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function autocomplete() {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->model('catalog/manufacturer');
|
||||
|
||||
$filter_data = array(
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => $this->config->get('config_limit_autocomplete')
|
||||
);
|
||||
|
||||
$results = $this->model_catalog_manufacturer->getManufacturers($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$json[] = array(
|
||||
'manufacturer_id' => $result['manufacturer_id'],
|
||||
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($json as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $json);
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,508 @@
|
||||
<?php
|
||||
class ControllerCatalogOption extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_option->addOption($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_option->editOption($this->request->get['option_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $option_id) {
|
||||
$this->model_catalog_option->deleteOption($option_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'od.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/option/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/option/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['options'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$option_total = $this->model_catalog_option->getTotalOptions();
|
||||
|
||||
$results = $this->model_catalog_option->getOptions($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['options'][] = array(
|
||||
'option_id' => $result['option_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/option/edit', 'user_token=' . $this->session->data['user_token'] . '&option_id=' . $result['option_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . '&sort=od.name' . $url, true);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . '&sort=o.sort_order' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $option_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($option_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($option_total - $this->config->get('config_limit_admin'))) ? $option_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $option_total, ceil($option_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/option_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['option_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['name'])) {
|
||||
$data['error_name'] = $this->error['name'];
|
||||
} else {
|
||||
$data['error_name'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->error['option_value'])) {
|
||||
$data['error_option_value'] = $this->error['option_value'];
|
||||
} else {
|
||||
$data['error_option_value'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['option_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/option/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/option/edit', 'user_token=' . $this->session->data['user_token'] . '&option_id=' . $this->request->get['option_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/option', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['option_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$option_info = $this->model_catalog_option->getOption($this->request->get['option_id']);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->post['option_description'])) {
|
||||
$data['option_description'] = $this->request->post['option_description'];
|
||||
} elseif (isset($this->request->get['option_id'])) {
|
||||
$data['option_description'] = $this->model_catalog_option->getOptionDescriptions($this->request->get['option_id']);
|
||||
} else {
|
||||
$data['option_description'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['type'])) {
|
||||
$data['type'] = $this->request->post['type'];
|
||||
} elseif (!empty($option_info)) {
|
||||
$data['type'] = $option_info['type'];
|
||||
} else {
|
||||
$data['type'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['sort_order'])) {
|
||||
$data['sort_order'] = $this->request->post['sort_order'];
|
||||
} elseif (!empty($option_info)) {
|
||||
$data['sort_order'] = $option_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['option_value'])) {
|
||||
$option_values = $this->request->post['option_value'];
|
||||
} elseif (isset($this->request->get['option_id'])) {
|
||||
$option_values = $this->model_catalog_option->getOptionValueDescriptions($this->request->get['option_id']);
|
||||
} else {
|
||||
$option_values = array();
|
||||
}
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$data['option_values'] = array();
|
||||
|
||||
foreach ($option_values as $option_value) {
|
||||
if (is_file(DIR_IMAGE . $option_value['image'])) {
|
||||
$image = $option_value['image'];
|
||||
$thumb = $option_value['image'];
|
||||
} else {
|
||||
$image = '';
|
||||
$thumb = 'no_image.png';
|
||||
}
|
||||
|
||||
$data['option_values'][] = array(
|
||||
'option_value_id' => $option_value['option_value_id'],
|
||||
'option_value_description' => $option_value['option_value_description'],
|
||||
'image' => $image,
|
||||
'thumb' => $this->model_tool_image->resize($thumb, 100, 100),
|
||||
'sort_order' => $option_value['sort_order']
|
||||
);
|
||||
}
|
||||
|
||||
$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/option_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/option')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['option_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['name']) < 1) || (utf8_strlen($value['name']) > 128)) {
|
||||
$this->error['name'][$language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if (($this->request->post['type'] == 'select' || $this->request->post['type'] == 'radio' || $this->request->post['type'] == 'checkbox') && !isset($this->request->post['option_value'])) {
|
||||
$this->error['warning'] = $this->language->get('error_type');
|
||||
}
|
||||
|
||||
if (isset($this->request->post['option_value'])) {
|
||||
foreach ($this->request->post['option_value'] as $option_value_id => $option_value) {
|
||||
foreach ($option_value['option_value_description'] as $language_id => $option_value_description) {
|
||||
if ((utf8_strlen($option_value_description['name']) < 1) || (utf8_strlen($option_value_description['name']) > 128)) {
|
||||
$this->error['option_value'][$option_value_id][$language_id] = $this->language->get('error_option_value');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/option')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($this->request->post['selected'] as $option_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByOptionId($option_id);
|
||||
|
||||
if ($product_total) {
|
||||
$this->error['warning'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function autocomplete() {
|
||||
$json = array();
|
||||
|
||||
if (isset($this->request->get['filter_name'])) {
|
||||
$this->load->language('catalog/option');
|
||||
|
||||
$this->load->model('catalog/option');
|
||||
|
||||
$this->load->model('tool/image');
|
||||
|
||||
$filter_data = array(
|
||||
'filter_name' => $this->request->get['filter_name'],
|
||||
'start' => 0,
|
||||
'limit' => $this->config->get('config_limit_autocomplete')
|
||||
);
|
||||
|
||||
$options = $this->model_catalog_option->getOptions($filter_data);
|
||||
|
||||
foreach ($options as $option) {
|
||||
$option_value_data = array();
|
||||
|
||||
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') {
|
||||
$option_values = $this->model_catalog_option->getOptionValues($option['option_id']);
|
||||
|
||||
foreach ($option_values as $option_value) {
|
||||
if (is_file(DIR_IMAGE . $option_value['image'])) {
|
||||
$image = $this->model_tool_image->resize($option_value['image'], 50, 50);
|
||||
} else {
|
||||
$image = $this->model_tool_image->resize('no_image.png', 50, 50);
|
||||
}
|
||||
|
||||
$option_value_data[] = array(
|
||||
'option_value_id' => $option_value['option_value_id'],
|
||||
'name' => strip_tags(html_entity_decode($option_value['name'], ENT_QUOTES, 'UTF-8')),
|
||||
'image' => $image
|
||||
);
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($option_value_data as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $option_value_data);
|
||||
}
|
||||
|
||||
$type = '';
|
||||
|
||||
if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox') {
|
||||
$type = $this->language->get('text_choose');
|
||||
}
|
||||
|
||||
if ($option['type'] == 'text' || $option['type'] == 'textarea') {
|
||||
$type = $this->language->get('text_input');
|
||||
}
|
||||
|
||||
if ($option['type'] == 'file') {
|
||||
$type = $this->language->get('text_file');
|
||||
}
|
||||
|
||||
if ($option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
|
||||
$type = $this->language->get('text_date');
|
||||
}
|
||||
|
||||
$json[] = array(
|
||||
'option_id' => $option['option_id'],
|
||||
'name' => strip_tags(html_entity_decode($option['name'], ENT_QUOTES, 'UTF-8')),
|
||||
'category' => $type,
|
||||
'type' => $option['type'],
|
||||
'option_value' => $option_value_data
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$sort_order = array();
|
||||
|
||||
foreach ($json as $key => $value) {
|
||||
$sort_order[$key] = $value['name'];
|
||||
}
|
||||
|
||||
array_multisort($sort_order, SORT_ASC, $json);
|
||||
|
||||
$this->response->addHeader('Content-Type: application/json');
|
||||
$this->response->setOutput(json_encode($json));
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,514 @@
|
||||
<?php
|
||||
class ControllerCatalogRecurring extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/recurring');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/recurring');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/recurring');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/recurring');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_recurring->addRecurring($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/recurring');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/recurring');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_recurring->editRecurring($this->request->get['recurring_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/recurring');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/recurring');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $recurring_id) {
|
||||
$this->model_catalog_recurring->deleteRecurring($recurring_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function copy() {
|
||||
$this->load->language('catalog/recurring');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/recurring');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateCopy()) {
|
||||
foreach ($this->request->post['selected'] as $recurring_id) {
|
||||
$this->model_catalog_recurring->copyRecurring($recurring_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'rd.name';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (int)$this->request->get['page'];
|
||||
} else {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/recurring/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['copy'] = $this->url->link('catalog/recurring/copy', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/recurring/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['recurrings'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$recurring_total = $this->model_catalog_recurring->getTotalRecurrings();
|
||||
|
||||
$results = $this->model_catalog_recurring->getRecurrings($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['recurrings'][] = array(
|
||||
'recurring_id' => $result['recurring_id'],
|
||||
'name' => $result['name'],
|
||||
'sort_order' => $result['sort_order'],
|
||||
'edit' => $this->url->link('catalog/recurring/edit', 'user_token=' . $this->session->data['user_token'] . '&recurring_id=' . $result['recurring_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_name'] = $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=pd.name' . $url, true);
|
||||
$data['sort_sort_order'] = $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . '&sort=p.sort_order' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $recurring_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($recurring_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($recurring_total - $this->config->get('config_limit_admin'))) ? $recurring_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $recurring_total, ceil($recurring_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/recurring_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['recurring_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['name'])) {
|
||||
$data['error_name'] = $this->error['name'];
|
||||
} else {
|
||||
$data['error_name'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['recurring_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/recurring/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/recurring/edit', 'user_token=' . $this->session->data['user_token'] . '&recurring_id=' . $this->request->get['recurring_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/recurring', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['recurring_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$recurring_info = $this->model_catalog_recurring->getRecurring($this->request->get['recurring_id']);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->load->model('localisation/language');
|
||||
|
||||
$data['languages'] = $this->model_localisation_language->getLanguages();
|
||||
|
||||
if (isset($this->request->post['recurring_description'])) {
|
||||
$data['recurring_description'] = $this->request->post['recurring_description'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['recurring_description'] = $this->model_catalog_recurring->getRecurringDescription($recurring_info['recurring_id']);
|
||||
} else {
|
||||
$data['recurring_description'] = array();
|
||||
}
|
||||
|
||||
if (isset($this->request->post['price'])) {
|
||||
$data['price'] = $this->request->post['price'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['price'] = $recurring_info['price'];
|
||||
} else {
|
||||
$data['price'] = 0;
|
||||
}
|
||||
|
||||
$data['frequencies'] = array();
|
||||
|
||||
$data['frequencies'][] = array(
|
||||
'text' => $this->language->get('text_day'),
|
||||
'value' => 'day'
|
||||
);
|
||||
|
||||
$data['frequencies'][] = array(
|
||||
'text' => $this->language->get('text_week'),
|
||||
'value' => 'week'
|
||||
);
|
||||
|
||||
$data['frequencies'][] = array(
|
||||
'text' => $this->language->get('text_semi_month'),
|
||||
'value' => 'semi_month'
|
||||
);
|
||||
|
||||
$data['frequencies'][] = array(
|
||||
'text' => $this->language->get('text_month'),
|
||||
'value' => 'month'
|
||||
);
|
||||
|
||||
$data['frequencies'][] = array(
|
||||
'text' => $this->language->get('text_year'),
|
||||
'value' => 'year'
|
||||
);
|
||||
|
||||
if (isset($this->request->post['frequency'])) {
|
||||
$data['frequency'] = $this->request->post['frequency'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['frequency'] = $recurring_info['frequency'];
|
||||
} else {
|
||||
$data['frequency'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['duration'])) {
|
||||
$data['duration'] = $this->request->post['duration'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['duration'] = $recurring_info['duration'];
|
||||
} else {
|
||||
$data['duration'] = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['cycle'])) {
|
||||
$data['cycle'] = $this->request->post['cycle'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['cycle'] = $recurring_info['cycle'];
|
||||
} else {
|
||||
$data['cycle'] = 1;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['status'])) {
|
||||
$data['status'] = $this->request->post['status'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['status'] = $recurring_info['status'];
|
||||
} else {
|
||||
$data['status'] = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['trial_price'])) {
|
||||
$data['trial_price'] = $this->request->post['trial_price'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['trial_price'] = $recurring_info['trial_price'];
|
||||
} else {
|
||||
$data['trial_price'] = 0.00;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['trial_frequency'])) {
|
||||
$data['trial_frequency'] = $this->request->post['trial_frequency'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['trial_frequency'] = $recurring_info['trial_frequency'];
|
||||
} else {
|
||||
$data['trial_frequency'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['trial_duration'])) {
|
||||
$data['trial_duration'] = $this->request->post['trial_duration'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['trial_duration'] = $recurring_info['trial_duration'];
|
||||
} else {
|
||||
$data['trial_duration'] = '0';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['trial_cycle'])) {
|
||||
$data['trial_cycle'] = $this->request->post['trial_cycle'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['trial_cycle'] = $recurring_info['trial_cycle'];
|
||||
} else {
|
||||
$data['trial_cycle'] = '1';
|
||||
}
|
||||
if (isset($this->request->post['trial_status'])) {
|
||||
$data['trial_status'] = $this->request->post['trial_status'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['trial_status'] = $recurring_info['trial_status'];
|
||||
} else {
|
||||
$data['trial_status'] = 0;
|
||||
}
|
||||
|
||||
if (isset($this->request->post['sort_order'])) {
|
||||
$data['sort_order'] = $this->request->post['sort_order'];
|
||||
} elseif (!empty($recurring_info)) {
|
||||
$data['sort_order'] = $recurring_info['sort_order'];
|
||||
} else {
|
||||
$data['sort_order'] = 0;
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/recurring_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/recurring')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
foreach ($this->request->post['recurring_description'] as $language_id => $value) {
|
||||
if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 255)) {
|
||||
$this->error['name'][$language_id] = $this->language->get('error_name');
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->error && !isset($this->error['warning'])) {
|
||||
$this->error['warning'] = $this->language->get('error_warning');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/recurring')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
foreach ($this->request->post['selected'] as $recurring_id) {
|
||||
$product_total = $this->model_catalog_product->getTotalProductsByProfileId($recurring_id);
|
||||
|
||||
if ($product_total) {
|
||||
$this->error['warning'] = sprintf($this->language->get('error_product'), $product_total);
|
||||
}
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateCopy() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/recurring')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,650 @@
|
||||
<?php
|
||||
// * @source See SOURCE.txt for source and other copyright.
|
||||
// * @license GNU General Public License version 3; see LICENSE.txt
|
||||
|
||||
class ControllerCatalogReview extends Controller {
|
||||
private $error = array();
|
||||
|
||||
public function index() {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
public function add() {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_review->addReview($this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function edit() {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
|
||||
$this->model_catalog_review->editReview($this->request->get['review_id'], $this->request->post);
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getForm();
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$this->load->language('catalog/review');
|
||||
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
|
||||
$this->load->model('catalog/review');
|
||||
|
||||
if (isset($this->request->post['selected']) && $this->validateDelete()) {
|
||||
foreach ($this->request->post['selected'] as $review_id) {
|
||||
$this->model_catalog_review->deleteReview($review_id);
|
||||
}
|
||||
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$this->response->redirect($this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function getList() {
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$filter_product = $this->request->get['filter_product'];
|
||||
} else {
|
||||
$filter_product = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$filter_author = $this->request->get['filter_author'];
|
||||
} else {
|
||||
$filter_author = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$filter_status = $this->request->get['filter_status'];
|
||||
} else {
|
||||
$filter_status = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$filter_date_added = $this->request->get['filter_date_added'];
|
||||
} else {
|
||||
$filter_date_added = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$order = $this->request->get['order'];
|
||||
} else {
|
||||
$order = 'DESC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$sort = $this->request->get['sort'];
|
||||
} else {
|
||||
$sort = 'r.date_added';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$page = (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_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
$data['add'] = $this->url->link('catalog/review/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['delete'] = $this->url->link('catalog/review/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['enabled'] = $this->url->link('catalog/review/enable', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
$data['disabled'] = $this->url->link('catalog/review/disable', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
$data['reviews'] = array();
|
||||
|
||||
$filter_data = array(
|
||||
'filter_product' => $filter_product,
|
||||
'filter_author' => $filter_author,
|
||||
'filter_status' => $filter_status,
|
||||
'filter_date_added' => $filter_date_added,
|
||||
'sort' => $sort,
|
||||
'order' => $order,
|
||||
'start' => ($page - 1) * $this->config->get('config_limit_admin'),
|
||||
'limit' => $this->config->get('config_limit_admin')
|
||||
);
|
||||
|
||||
$review_total = $this->model_catalog_review->getTotalReviews($filter_data);
|
||||
|
||||
$results = $this->model_catalog_review->getReviews($filter_data);
|
||||
|
||||
foreach ($results as $result) {
|
||||
$data['reviews'][] = array(
|
||||
'review_id' => $result['review_id'],
|
||||
'name' => $result['name'],
|
||||
'author' => $result['author'],
|
||||
'rating' => $result['rating'],
|
||||
'status' => ($result['status']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
|
||||
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
||||
'edit' => $this->url->link('catalog/review/edit', 'user_token=' . $this->session->data['user_token'] . '&review_id=' . $result['review_id'] . $url, true)
|
||||
);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->session->data['success'])) {
|
||||
$data['success'] = $this->session->data['success'];
|
||||
|
||||
unset($this->session->data['success']);
|
||||
} else {
|
||||
$data['success'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['selected'])) {
|
||||
$data['selected'] = (array)$this->request->post['selected'];
|
||||
} else {
|
||||
$data['selected'] = array();
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if ($order == 'ASC') {
|
||||
$url .= '&order=DESC';
|
||||
} else {
|
||||
$url .= '&order=ASC';
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['sort_product'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=pd.name' . $url, true);
|
||||
$data['sort_author'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=r.author' . $url, true);
|
||||
$data['sort_rating'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=r.rating' . $url, true);
|
||||
$data['sort_status'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=r.status' . $url, true);
|
||||
$data['sort_date_added'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . '&sort=r.date_added' . $url, true);
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
$pagination = new Pagination();
|
||||
$pagination->total = $review_total;
|
||||
$pagination->page = $page;
|
||||
$pagination->limit = $this->config->get('config_limit_admin');
|
||||
$pagination->url = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
|
||||
|
||||
$data['pagination'] = $pagination->render();
|
||||
|
||||
$data['results'] = sprintf($this->language->get('text_pagination'), ($review_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($review_total - $this->config->get('config_limit_admin'))) ? $review_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $review_total, ceil($review_total / $this->config->get('config_limit_admin')));
|
||||
|
||||
$data['filter_product'] = $filter_product;
|
||||
$data['filter_author'] = $filter_author;
|
||||
$data['filter_status'] = $filter_status;
|
||||
$data['filter_date_added'] = $filter_date_added;
|
||||
|
||||
$data['sort'] = $sort;
|
||||
$data['order'] = $order;
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/review_list', $data));
|
||||
}
|
||||
|
||||
protected function getForm() {
|
||||
$data['text_form'] = !isset($this->request->get['review_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
|
||||
|
||||
if (isset($this->error['warning'])) {
|
||||
$data['error_warning'] = $this->error['warning'];
|
||||
} else {
|
||||
$data['error_warning'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['product'])) {
|
||||
$data['error_product'] = $this->error['product'];
|
||||
} else {
|
||||
$data['error_product'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['author'])) {
|
||||
$data['error_author'] = $this->error['author'];
|
||||
} else {
|
||||
$data['error_author'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['text'])) {
|
||||
$data['error_text'] = $this->error['text'];
|
||||
} else {
|
||||
$data['error_text'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->error['rating'])) {
|
||||
$data['error_rating'] = $this->error['rating'];
|
||||
} else {
|
||||
$data['error_rating'] = '';
|
||||
}
|
||||
|
||||
$url = '';
|
||||
|
||||
if (isset($this->request->get['filter_product'])) {
|
||||
$url .= '&filter_product=' . urlencode(html_entity_decode($this->request->get['filter_product'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_author'])) {
|
||||
$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_status'])) {
|
||||
$url .= '&filter_status=' . $this->request->get['filter_status'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['filter_date_added'])) {
|
||||
$url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
|
||||
$data['breadcrumbs'] = array();
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('text_home'),
|
||||
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
|
||||
);
|
||||
|
||||
$data['breadcrumbs'][] = array(
|
||||
'text' => $this->language->get('heading_title'),
|
||||
'href' => $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true)
|
||||
);
|
||||
|
||||
if (!isset($this->request->get['review_id'])) {
|
||||
$data['action'] = $this->url->link('catalog/review/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
} else {
|
||||
$data['action'] = $this->url->link('catalog/review/edit', 'user_token=' . $this->session->data['user_token'] . '&review_id=' . $this->request->get['review_id'] . $url, true);
|
||||
}
|
||||
|
||||
$data['cancel'] = $this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
||||
|
||||
if (isset($this->request->get['review_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
|
||||
$review_info = $this->model_catalog_review->getReview($this->request->get['review_id']);
|
||||
}
|
||||
|
||||
$data['user_token'] = $this->session->data['user_token'];
|
||||
|
||||
$this->load->model('catalog/product');
|
||||
|
||||
if (isset($this->request->post['product_id'])) {
|
||||
$data['product_id'] = $this->request->post['product_id'];
|
||||
} elseif (!empty($review_info)) {
|
||||
$data['product_id'] = $review_info['product_id'];
|
||||
} else {
|
||||
$data['product_id'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['product'])) {
|
||||
$data['product'] = $this->request->post['product'];
|
||||
} elseif (!empty($review_info)) {
|
||||
$data['product'] = $review_info['product'];
|
||||
} else {
|
||||
$data['product'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['author'])) {
|
||||
$data['author'] = $this->request->post['author'];
|
||||
} elseif (!empty($review_info)) {
|
||||
$data['author'] = $review_info['author'];
|
||||
} else {
|
||||
$data['author'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['text'])) {
|
||||
$data['text'] = $this->request->post['text'];
|
||||
} elseif (!empty($review_info)) {
|
||||
$data['text'] = $review_info['text'];
|
||||
} else {
|
||||
$data['text'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['rating'])) {
|
||||
$data['rating'] = $this->request->post['rating'];
|
||||
} elseif (!empty($review_info)) {
|
||||
$data['rating'] = $review_info['rating'];
|
||||
} else {
|
||||
$data['rating'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['date_added'])) {
|
||||
$data['date_added'] = $this->request->post['date_added'];
|
||||
} elseif (!empty($review_info)) {
|
||||
$data['date_added'] = ($review_info['date_added'] != '0000-00-00 00:00' ? $review_info['date_added'] : '');
|
||||
} else {
|
||||
$data['date_added'] = '';
|
||||
}
|
||||
|
||||
if (isset($this->request->post['status'])) {
|
||||
$data['status'] = $this->request->post['status'];
|
||||
} elseif (!empty($review_info)) {
|
||||
$data['status'] = $review_info['status'];
|
||||
} else {
|
||||
$data['status'] = '';
|
||||
}
|
||||
|
||||
$data['header'] = $this->load->controller('common/header');
|
||||
$data['column_left'] = $this->load->controller('common/column_left');
|
||||
$data['footer'] = $this->load->controller('common/footer');
|
||||
|
||||
$this->response->setOutput($this->load->view('catalog/review_form', $data));
|
||||
}
|
||||
|
||||
protected function validateForm() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/review')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
if (!$this->request->post['product_id']) {
|
||||
$this->error['product'] = $this->language->get('error_product');
|
||||
}
|
||||
|
||||
if ((utf8_strlen($this->request->post['author']) < 3) || (utf8_strlen($this->request->post['author']) > 64)) {
|
||||
$this->error['author'] = $this->language->get('error_author');
|
||||
}
|
||||
|
||||
if (utf8_strlen($this->request->post['text']) < 1) {
|
||||
$this->error['text'] = $this->language->get('error_text');
|
||||
}
|
||||
|
||||
if (!isset($this->request->post['rating']) || $this->request->post['rating'] < 0 || $this->request->post['rating'] > 5) {
|
||||
$this->error['rating'] = $this->language->get('error_rating');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
public function enable() {
|
||||
$this->load->language('catalog/review');
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
$this->load->model('catalog/review');
|
||||
if (isset($this->request->post['selected']) && $this->validateEnable()) {
|
||||
foreach ($this->request->post['selected'] as $review_id) {
|
||||
$data = array();
|
||||
$result = $this->model_catalog_review->getReview($review_id);
|
||||
foreach ($result as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
$data['status'] = 1;
|
||||
$this->model_catalog_review->editReview($review_id, $data);
|
||||
}
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
$url = '';
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
$this->response->redirect($this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
$this->getList();
|
||||
}
|
||||
public function disable() {
|
||||
$this->load->language('catalog/review');
|
||||
$this->document->setTitle($this->language->get('heading_title'));
|
||||
$this->load->model('catalog/review');
|
||||
if (isset($this->request->post['selected']) && $this->validateDisable()) {
|
||||
foreach ($this->request->post['selected'] as $review_id) {
|
||||
$data = array();
|
||||
$result = $this->model_catalog_review->getReview($review_id);
|
||||
foreach ($result as $key => $value) {
|
||||
$data[$key] = $value;
|
||||
}
|
||||
$data['status'] = 0;
|
||||
$this->model_catalog_review->editReview($review_id, $data);
|
||||
}
|
||||
$this->session->data['success'] = $this->language->get('text_success');
|
||||
$url = '';
|
||||
if (isset($this->request->get['page'])) {
|
||||
$url .= '&page=' . $this->request->get['page'];
|
||||
}
|
||||
if (isset($this->request->get['sort'])) {
|
||||
$url .= '&sort=' . $this->request->get['sort'];
|
||||
}
|
||||
if (isset($this->request->get['order'])) {
|
||||
$url .= '&order=' . $this->request->get['order'];
|
||||
}
|
||||
$this->response->redirect($this->url->link('catalog/review', 'user_token=' . $this->session->data['user_token'] . $url, true));
|
||||
}
|
||||
$this->getList();
|
||||
}
|
||||
|
||||
protected function validateEnable() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/review')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDisable() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/review')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
|
||||
protected function validateDelete() {
|
||||
if (!$this->user->hasPermission('modify', 'catalog/review')) {
|
||||
$this->error['warning'] = $this->language->get('error_permission');
|
||||
}
|
||||
|
||||
return !$this->error;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user