Added: option to view new customers in Admin Customer list using the KPI and the new customers option in dashboard

This commit is contained in:
vishalsingh.qlo325
2024-05-28 17:09:18 +05:30
parent 19c4e45320
commit cbf7a64e11
4 changed files with 26 additions and 2 deletions

View File

@@ -217,6 +217,23 @@ class AdminCustomersControllerCore extends AdminController
$this->redirect_after = $this->context->link->getAdminLink('AdminCustomers');
}
if (Tools::getValue('action') == 'filterOnlyNewCustomer') {
if (($dateFrom = Tools::getValue('date_from'))
&& ($dateTo = Tools::getValue('date_to'))
&& strtotime($dateTo) >= strtotime($dateFrom)
) {
$this->processResetFilters();
$this->context->cookie->{'submitFilter'.$this->table} = true;
$prefix = $this->getCookieFilterPrefix();
//Updating the date format of the filter dates to the desired format.
$dateFrom = date('Y-m-d', strtotime($dateFrom));
$dateTo = date('Y-m-d', strtotime($dateTo));
$this->context->cookie->{$prefix.$this->table.'Filter_date_add'} = json_encode(array($dateFrom, $dateTo));
}
$this->redirect_after = $this->context->link->getAdminLink('AdminCustomers');
}
parent::postProcess();
}
@@ -739,6 +756,9 @@ class AdminCustomersControllerCore extends AdminController
$helper->color = 'color4';
$helper->title = $this->l('New Customers', null, null, false);
$nbDaysNewCustomers = Validate::isUnsignedInt(Configuration::get('PS_KPI_NEW_CUSTOMERS_NB_DAYS')) ? Configuration::get('PS_KPI_NEW_CUSTOMERS_NB_DAYS') : 30;
$date_from = date('Y-m-d', strtotime('-'.$nbDaysNewCustomers.' day'));
$date_to = date('Y-m-d');
$helper->href = $this->context->link->getAdminLink('AdminCustomers').'&filterOnlyNewCustomer=1&date_from='.$date_from.'&date_to='.$date_to;
$helper->subtitle = sprintf($this->l('%d Days', null, null, false), (int) $nbDaysNewCustomers);
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=total_new_customers';
$helper->tooltip = $this->l('The total number of new customers who registered in given period of time.', null, null, false);

View File

@@ -1885,7 +1885,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
public static function getTotalNewCustomers($nbDaysNewCustomers)
{
$maxDateAdd = date('Y-m-d H:i:s', strtotime('-'.$nbDaysNewCustomers.' day'));
$maxDateAdd = date('Y-m-d', strtotime('-'.$nbDaysNewCustomers.' day'));
$sql = 'SELECT COUNT(c.`id_customer`)
FROM `'._DB_PREFIX_.'customer` c
WHERE c.`date_add` >= "'.pSQL($maxDateAdd).'" AND c.`deleted` = 0';

View File

@@ -58,6 +58,8 @@ $(document).ready(function() {
$('#date-start').change(function() {
start = Date.parseDate($('#date-start').val(), 'Y-m-d');
end = Date.parseDate($('#date-end').val(), 'Y-m-d');
var url = $('#dash_filter_new_customers').data('href') + '&date_from='+start.format('Y-m-d')+ '&date_to='+ end.format('Y-m-d');
$('#dash_filter_new_customers').attr('href', url);
$('#customers-newsletters-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format)));
$('#traffic-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format)));
@@ -66,6 +68,8 @@ $(document).ready(function() {
$('#date-end').change(function() {
start = Date.parseDate($('#date-start').val(), 'Y-m-d');
end = Date.parseDate($('#date-end').val(), 'Y-m-d');
var url = $('#dash_filter_new_customers').data('href') + '&date_from='+start.format('Y-m-d')+ '&date_to='+ end.format('Y-m-d');
$('#dash_filter_new_customers').attr('href', url);
$('#customers-newsletters-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format)));
$('#traffic-subtitle').html(sprintf(date_subtitle, start.format(date_format), end.format(date_format)));

View File

@@ -121,7 +121,7 @@
<ul class="stats-list">
<li>
<span class="item-label">
<a href="{$link->getAdminLink("AdminCustomers")|escape:"html":"UTF-8"}" target="_blank">
<a href="#" data-href="{$link->getAdminLink("AdminCustomers")|escape:"html":"UTF-8"}&filterOnlyNewCustomer=1" id="dash_filter_new_customers" target="_blank">
<span>{l s="New Customers" mod='dashactivity'}</span>
</a>
</span>