Skip to content

Commit 4e754e7

Browse files
authored
Merge pull request #1088 from vishal-singh-webkul/gli-1868
Updated: Customer deletion and ban process and added filters for the admin to view the banned customers.
2 parents 8371a09 + 89f1a38 commit 4e754e7

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
lines changed

admin/themes/default/template/controllers/customers/helpers/view/view.tpl

+18-6
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,27 @@
146146
<label class="control-label col-lg-3">{l s='Status'}</label>
147147
<div class="col-lg-9">
148148
<p class="form-control-static">
149-
{if $customer->active}
150-
<span class="label label-success">
151-
<i class="icon-check"></i>
152-
{l s='Active'}
149+
{if !$customer->deleted}
150+
{if $customer->active}
151+
<span class="label label-success">
152+
<i class="icon-check"></i>
153+
{l s='Active'}
154+
</span>
155+
{else}
156+
<span class="label label-danger">
157+
<i class="icon-remove"></i>
158+
{l s='Inactive'}
159+
</span>
160+
{/if}
161+
{elseif $customer->deleted == Customer::STATUS_BANNED}
162+
<span class="label label-warning">
163+
<i class="icon-remove"></i>
164+
{l s='Banned'}
153165
</span>
154-
{else}
166+
{elseif $customer->deleted == Customer::STATUS_DELETED}
155167
<span class="label label-danger">
156168
<i class="icon-remove"></i>
157-
{l s='Inactive'}
169+
{l s='Deleted'}
158170
</span>
159171
{/if}
160172
</p>

classes/Customer.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class CustomerCore extends ObjectModel
135135

136136
public $groupBox;
137137

138+
const STATUS_BANNED = 1;
139+
const STATUS_DELETED = 2;
140+
138141
protected $webserviceParameters = array(
139142
'fields' => array(
140143
'id_default_group' => array('xlink_resource' => 'groups'),
@@ -179,7 +182,7 @@ class CustomerCore extends ObjectModel
179182
'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
180183
'max_payment_days' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
181184
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
182-
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
185+
'deleted' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
183186
'note' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'size' => 65000, 'copy_post' => false),
184187
'is_guest' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
185188
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),

controllers/admin/AdminCustomersController.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ public function __construct()
170170
'type' => 'datetime',
171171
'search' => false,
172172
'havingFilter' => true
173+
),
174+
'deleted' => array(
175+
'title' => $this->l('Banned'),
176+
'type' => 'bool',
177+
'displayed' => false,
173178
)
174179
));
175180

@@ -218,6 +223,12 @@ public function postProcess()
218223
}
219224

220225
parent::postProcess();
226+
// Added this to check if the filter for the banned(deleted) is used, since $this->delete = true will not display the deleted customers.
227+
$prefix = $this->getCookieFilterPrefix();
228+
$filters = $this->context->cookie->getFamily($prefix.$this->table.'Filter_');
229+
if (isset($filters[$prefix.$this->table.'Filter_deleted']) && $filters[$prefix.$this->table.'Filter_deleted'] == 1) {
230+
$this->deleted = false;
231+
}
221232
}
222233

223234
public function initContent()
@@ -753,6 +764,7 @@ public function renderKpis()
753764
$helper->color = 'color2';
754765
$helper->title = $this->l('Banned Customers', null, null, false);
755766
$helper->subtitle = $this->l('All Time', null, null, false);
767+
$helper->href = $this->context->link->getAdminLink('AdminCustomers').'&customerFilter_deleted=1';
756768
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_banned_customers';
757769
$helper->tooltip = $this->l('The total number of banned customers.', null, null, false);
758770
$kpis[] = $helper;
@@ -962,7 +974,7 @@ public function processDelete()
962974
if (Validate::isLoadedObject($objCustomer = $this->loadObject())) {
963975
if ($this->delete_mode == 'real' && Order::getCustomerOrders($objCustomer->id, true)) {
964976
$objCustomer->email = 'anonymous'.'-'.$objCustomer->id.'@'.Tools::link_rewrite(Configuration::get('PS_SHOP_NAME')).'_anonymous.com';
965-
$objCustomer->deleted = 1;
977+
$objCustomer->deleted = Customer::STATUS_DELETED;
966978
if (!$objCustomer->update()) {
967979
$this->errors[] = Tools::displayError('Some error ocurred while deleting the Customer');
968980
return;
@@ -1003,7 +1015,7 @@ protected function processBulkDelete()
10031015
// check if customer has orders for email change else customer will be deleted
10041016
if (Order::getCustomerOrders($objCustomer->id, true)) {
10051017
$objCustomer->email = 'anonymous'.'-'.$objCustomer->id.'@'.Tools::getShopDomain();
1006-
$objCustomer->deleted = 1;
1018+
$objCustomer->deleted = Customer::STATUS_DELETED;
10071019
if ($objCustomer->update()) {
10081020
// unset the customer which is processed
10091021
// not processed customers will be deleted with default process if no errors are there

modules/blocknewsletter/blocknewsletter.php

+11
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,23 @@ public function registerHooks()
8484
'actionCustomerAccountAdd',
8585
'registerGDPRConsent',
8686
'actionExportGDPRData',
87+
'actionObjectCustomerUpdateBefore',
8788
'actionDeleteGDPRCustomer',
8889
'actionObjectCustomerDeleteAfter',
8990
)
9091
);
9192
}
9293

94+
public function hookActionObjectCustomerUpdateBefore($params)
95+
{
96+
$objCustomer = new Customer ($params['object']->id);
97+
if ($params['object']->deleted == Customer::STATUS_DELETED
98+
&& ($register_status = $this->isNewsletterRegistered($objCustomer->email))
99+
) {
100+
$this->unregister($objCustomer->email, $register_status);
101+
}
102+
}
103+
93104
public function hookActionObjectCustomerDeleteAfter($params)
94105
{
95106
$objCustomer = $params['object'];

0 commit comments

Comments
 (0)