diff --git a/admin-dev/themes/default/template/controllers/orders/helpers/list/list_header.tpl b/admin-dev/themes/default/template/controllers/orders/helpers/list/list_header.tpl index 48c6adde9..bb6fc4589 100644 --- a/admin-dev/themes/default/template/controllers/orders/helpers/list/list_header.tpl +++ b/admin-dev/themes/default/template/controllers/orders/helpers/list/list_header.tpl @@ -39,18 +39,6 @@ Net Profit per visitor
30 days
$2.12 - -
- - Average order value
30 days
- $78.36 -
- -
- - Carts abandoned
Today
- 14 -
diff --git a/admin-dev/themes/default/template/helpers/kpi/kpi.tpl b/admin-dev/themes/default/template/helpers/kpi/kpi.tpl new file mode 100644 index 000000000..46c513813 --- /dev/null +++ b/admin-dev/themes/default/template/helpers/kpi/kpi.tpl @@ -0,0 +1,44 @@ +{* +* 2007-2013 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-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +
+ + {$title|escape}
{$subtitle|escape}
+ {$value|escape} +
+{if $source != ''} + +{/if} \ No newline at end of file diff --git a/admin-dev/themes/default/template/helpers/kpi/row.tpl b/admin-dev/themes/default/template/helpers/kpi/row.tpl new file mode 100644 index 000000000..cb33a4afe --- /dev/null +++ b/admin-dev/themes/default/template/helpers/kpi/row.tpl @@ -0,0 +1,31 @@ +{* +* 2007-2013 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-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +
+
+ {foreach $kpis as $kpi} + {$kpi} + {/foreach} +
+
\ No newline at end of file diff --git a/cache/class_index.php b/cache/class_index.php index 50f612e9d..33fe6a8d7 100644 --- a/cache/class_index.php +++ b/cache/class_index.php @@ -362,6 +362,10 @@ 'HelperFormCore' => 'classes/helper/HelperForm.php', 'HelperHelpAccess' => '', 'HelperHelpAccessCore' => 'classes/helper/HelperHelpAccess.php', + 'HelperKpi' => '', + 'HelperKpiCore' => 'classes/helper/HelperKpi.php', + 'HelperKpiRow' => '', + 'HelperKpiRowCore' => 'classes/helper/HelperKpiRow.php', 'HelperList' => '', 'HelperListCore' => 'classes/helper/HelperList.php', 'HelperOptions' => '', diff --git a/classes/controller/AdminController.php b/classes/controller/AdminController.php index e1df32feb..eac02bbf2 100644 --- a/classes/controller/AdminController.php +++ b/classes/controller/AdminController.php @@ -1522,6 +1522,7 @@ class AdminControllerCore extends Controller elseif (!$this->ajax) { $this->content .= $this->renderModulesList(); + $this->content .= $this->renderKpis(); $this->content .= $this->renderList(); $this->content .= $this->renderOptions(); @@ -1729,6 +1730,10 @@ class AdminControllerCore extends Controller return $form; } } + + public function renderKpis() + { + } /** * Function used to render the options for this controller @@ -1810,7 +1815,6 @@ class AdminControllerCore extends Controller public function setMedia() { - $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_); $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath); diff --git a/classes/helper/HelperKpi.php b/classes/helper/HelperKpi.php new file mode 100644 index 000000000..ff708b2c0 --- /dev/null +++ b/classes/helper/HelperKpi.php @@ -0,0 +1,55 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class HelperKpiCore extends Helper +{ + public $base_folder = 'helpers/kpi/'; + public $base_tpl = 'kpi.tpl'; + + public $id; + public $icon; + public $color; + public $title; + public $subtitle; + public $value; + public $source; + + public function generate() + { + $this->tpl = $this->createTemplate($this->base_tpl); + + $this->tpl->assign(array( + 'id' => $this->id, + 'icon' => $this->icon, + 'color' => $this->color, + 'title' => $this->title, + 'subtitle' => $this->subtitle, + 'value' => $this->value, + 'source' => $this->source + )); + return $this->tpl->fetch(); + } +} \ No newline at end of file diff --git a/classes/helper/HelperKpiRow.php b/classes/helper/HelperKpiRow.php new file mode 100644 index 000000000..6f85581ae --- /dev/null +++ b/classes/helper/HelperKpiRow.php @@ -0,0 +1,41 @@ + +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class HelperKpiRowCore extends Helper +{ + public $base_folder = 'helpers/kpi/'; + public $base_tpl = 'row.tpl'; + + public $kpis = array(); + + public function generate() + { + $this->tpl = $this->createTemplate($this->base_tpl); + + $this->tpl->assign('kpis', $this->kpis); + return $this->tpl->fetch(); + } +} \ No newline at end of file diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index ffcdd5be2..56f8b4f40 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1238,6 +1238,40 @@ class AdminOrdersControllerCore extends AdminController parent::postProcess(); } + + public function renderKpis() + { + $time = time(); + $kpis = array(); + + $helper = new HelperKpi(); + $helper->id = 'box-carts'; + $helper->icon = 'icon-shopping-cart'; + $helper->color = 'color2'; + $helper->title = $this->l('Abandoned Carts'); + $helper->subtitle = $this->l('Today'); + if (Configuration::get('PS_KPI_ABANDONED_CARTS') !== false) + $helper->value = Configuration::get('PS_KPI_ABANDONED_CARTS'); + if (Configuration::get('PS_KPI_ABANDONED_CARTS_EXPIRE') < $time) + $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=abandoned_cart'; + $kpis[] = $helper->generate(); + + $helper = new HelperKpi(); + $helper->id = 'box-average-order'; + $helper->icon = 'icon-money'; + $helper->color = 'color3'; + $helper->title = $this->l('Average Order Value'); + $helper->subtitle = $this->l('30 days'); + if (Configuration::get('PS_KPI_AVG_ORDER_VALUE') !== false) + $helper->value = Configuration::get('PS_KPI_AVERAGE_ORDER_VALUE'); + if (Configuration::get('PS_KPI_AVG_ORDER_VALUE_EXPIRE') < $time) + $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=average_order_value'; + $kpis[] = $helper->generate(); + + $helper = new HelperKpiRow(); + $helper->kpis = $kpis; + return $helper->generate(); + } public function renderView() { diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 3d049c89e..d3510846f 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -26,4 +26,38 @@ class AdminStatsControllerCore extends AdminStatsTabController { + public function displayAjaxGetKpi() + { + $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); + switch (Tools::getValue('kpi')) + { + case 'abandoned_cart': + $value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT COUNT(*) + FROM `'._DB_PREFIX_.'cart` + WHERE `date_add` BETWEEN "'.pSQL(date('Y-m-d')).' 00:00:00" AND "'.pSQL(date('Y-m-d')).' 23:59:59" + AND id_cart NOT IN (SELECT id_cart FROM `'._DB_PREFIX_.'orders`) + '.Shop::addSqlRestriction(Shop::SHARE_ORDER)); + Configuration::updateValue('PS_KPI_ABANDONED_CARTS', $value); + Configuration::updateValue('PS_KPI_ABANDONED_CARTS_EXPIRE', strtotime('+10 min')); + break; + case 'average_order_value': + $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' + SELECT + COUNT(`id_order`) as orders, + SUM(`total_paid_tax_excl` / `conversion_rate`) as total_paid_tax_excl + FROM `'._DB_PREFIX_.'orders` + WHERE `invoice_date` BETWEEN "'.pSQL(date('Y-m-d', strtotime('-31 day'))).' 00:00:00" AND "'.pSQL(date('Y-m-d', strtotime('-1 day'))).' 23:59:59" + '.Shop::addSqlRestriction(Shop::SHARE_ORDER)); + $value = Tools::displayPrice($row['orders'] ? $row['total_paid_tax_excl'] / $row['orders'] : 0, $currency); + Configuration::updateValue('PS_KPI_AVG_ORDER_VALUE', $value); + Configuration::updateValue('PS_KPI_AVG_ORDER_VALUE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day')))); + break; + default: + $value = false; + } + if ($value !== false) + die(Tools::jsonEncode(array('value' => $value))); + die(Tools::jsonEncode(array('has_errors' => true))); + } } \ No newline at end of file diff --git a/controllers/admin/AdminStatsTabController.php b/controllers/admin/AdminStatsTabController.php index eeb70e0a7..8c2c0e157 100644 --- a/controllers/admin/AdminStatsTabController.php +++ b/controllers/admin/AdminStatsTabController.php @@ -36,6 +36,9 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor public function initContent() { + if ($this->ajax) + return; + $this->initTabModuleList(); $this->addToolBarModulesListButton(); $this->toolbar_title = $this->l('Stats', 'AdminStatsTab');