diff --git a/admin/themes/default/template/controllers/carts/_orders.tpl b/admin/themes/default/template/controllers/carts/_orders.tpl new file mode 100644 index 000000000..a27311ef6 --- /dev/null +++ b/admin/themes/default/template/controllers/carts/_orders.tpl @@ -0,0 +1,34 @@ +{* +* 2007-2017 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2017 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if $type == 'orders' && isset($ids_order)} + {foreach from=$ids_order item=id_order name=orders} + #{$id_order}{if !$smarty.foreach.orders.last},{/if} + {/foreach} +{elseif $type == 'abandoned'} + {l s='Abandoned cart'} +{elseif $type == 'non_orderd'} + {l s='Non-orderd cart'} +{/if} diff --git a/admin/themes/default/template/controllers/carts/helpers/view/view.tpl b/admin/themes/default/template/controllers/carts/helpers/view/view.tpl index 053883255..7f8a5e8d1 100644 --- a/admin/themes/default/template/controllers/carts/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/carts/helpers/view/view.tpl @@ -59,13 +59,13 @@ {else} -

{l s='Guest not registered'}

+

{l s='Guest not registered.'}

{/if}
-

{l s='Order information'}

+

{l s='Order(s) Information'}

{if is_array($cart_orders) && count($cart_orders)} {foreach from=$cart_orders item=$cart_order}

{l s='Order #%d' sprintf=$cart_order.id_order|string_format:"%06d"}

diff --git a/controllers/admin/AdminCartsController.php b/controllers/admin/AdminCartsController.php index 2bca4d30c..a1dd38f88 100644 --- a/controllers/admin/AdminCartsController.php +++ b/controllers/admin/AdminCartsController.php @@ -43,17 +43,18 @@ class AdminCartsControllerCore extends AdminController $this->_orderWay = 'DESC'; $this->context = Context::getContext(); - $this->_select = 'CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) `customer`, a.id_cart total, - IF (IFNULL(o.id_order, \''.$this->l('Non ordered').'\') = \''.$this->l('Non ordered').'\', 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').'\'), o.id_order) AS status, 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->_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(o.`id_order`), 0) AS `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) LEFT JOIN '._DB_PREFIX_.'orders o ON (o.id_cart = a.id_cart) 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') && Tools::getValue('action') == 'filterOnlyAbandonedCarts') { - $this->_having = 'status = \''.$this->l('Abandoned cart').'\''; - } else { - $this->_use_found_rows = false; + if (Tools::getValue('action') == 'filterAbandonedCarts') { + $this->_filterHaving = ' AND `ids_order` = 0 AND `time_diff` > 86400'; } $this->fields_list = array( @@ -62,11 +63,12 @@ class AdminCartsControllerCore extends AdminController 'align' => 'text-center', 'class' => 'fixed-width-xs' ), - 'status' => array( + 'ids_order' => array( 'title' => $this->l('Order ID'), 'align' => 'text-center', - 'badge_danger' => true, - 'havingFilter' => true + 'havingFilter' => true, + 'filter_key' => 'ids_order', + 'callback' => 'getOrderColumn', ), 'customer' => array( 'title' => $this->l('Customer'), @@ -114,6 +116,29 @@ class AdminCartsControllerCore extends AdminController } parent::__construct(); + + $this->list_no_link = true; + } + + public function getOrderColumn($idsOrder, $tr) + { + $smartyVars = array(); + if ($idsOrder) { + $idsOrder = explode(',', $idsOrder); + $smartyVars['type'] = 'orders'; + $smartyVars['ids_order'] = $idsOrder; + } else { + if ($tr['time_diff'] > 86400) { + $smartyVars['type'] = 'abandoned'; + } else { + $smartyVars['type'] = 'non_orderd'; + } + } + + $tpl = $this->createTemplate('_orders.tpl'); + $tpl->assign($smartyVars); + + return $tpl->fetch(); } public function initPageHeaderToolbar() @@ -160,7 +185,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=filterAbandonedCarts'; if (ConfigurationKPI::get('ABANDONED_CARTS') !== false) { $helper->value = ConfigurationKPI::get('ABANDONED_CARTS'); } @@ -225,10 +250,10 @@ class AdminCartsControllerCore extends AdminController if (Validate::isLoadedObject($objOrder)) { $tax_calculation_method = $objOrder->getTaxCalculationMethod(); $id_shop = (int)$objOrder->id_shop; - } else { - $id_shop = (int)$cart->id_shop; - $tax_calculation_method = Group::getPriceDisplayMethod(Group::getCurrent()->id); } + } else { + $id_shop = (int)$cart->id_shop; + $tax_calculation_method = Group::getPriceDisplayMethod(Group::getCurrent()->id); } if ($tax_calculation_method == PS_TAX_EXC) { @@ -959,7 +984,7 @@ class AdminCartsControllerCore extends AdminController $skip_list = array(); foreach ($this->_list as $row) { - if (isset($row['id_order']) && is_numeric($row['id_order'])) { + if (isset($row['ids_order']) && $row['ids_order'] != '0') { $skip_list[] = $row['id_cart']; } }