Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated: Customer deletion and ban process and added filters for the admin to view the banned customers. #1088

Merged
merged 14 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,27 @@
<label class="control-label col-lg-3">{l s='Status'}</label>
<div class="col-lg-9">
<p class="form-control-static">
{if $customer->active}
<span class="label label-success">
<i class="icon-check"></i>
{l s='Active'}
{if !$customer->deleted}
{if $customer->active}
<span class="label label-success">
<i class="icon-check"></i>
{l s='Active'}
</span>
{else}
<span class="label label-danger">
<i class="icon-remove"></i>
{l s='Inactive'}
</span>
{/if}
{elseif $customer->deleted == Customer::STATUS_BANNED}
<span class="label label-warning">
<i class="icon-remove"></i>
{l s='Banned'}
</span>
{else}
{elseif $customer->deleted == Customer::STATUS_DELETED}
<span class="label label-danger">
<i class="icon-remove"></i>
{l s='Inactive'}
{l s='Deleted'}
</span>
{/if}
</p>
Expand Down
5 changes: 4 additions & 1 deletion classes/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ class CustomerCore extends ObjectModel

public $groupBox;

const STATUS_BANNED = 1;
const STATUS_DELETED = 2;

protected $webserviceParameters = array(
'fields' => array(
'id_default_group' => array('xlink_resource' => 'groups'),
Expand Down Expand Up @@ -179,7 +182,7 @@ class CustomerCore extends ObjectModel
'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
'max_payment_days' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'deleted' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'copy_post' => false),
'note' => array('type' => self::TYPE_HTML, 'validate' => 'isCleanHtml', 'size' => 65000, 'copy_post' => false),
'is_guest' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool', 'copy_post' => false),
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'copy_post' => false),
Expand Down
16 changes: 14 additions & 2 deletions controllers/admin/AdminCustomersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ public function __construct()
'type' => 'datetime',
'search' => false,
'havingFilter' => true
),
'deleted' => array(
'title' => $this->l('Banned'),
'type' => 'bool',
'displayed' => false,
)
));

Expand Down Expand Up @@ -218,6 +223,12 @@ public function postProcess()
}

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

public function initContent()
Expand Down Expand Up @@ -753,6 +764,7 @@ public function renderKpis()
$helper->color = 'color2';
$helper->title = $this->l('Banned Customers', null, null, false);
$helper->subtitle = $this->l('All Time', null, null, false);
$helper->href = $this->context->link->getAdminLink('AdminCustomers').'&customerFilter_deleted=1';
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_banned_customers';
$helper->tooltip = $this->l('The total number of banned customers.', null, null, false);
$kpis[] = $helper;
Expand Down Expand Up @@ -962,7 +974,7 @@ public function processDelete()
if (Validate::isLoadedObject($objCustomer = $this->loadObject())) {
if ($this->delete_mode == 'real' && Order::getCustomerOrders($objCustomer->id, true)) {
$objCustomer->email = 'anonymous'.'-'.$objCustomer->id.'@'.Tools::link_rewrite(Configuration::get('PS_SHOP_NAME')).'_anonymous.com';
$objCustomer->deleted = 1;
$objCustomer->deleted = Customer::STATUS_DELETED;
if (!$objCustomer->update()) {
$this->errors[] = Tools::displayError('Some error ocurred while deleting the Customer');
return;
Expand Down Expand Up @@ -1003,7 +1015,7 @@ protected function processBulkDelete()
// check if customer has orders for email change else customer will be deleted
if (Order::getCustomerOrders($objCustomer->id, true)) {
$objCustomer->email = 'anonymous'.'-'.$objCustomer->id.'@'.Tools::getShopDomain();
$objCustomer->deleted = 1;
$objCustomer->deleted = Customer::STATUS_DELETED;
if ($objCustomer->update()) {
// unset the customer which is processed
// not processed customers will be deleted with default process if no errors are there
Expand Down
11 changes: 11 additions & 0 deletions modules/blocknewsletter/blocknewsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,23 @@ public function registerHooks()
'actionCustomerAccountAdd',
'registerGDPRConsent',
'actionExportGDPRData',
'actionObjectCustomerUpdateBefore',
'actionDeleteGDPRCustomer',
'actionObjectCustomerDeleteAfter',
)
);
}

public function hookActionObjectCustomerUpdateBefore($params)
{
$objCustomer = new Customer ($params['object']->id);
if ($params['object']->deleted == Customer::STATUS_DELETED
&& ($register_status = $this->isNewsletterRegistered($objCustomer->email))
) {
$this->unregister($objCustomer->email, $register_status);
}
}

public function hookActionObjectCustomerDeleteAfter($params)
{
$objCustomer = $params['object'];
Expand Down