Merge pull request #1039 from vishal-singh-webkul/gli-1926

Updated: Abandoned cart Filter and the Abandoned cart KPI in the admin carts controller.
This commit is contained in:
Rohit Jain
2024-05-30 13:01:42 +05:30
committed by GitHub
3 changed files with 40 additions and 16 deletions

View File

@@ -42,11 +42,11 @@ class AdminCartsControllerCore extends AdminController
$this->allow_export = true;
$this->_orderWay = 'DESC';
$this->context = Context::getContext();
$this->_select = 'CONCAT(c.`firstname`, \' \', c.`lastname`) `customer`, a.id_cart total,
TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', a.`date_add`)) AS `time_diff`,
IFNULL(GROUP_CONCAT(DISTINCT o.`id_order`), 0) AS `ids_order`,
IF (IFNULL(o.id_order, \''.$this->l('Non ordered cart').'\') = \''.$this->l('Non ordered cart').'\', IF(TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', a.`date_add`)) > 86400, \''.$this->l('Abandoned cart').'\', \''.$this->l('Non ordered cart').'\'), GROUP_CONCAT(DISTINCT o.`id_order`)) AS filter_ids_order,
IF (IFNULL(o.id_order, \''.$this->l('Non ordered cart').'\') = \''.$this->l('Non ordered cart').'\', IF(TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', a.`date_add`)) > '._TIME_1_DAY_.', \''.$this->l('Abandoned cart').'\', \''.$this->l('Non ordered cart').'\'), GROUP_CONCAT(DISTINCT o.`id_order`)) AS filter_ids_order,
IF(o.id_order, 1, 0) badge_success, IF(o.id_order, 0, 1) badge_danger, IF(co.id_guest, 1, 0) id_guest';
$this->_join = 'LEFT JOIN '._DB_PREFIX_.'customer c ON (c.id_customer = a.id_customer)
LEFT JOIN '._DB_PREFIX_.'currency cu ON (cu.id_currency = a.id_currency)
@@ -54,10 +54,6 @@ class AdminCartsControllerCore extends AdminController
LEFT JOIN `'._DB_PREFIX_.'connections` co ON (a.id_guest = co.id_guest AND TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', co.`date_add`)) < 1800)';
$this->_group = ' GROUP BY a.`id_cart`';
if (Tools::getValue('action') == 'filterOnlyAbandonedCarts') {
$this->_filterHaving = ' AND `ids_order` = 0 AND `time_diff` > 86400';
}
$this->fields_list = array(
'id_cart' => array(
'title' => $this->l('ID'),
@@ -117,10 +113,32 @@ class AdminCartsControllerCore extends AdminController
}
parent::__construct();
$this->list_no_link = true;
}
public function postProcess()
{
if (Tools::getValue('action') == 'filterOnlyAbandonedCarts') {
$this->processResetFilters();
$this->context->cookie->{'submitFilter'.$this->table} = true;
$prefix = $this->getCookieFilterPrefix();
$this->context->cookie->{$prefix.$this->table.'Filter_filter_ids_order'} = $this->l('Abandoned cart');
if (($dateFrom = Tools::getValue('date_from'))
&& ($dateTo = Tools::getValue('date_to'))
&& strtotime($dateTo) >= strtotime($dateFrom)
) {
//Updating the date format of the filter dates to the required format.
$dateFrom = date('Y-m-d', strtotime($dateFrom));
$dateTo = date('Y-m-d', strtotime($dateTo));
$this->context->cookie->{$prefix.$this->table.'Filter_'.$this->fields_list['date_add']['filter_key']} = json_encode(array($dateFrom, $dateTo));
}
$this->redirect_after = $this->context->link->getAdminLink('AdminCarts');
}
parent::postProcess();
}
public function getOrderColumn($idsOrder, $tr)
{
$smartyVars = array();
@@ -129,7 +147,7 @@ class AdminCartsControllerCore extends AdminController
$smartyVars['type'] = 'orders';
$smartyVars['ids_order'] = $idsOrder;
} else {
if ($tr['time_diff'] > 86400) {
if ($tr['time_diff'] > _TIME_1_DAY_) {
$smartyVars['type'] = 'abandoned';
} else {
$smartyVars['type'] = 'non_orderd';
@@ -184,7 +202,7 @@ class AdminCartsControllerCore extends AdminController
$date_from = date(Context::getContext()->language->date_format_lite, strtotime('-2 day'));
$date_to = date(Context::getContext()->language->date_format_lite, strtotime('-1 day'));
$helper->subtitle = sprintf($this->l('From %s to %s', null, null, false), $date_from, $date_to);
$helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts';
$helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts&date_from='.$date_from.'&date_to='.$date_to;
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart';
$kpis[] = $helper;

View File

@@ -2429,7 +2429,7 @@ class AdminOrdersControllerCore extends AdminController
$dateFrom = date(Context::getContext()->language->date_format_lite, strtotime('-2 day'));
$dateTo = date(Context::getContext()->language->date_format_lite, strtotime('-1 day'));
$helper->subtitle = sprintf($this->l('From %s to %s', null, null, false), $dateFrom, $dateTo);
$helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts';
$helper->href = $this->context->link->getAdminLink('AdminCarts').'&action=filterOnlyAbandonedCarts&date_from='.$dateFrom.'&date_to='.$dateTo;
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart';
$helper->tooltip = $this->l('Total number of abandoned carts in given period of time.', null, null, false);
$kpis[] = $helper;

View File

@@ -78,13 +78,15 @@ class AdminStatsControllerCore extends AdminStatsTabController
return $visits;
}
public static function getAbandonedCarts($date_from, $date_to)
public static function getAbandonedCarts($date_from, $date_to, $timeDiff = false)
{
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(DISTINCT id_guest)
FROM `'._DB_PREFIX_.'cart`
WHERE `date_add` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'"
AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'orders` WHERE `'._DB_PREFIX_.'orders`.id_cart = `'._DB_PREFIX_.'cart`.id_cart)
SELECT COUNT(`id_cart`)
FROM `'._DB_PREFIX_.'cart` c
WHERE `date_add` BETWEEN "'.pSQL($date_from).'" AND "'.pSQL($date_to).'"'.
(($timeDiff) ? 'AND TIME_TO_SEC(TIMEDIFF(\''.pSQL(date('Y-m-d H:i:00', time())).'\', `date_add`)) > '.$timeDiff : ' ').'
AND NOT EXISTS (SELECT 1 FROM `'._DB_PREFIX_.'orders` o WHERE o.`id_cart` = c.`id_cart`)
'.Shop::addSqlRestriction());
}
@@ -638,7 +640,11 @@ class AdminStatsControllerCore extends AdminStatsTabController
break;
case 'abandoned_cart':
$value = AdminStatsController::getAbandonedCarts(date('Y-m-d H:i:s', strtotime('-2 day')), date('Y-m-d H:i:s', strtotime('-1 day')));
$value = AdminStatsController::getAbandonedCarts(
date('Y-m-d', strtotime('-2 day')).' 0:0:0',
date('Y-m-d', strtotime('-1 day')).' 23:59:59',
_TIME_1_DAY_
);
break;
case 'installed_modules':