Skip to content

Commit

Permalink
Added some changes in Marketing Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
condor2 committed Mar 1, 2024
1 parent 9df3103 commit 554dcc1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
54 changes: 26 additions & 28 deletions upload/admin/controller/marketing/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ public function send(): void {

if (!$json) {
$this->load->model('setting/store');
$this->load->model('customer/customer');
$this->load->model('customer/customer_group');
$this->load->model('marketing/affiliate');
$this->load->model('sale/order');

$store_info = $this->model_setting_store->getStore($this->request->post['store_id']);

Expand All @@ -116,14 +120,6 @@ public function send(): void {
$setting = $this->model_setting_setting->getSetting('config', $this->request->post['store_id']);
$store_email = $setting['config_email'] ?? $this->config->get('config_email');

$this->load->model('customer/customer');

$this->load->model('customer/customer_group');

$this->load->model('marketing/affiliate');

$this->load->model('sale/order');

if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
Expand Down Expand Up @@ -176,23 +172,21 @@ public function send(): void {
$emails[$result['customer_id']] = $result['email'];
}
break;
case 'customer':if (!empty($this->request->post['customer'])) {
$start = ($page - 1) * 10;
case 'customer':
if (!empty($this->request->post['customer'])) {
$customers = array_slice($this->request->post['customer'], ($page - 1) * 10, 10);

for ($i = 0; $i < 10; $i++) {
if (isset($this->request->post['customer'][($start + $i)])) {
$customer_id = $this->request->post['customer'][($start + $i)];
foreach ($customers as $customer_id) {
$customer_info = $this->model_customer_customer->getCustomer($customer_id);

if ($customer_info) {
$emails[] = $customer_info['email'];
}
}
}

$email_total = count($this->request->post['customer']);
}
break;
$email_total = count($emails);
}
// no break
case 'affiliate_all':$affiliate_data = [
'start' => ($page - 1) * 10,
'limit' => 10
Expand All @@ -206,22 +200,20 @@ public function send(): void {
$emails[] = $result['email'];
}
break;
case 'affiliate':if (!empty($this->request->post['affiliate'])) {
$start = ($page - 1) * 10;
case 'affiliate':
if (!empty($this->request->post['affiliate'])) {
$affiliates = array_slice($this->request->post['affiliate'], ($page - 1) * 10, 10);

for ($i = 0; $i < 10; $i++) {
if (isset($this->request->post['affiliate'][($start + $i)])) {
$affiliate_id = $this->request->post['affiliate'][($start + $i)];
foreach ($affiliates as $affiliate_id) {
$affiliate_info = $this->model_marketing_affiliate->getAffiliate($affiliate_id);

if ($affiliate_info) {
$emails[] = $affiliate_info['email'];
}
}
}
}

$email_total = count($this->request->post['affiliate']);
$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']);
Expand All @@ -241,8 +233,14 @@ public function send(): void {
$start = ($page - 1) * 10;
$end = $start + 10;

if ($end < $email_total) {
$json['success'] = sprintf($this->language->get('text_sent'), $start, $email_total);
if ($page == 1 && $email_total < 10) {
$json['success'] = sprintf($this->language->get('text_sent'), $email_total, $email_total);
} elseif ($page == 1 && $email_total > 10) {
$json['success'] = sprintf($this->language->get('text_sent'), 10, $email_total);
} elseif ($page > 1 && $email_total < ($page * 10)) {
$json['success'] = sprintf($this->language->get('text_sent'), $email_total, $email_total);
} else {
$json['success'] = sprintf($this->language->get('text_sent'), $end, $email_total);
}

if ($end < $email_total) {
Expand All @@ -251,7 +249,7 @@ public function send(): void {
$json['next'] = '';
}

$message = '<html dir="ltr" lang="en">' . "\n";
$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";
Expand Down
5 changes: 2 additions & 3 deletions upload/admin/view/template/marketing/contact.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ function send(url) {
beforeSend: function() {
$('#button-send').button('loading');
},
complete: function() {
$('#button-send').button('reset');
},
success: function(json) {
$('.alert, .text-danger').remove();
Expand Down Expand Up @@ -228,6 +225,8 @@ function send(url) {
if (json['next']) {
send(json['next']);
} else {
$('#button-send').button('reset');
}
},
error: function(xhr, ajaxOptions, thrownError) {
Expand Down

0 comments on commit 554dcc1

Please sign in to comment.