first commit

This commit is contained in:
sujan
2024-08-06 18:06:00 +05:45
commit a2fa49071a
2745 changed files with 391199 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,256 @@
<?php
namespace Opencart\Admin\Controller\Marketing;
/**
* Class Contact
*
* @package Opencart\Admin\Controller\Marketing
*/
class Contact extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('marketing/contact');
$this->document->setTitle($this->language->get('heading_title'));
$this->document->addScript('view/javascript/ckeditor/ckeditor.js');
$this->document->addScript('view/javascript/ckeditor/adapters/jquery.js');
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('marketing/contact', 'user_token=' . $this->session->data['user_token'])
];
$this->load->model('setting/store');
$data['stores'] = $this->model_setting_store->getStores();
$this->load->model('customer/customer_group');
$data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups();
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('marketing/contact', $data));
}
/**
* @return void
* @throws \Exception
*/
public function send(): void {
$this->load->language('marketing/contact');
$json = [];
if (!$this->user->hasPermission('modify', 'marketing/contact')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if (!$this->request->post['subject']) {
$json['error']['subject'] = $this->language->get('error_subject');
}
if (!$this->request->post['message']) {
$json['error']['message'] = $this->language->get('error_message');
}
if (!$json) {
$this->load->model('setting/store');
$this->load->model('setting/setting');
$this->load->model('customer/customer');
$this->load->model('sale/order');
$store_info = $this->model_setting_store->getStore($this->request->post['store_id']);
if ($store_info) {
$store_name = $store_info['name'];
} else {
$store_name = $this->config->get('config_name');
}
$setting = $this->model_setting_setting->getSetting('config', $this->request->post['store_id']);
$store_email = isset($setting['config_email']) ? $setting['config_email'] : $this->config->get('config_email');
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$email_total = 0;
$emails = [];
switch ($this->request->post['to']) {
case 'newsletter':
$customer_data = [
'filter_newsletter' => 1,
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$email_total = $this->model_customer_customer->getTotalCustomers($customer_data);
$results = $this->model_customer_customer->getCustomers($customer_data);
foreach ($results as $result) {
$emails[] = $result['email'];
}
break;
case 'customer_all':
$customer_data = [
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$email_total = $this->model_customer_customer->getTotalCustomers($customer_data);
$results = $this->model_customer_customer->getCustomers($customer_data);
foreach ($results as $result) {
$emails[] = $result['email'];
}
break;
case 'customer_group':
$customer_data = [
'filter_customer_group_id' => $this->request->post['customer_group_id'],
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$email_total = $this->model_customer_customer->getTotalCustomers($customer_data);
$results = $this->model_customer_customer->getCustomers($customer_data);
foreach ($results as $result) {
$emails[$result['customer_id']] = $result['email'];
}
break;
case 'customer':
if (!empty($this->request->post['customer'])) {
$email_total = count($this->request->post['customer']);
$customers = array_slice($this->request->post['customer'], ($page - 1) * $limit, $limit);
foreach ($customers as $customer_id) {
$customer_info = $this->model_customer_customer->getCustomer($customer_id);
if ($customer_info) {
$emails[] = $customer_info['email'];
}
}
}
break;
case 'affiliate_all':
$affiliate_data = [
'filter_affiliate' => 1,
'start' => ($page - 1) * $limit,
'limit' => $limit
];
$email_total = $this->model_customer_customer->getTotalCustomers($affiliate_data);
$results = $this->model_customer_customer->getCustomers($affiliate_data);
foreach ($results as $result) {
$emails[] = $result['email'];
}
break;
case 'affiliate':
if (!empty($this->request->post['affiliate'])) {
$affiliates = array_slice($this->request->post['affiliate'], ($page - 1) * $limit, $limit);
foreach ($affiliates as $affiliate_id) {
$affiliate_info = $this->model_customer_customer->getCustomer($affiliate_id);
if ($affiliate_info) {
$emails[] = $affiliate_info['email'];
}
}
$email_total = count($this->request->post['affiliate']);
}
break;
case 'product':
if (isset($this->request->post['product'])) {
$email_total = $this->model_sale_order->getTotalEmailsByProductsOrdered($this->request->post['product']);
$results = $this->model_sale_order->getEmailsByProductsOrdered($this->request->post['product'], ($page - 1) * $limit, $limit);
foreach ($results as $result) {
$emails[] = $result['email'];
}
}
break;
}
if ($emails) {
$start = ($page - 1) * $limit;
$end = $start + $limit;
if ($end < $email_total) {
$json['text'] = sprintf($this->language->get('text_sent'), $start ? $start : 1, $email_total);
$json['next'] = $this->url->link('marketing/contact.send', 'user_token=' . $this->session->data['user_token'] . '&page=' . ($page + 1), true);
} else {
$json['success'] = $this->language->get('text_success');
$json['next'] = '';
}
$message = '<html dir="ltr" lang="' . $this->language->get('code') . '">' . "\n";
$message .= ' <head>' . "\n";
$message .= ' <title>' . $this->request->post['subject'] . '</title>' . "\n";
$message .= ' <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">' . "\n";
$message .= ' </head>' . "\n";
$message .= ' <body>' . html_entity_decode($this->request->post['message'], ENT_QUOTES, 'UTF-8') . '</body>' . "\n";
$message .= '</html>' . "\n";
if ($this->config->get('config_mail_engine')) {
$mail_option = [
'parameter' => $this->config->get('config_mail_parameter'),
'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
'smtp_username' => $this->config->get('config_mail_smtp_username'),
'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
'smtp_port' => $this->config->get('config_mail_smtp_port'),
'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
];
$mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
foreach ($emails as $email) {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
$mail->setTo(trim($email));
$mail->setFrom($store_email);
$mail->setSender(html_entity_decode($store_name, ENT_QUOTES, 'UTF-8'));
$mail->setSubject(html_entity_decode($this->request->post['subject'], ENT_QUOTES, 'UTF-8'));
$mail->setHtml($message);
$mail->send();
}
}
}
} else {
$json['error']['warning'] = $this->language->get('error_email');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}

View File

@ -0,0 +1,481 @@
<?php
namespace Opencart\Admin\Controller\Marketing;
/**
* Class Coupon
*
* @package Opencart\Admin\Controller\Marketing
*/
class Coupon extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('marketing/coupon');
$this->document->setTitle($this->language->get('heading_title'));
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['add'] = $this->url->link('marketing/coupon.form', 'user_token=' . $this->session->data['user_token'] . $url);
$data['delete'] = $this->url->link('marketing/coupon.delete', 'user_token=' . $this->session->data['user_token']);
$data['list'] = $this->getList();
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('marketing/coupon', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('marketing/coupon');
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
protected function getList(): string {
if (isset($this->request->get['sort'])) {
$sort = (string)$this->request->get['sort'];
} else {
$sort = 'name';
}
if (isset($this->request->get['order'])) {
$order = (string)$this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['action'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . $url);
$data['coupons'] = [];
$filter_data = [
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
'limit' => $this->config->get('config_pagination_admin')
];
$this->load->model('marketing/coupon');
$coupon_total = $this->model_marketing_coupon->getTotalCoupons();
$results = $this->model_marketing_coupon->getCoupons($filter_data);
foreach ($results as $result) {
$data['coupons'][] = [
'coupon_id' => $result['coupon_id'],
'name' => $result['name'],
'code' => $result['code'],
'discount' => $result['discount'],
'date_start' => date($this->language->get('date_format_short'), strtotime($result['date_start'])),
'date_end' => date($this->language->get('date_format_short'), strtotime($result['date_end'])),
'status' => $result['status'],
'edit' => $this->url->link('marketing/coupon.form', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $result['coupon_id'] . $url)
];
}
$url = '';
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
$data['sort_name'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url);
$data['sort_code'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=code' . $url);
$data['sort_discount'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=discount' . $url);
$data['sort_date_start'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=date_start' . $url);
$data['sort_date_end'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=date_end' . $url);
$data['sort_status'] = $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url);
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $coupon_total,
'page' => $page,
'limit' => $this->config->get('config_pagination_admin'),
'url' => $this->url->link('marketing/coupon.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($coupon_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($coupon_total - $this->config->get('config_pagination_admin'))) ? $coupon_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $coupon_total, ceil($coupon_total / $this->config->get('config_pagination_admin')));
$data['sort'] = $sort;
$data['order'] = $order;
return $this->load->view('marketing/coupon_list', $data);
}
/**
* @return void
*/
public function form(): void {
$this->load->language('marketing/coupon');
$this->document->setTitle($this->language->get('heading_title'));
$data['text_form'] = !isset($this->request->get['coupon_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
$url = '';
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['save'] = $this->url->link('marketing/coupon.save', 'user_token=' . $this->session->data['user_token']);
$data['back'] = $this->url->link('marketing/coupon', 'user_token=' . $this->session->data['user_token'] . $url);
if (isset($this->request->get['coupon_id'])) {
$this->load->model('marketing/coupon');
$coupon_info = $this->model_marketing_coupon->getCoupon($this->request->get['coupon_id']);
}
if (isset($this->request->get['coupon_id'])) {
$data['coupon_id'] = (int)$this->request->get['coupon_id'];
} else {
$data['coupon_id'] = 0;
}
if (!empty($coupon_info)) {
$data['name'] = $coupon_info['name'];
} else {
$data['name'] = '';
}
if (!empty($coupon_info)) {
$data['code'] = $coupon_info['code'];
} else {
$data['code'] = '';
}
if (!empty($coupon_info)) {
$data['type'] = $coupon_info['type'];
} else {
$data['type'] = '';
}
if (!empty($coupon_info)) {
$data['discount'] = $coupon_info['discount'];
} else {
$data['discount'] = '';
}
if (!empty($coupon_info)) {
$data['logged'] = $coupon_info['logged'];
} else {
$data['logged'] = '';
}
if (!empty($coupon_info)) {
$data['shipping'] = $coupon_info['shipping'];
} else {
$data['shipping'] = '';
}
if (!empty($coupon_info)) {
$data['total'] = $coupon_info['total'];
} else {
$data['total'] = '';
}
if (!empty($coupon_info)) {
$products = $this->model_marketing_coupon->getProducts($this->request->get['coupon_id']);
} else {
$products = [];
}
$this->load->model('catalog/product');
$data['coupon_products'] = [];
foreach ($products as $product_id) {
$product_info = $this->model_catalog_product->getProduct($product_id);
if ($product_info) {
$data['coupon_products'][] = [
'product_id' => $product_info['product_id'],
'name' => $product_info['name']
];
}
}
if (!empty($coupon_info)) {
$categories = $this->model_marketing_coupon->getCategories($this->request->get['coupon_id']);
} else {
$categories = [];
}
$this->load->model('catalog/category');
$data['coupon_categories'] = [];
foreach ($categories as $category_id) {
$category_info = $this->model_catalog_category->getCategory($category_id);
if ($category_info) {
$data['coupon_categories'][] = [
'category_id' => $category_info['category_id'],
'name' => ($category_info['path'] ? $category_info['path'] . ' &gt; ' : '') . $category_info['name']
];
}
}
if (!empty($coupon_info)) {
$data['date_start'] = ($coupon_info['date_start'] != '0000-00-00' ? $coupon_info['date_start'] : '');
} else {
$data['date_start'] = date('Y-m-d', time());
}
if (!empty($coupon_info)) {
$data['date_end'] = ($coupon_info['date_end'] != '0000-00-00' ? $coupon_info['date_end'] : '');
} else {
$data['date_end'] = date('Y-m-d', strtotime('+1 month'));
}
if (!empty($coupon_info)) {
$data['uses_total'] = $coupon_info['uses_total'];
} else {
$data['uses_total'] = 1;
}
if (!empty($coupon_info)) {
$data['uses_customer'] = $coupon_info['uses_customer'];
} else {
$data['uses_customer'] = 1;
}
if (!empty($coupon_info)) {
$data['status'] = $coupon_info['status'];
} else {
$data['status'] = true;
}
$data['history'] = $this->getHistory();
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('marketing/coupon_form', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('marketing/coupon');
$json = [];
if (!$this->user->hasPermission('modify', 'marketing/coupon')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 128)) {
$json['error']['name'] = $this->language->get('error_name');
}
if ((oc_strlen($this->request->post['code']) < 3) || (oc_strlen($this->request->post['code']) > 20)) {
$json['error']['code'] = $this->language->get('error_code');
}
$this->load->model('marketing/coupon');
$coupon_info = $this->model_marketing_coupon->getCouponByCode($this->request->post['code']);
if ($coupon_info) {
if (!isset($this->request->post['coupon_id'])) {
$json['error']['warning'] = $this->language->get('error_exists');
} elseif ($coupon_info['coupon_id'] != (int)$this->request->post['coupon_id']) {
$json['error']['warning'] = $this->language->get('error_exists');
}
}
if (!$json) {
if (!$this->request->post['coupon_id']) {
$json['coupon_id'] = $this->model_marketing_coupon->addCoupon($this->request->post);
} else {
$this->model_marketing_coupon->editCoupon($this->request->post['coupon_id'], $this->request->post);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('marketing/coupon');
$json = [];
if (isset($this->request->post['selected'])) {
$selected = $this->request->post['selected'];
} else {
$selected = [];
}
if (!$this->user->hasPermission('modify', 'marketing/coupon')) {
$json['error'] = $this->language->get('error_permission');
}
if (!$json) {
$this->load->model('marketing/coupon');
foreach ($selected as $coupon_id) {
$this->model_marketing_coupon->deleteCoupon($coupon_id);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function history(): void {
$this->load->language('marketing/coupon');
$this->response->setOutput($this->getHistory());
}
/**
* @return string
*/
public function getHistory(): string {
if (isset($this->request->get['coupon_id'])) {
$coupon_id = (int)$this->request->get['coupon_id'];
} else {
$coupon_id = 0;
}
if (isset($this->request->get['page']) && $this->request->get['route'] == 'marketing/coupon.history') {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$this->load->model('marketing/coupon');
$data['histories'] = [];
$results = $this->model_marketing_coupon->getHistories($coupon_id, ($page - 1) * $limit, $limit);
foreach ($results as $result) {
$data['histories'][] = [
'order_id' => $result['order_id'],
'customer' => $result['customer'],
'amount' => $result['amount'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
];
}
$history_total = $this->model_marketing_coupon->getTotalHistories($coupon_id);
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $history_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('marketing/coupon.history', 'user_token=' . $this->session->data['user_token'] . '&coupon_id=' . $coupon_id . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($history_total - $limit)) ? $history_total : ((($page - 1) * $limit) + $limit), $history_total, ceil($history_total / $limit));
return $this->load->view('marketing/coupon_history', $data);
}
}

View File

@ -0,0 +1,530 @@
<?php
namespace Opencart\Admin\Controller\Marketing;
/**
* Class Marketing
*
* @package Opencart\Admin\Controller\Marketing
*/
class Marketing extends \Opencart\System\Engine\Controller {
/**
* @return void
*/
public function index(): void {
$this->load->language('marketing/marketing');
$this->document->setTitle($this->language->get('heading_title'));
if (isset($this->request->get['filter_name'])) {
$filter_name = $this->request->get['filter_name'];
} else {
$filter_name = '';
}
if (isset($this->request->get['filter_code'])) {
$filter_code = $this->request->get['filter_code'];
} else {
$filter_code = '';
}
if (isset($this->request->get['filter_date_from'])) {
$filter_date_from = $this->request->get['filter_date_from'];
} else {
$filter_date_from = '';
}
if (isset($this->request->get['filter_date_to'])) {
$filter_date_to = $this->request->get['filter_date_to'];
} else {
$filter_date_to = '';
}
$url = '';
if (isset($this->request->get['filter_name'])) {
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_code'])) {
$url .= '&filter_code=' . $this->request->get['filter_code'];
}
if (isset($this->request->get['filter_date_from'])) {
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
}
if (isset($this->request->get['filter_date_to'])) {
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['add'] = $this->url->link('marketing/marketing.form', 'user_token=' . $this->session->data['user_token'] . $url);
$data['delete'] = $this->url->link('marketing/marketing.delete', 'user_token=' . $this->session->data['user_token']);
$data['list'] = $this->getList();
$data['filter_name'] = $filter_name;
$data['filter_code'] = $filter_code;
$data['filter_date_from'] = $filter_date_from;
$data['filter_date_to'] = $filter_date_to;
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('marketing/marketing', $data));
}
/**
* @return void
*/
public function list(): void {
$this->load->language('marketing/marketing');
$this->response->setOutput($this->getList());
}
/**
* @return string
*/
protected function getList(): string {
if (isset($this->request->get['filter_name'])) {
$filter_name = $this->request->get['filter_name'];
} else {
$filter_name = '';
}
if (isset($this->request->get['filter_code'])) {
$filter_code = $this->request->get['filter_code'];
} else {
$filter_code = '';
}
if (isset($this->request->get['filter_date_from'])) {
$filter_date_from = (string)$this->request->get['filter_date_from'];
} else {
$filter_date_from = '';
}
if (isset($this->request->get['filter_date_to'])) {
$filter_date_to = (string)$this->request->get['filter_date_to'];
} else {
$filter_date_to = '';
}
if (isset($this->request->get['sort'])) {
$sort = (string)$this->request->get['sort'];
} else {
$sort = 'm.name';
}
if (isset($this->request->get['order'])) {
$order = (string)$this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$url = '';
if (isset($this->request->get['filter_name'])) {
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_code'])) {
$url .= '&filter_code=' . $this->request->get['filter_code'];
}
if (isset($this->request->get['filter_date_from'])) {
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
}
if (isset($this->request->get['filter_date_to'])) {
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['action'] = $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . $url);
$data['marketings'] = [];
$filter_data = [
'filter_name' => $filter_name,
'filter_code' => $filter_code,
'filter_date_from' => $filter_date_from,
'filter_date_to' => $filter_date_to,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
'limit' => $this->config->get('config_pagination_admin')
];
$this->load->model('marketing/marketing');
$marketing_total = $this->model_marketing_marketing->getTotalMarketings($filter_data);
$results = $this->model_marketing_marketing->getMarketings($filter_data);
foreach ($results as $result) {
$data['marketings'][] = [
'marketing_id' => $result['marketing_id'],
'name' => $result['name'],
'code' => $result['code'],
'clicks' => $result['clicks'],
'orders' => $result['orders'],
'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
'edit' => $this->url->link('marketing/marketing.form', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $result['marketing_id'] . $url)
];
}
$url = '';
if (isset($this->request->get['filter_name'])) {
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_code'])) {
$url .= '&filter_code=' . $this->request->get['filter_code'];
}
if (isset($this->request->get['filter_date_from'])) {
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
}
if (isset($this->request->get['filter_date_to'])) {
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
}
if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}
$data['sort_name'] = $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . '&sort=m.name' . $url);
$data['sort_code'] = $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . '&sort=m.code' . $url);
$data['sort_date_added'] = $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . '&sort=m.date_added' . $url);
$url = '';
if (isset($this->request->get['filter_name'])) {
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_code'])) {
$url .= '&filter_code=' . $this->request->get['filter_code'];
}
if (isset($this->request->get['filter_date_from'])) {
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
}
if (isset($this->request->get['filter_date_to'])) {
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $marketing_total,
'page' => $page,
'limit' => $this->config->get('config_pagination_admin'),
'url' => $this->url->link('marketing/marketing.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($marketing_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($marketing_total - $this->config->get('config_pagination_admin'))) ? $marketing_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $marketing_total, ceil($marketing_total / $this->config->get('config_pagination_admin')));
$data['sort'] = $sort;
$data['order'] = $order;
return $this->load->view('marketing/marketing_list', $data);
}
/**
* @return void
*/
public function form(): void {
$this->load->language('marketing/marketing');
$this->document->setTitle($this->language->get('heading_title'));
$data['text_form'] = !isset($this->request->get['marketing_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
$url = '';
if (isset($this->request->get['filter_name'])) {
$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
}
if (isset($this->request->get['filter_code'])) {
$url .= '&filter_code=' . $this->request->get['filter_code'];
}
if (isset($this->request->get['filter_date_from'])) {
$url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
}
if (isset($this->request->get['filter_date_to'])) {
$url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
];
$data['breadcrumbs'][] = [
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url)
];
$data['save'] = $this->url->link('marketing/marketing.save', 'user_token=' . $this->session->data['user_token']);
$data['back'] = $this->url->link('marketing/marketing', 'user_token=' . $this->session->data['user_token'] . $url);
if (isset($this->request->get['marketing_id'])) {
$this->load->model('marketing/marketing');
$marketing_info = $this->model_marketing_marketing->getMarketing($this->request->get['marketing_id']);
}
if (isset($this->request->get['marketing_id'])) {
$data['marketing_id'] = (int)$this->request->get['marketing_id'];
} else {
$data['marketing_id'] = 0;
}
$data['store'] = HTTP_CATALOG;
if (!empty($marketing_info)) {
$data['name'] = $marketing_info['name'];
} else {
$data['name'] = '';
}
if (!empty($marketing_info)) {
$data['description'] = $marketing_info['description'];
} else {
$data['description'] = '';
}
if (!empty($marketing_info)) {
$data['code'] = $marketing_info['code'];
} else {
$data['code'] = uniqid();
}
$data['report'] = $this->getReport();
$data['user_token'] = $this->session->data['user_token'];
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
$this->response->setOutput($this->load->view('marketing/marketing_form', $data));
}
/**
* @return void
*/
public function save(): void {
$this->load->language('marketing/marketing');
$json = [];
if (!$this->user->hasPermission('modify', 'marketing/marketing')) {
$json['error']['warning'] = $this->language->get('error_permission');
}
if ((oc_strlen($this->request->post['name']) < 1) || (oc_strlen($this->request->post['name']) > 32)) {
$json['error']['name'] = $this->language->get('error_name');
}
if (!$this->request->post['code']) {
$json['error']['code'] = $this->language->get('error_code');
}
$this->load->model('marketing/marketing');
$marketing_info = $this->model_marketing_marketing->getMarketingByCode($this->request->post['code']);
if ($marketing_info && (!isset($this->request->post['marketing_id']) || ($this->request->post['marketing_id'] != $marketing_info['marketing_id']))) {
$json['error']['code'] = $this->language->get('error_exists');
}
if (!$json) {
if (!$this->request->post['marketing_id']) {
$json['marketing_id'] = $this->model_marketing_marketing->addMarketing($this->request->post);
} else {
$this->model_marketing_marketing->editMarketing($this->request->post['marketing_id'], $this->request->post);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function delete(): void {
$this->load->language('marketing/marketing');
$json = [];
if (isset($this->request->post['selected'])) {
$selected = $this->request->post['selected'];
} else {
$selected = [];
}
if (!$this->user->hasPermission('modify', 'marketing/marketing')) {
$json['error'] = $this->language->get('error_permission');
}
if (!$json) {
$this->load->model('marketing/marketing');
foreach ($selected as $marketing_id) {
$this->model_marketing_marketing->deleteMarketing($marketing_id);
}
$json['success'] = $this->language->get('text_success');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
/**
* @return void
*/
public function report(): void {
$this->load->language('marketing/marketing');
$this->response->setOutput($this->getReport());
}
/**
* @return string
*/
public function getReport(): string {
if (isset($this->request->get['marketing_id'])) {
$marketing_id = (int)$this->request->get['marketing_id'];
} else {
$marketing_id = 0;
}
if (isset($this->request->get['page']) && $this->request->get['route'] == 'marketing/marketing.report') {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$limit = 10;
$data['reports'] = [];
$this->load->model('marketing/marketing');
$this->load->model('customer/customer');
$this->load->model('setting/store');
$results = $this->model_marketing_marketing->getReports($marketing_id, ($page - 1) * $limit, $limit);
foreach ($results as $result) {
$store_info = $this->model_setting_store->getStore($result['store_id']);
if ($store_info) {
$store = $store_info['name'];
} elseif (!$result['store_id']) {
$store = $this->config->get('config_name');
} else {
$store = '';
}
$data['reports'][] = [
'ip' => $result['ip'],
'account' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']),
'store' => $store,
'country' => $result['country'],
'date_added' => date($this->language->get('datetime_format'), strtotime($result['date_added'])),
'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip'])
];
}
$report_total = $this->model_marketing_marketing->getTotalReports($marketing_id);
$data['pagination'] = $this->load->controller('common/pagination', [
'total' => $report_total,
'page' => $page,
'limit' => $limit,
'url' => $this->url->link('marketing/marketing.report', 'user_token=' . $this->session->data['user_token'] . '&marketing_id=' . $marketing_id . '&page={page}')
]);
$data['results'] = sprintf($this->language->get('text_pagination'), ($report_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($report_total - $limit)) ? $report_total : ((($page - 1) * $limit) + $limit), $report_total, ceil($report_total / $limit));
return $this->load->view('marketing/marketing_report', $data);
}
}