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 deleted file mode 100644 index 57882264b..000000000 --- a/admin-dev/themes/default/template/controllers/orders/helpers/list/list_header.tpl +++ /dev/null @@ -1,57 +0,0 @@ -{* -* 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 -*} -{extends file="helpers/list/list_header.tpl"} -{block name='leadin'} -
-
-
-
-
-
- Conversion Rate
30 days
- 1.89% -
-
-
- - - -{/block} diff --git a/admin-dev/themes/default/template/helpers/kpi/kpi.tpl b/admin-dev/themes/default/template/helpers/kpi/kpi.tpl index 46c513813..7e957b7b0 100644 --- a/admin-dev/themes/default/template/helpers/kpi/kpi.tpl +++ b/admin-dev/themes/default/template/helpers/kpi/kpi.tpl @@ -23,22 +23,70 @@ * International Registered Trademark & Property of PrestaShop SA *}
- + {if $icon}{/if} + {if $chart} +
+
+
+
+ {/if} {$title|escape}
{$subtitle|escape}
{$value|escape}
+ {if $source != ''} +{/if} + +{if $chart} + {/if} \ No newline at end of file diff --git a/classes/helper/HelperKpi.php b/classes/helper/HelperKpi.php index ff708b2c0..d171aaac2 100644 --- a/classes/helper/HelperKpi.php +++ b/classes/helper/HelperKpi.php @@ -31,10 +31,12 @@ class HelperKpiCore extends Helper public $id; public $icon; + public $chart; public $color; public $title; public $subtitle; public $value; + public $data; public $source; public function generate() @@ -44,10 +46,12 @@ class HelperKpiCore extends Helper $this->tpl->assign(array( 'id' => $this->id, 'icon' => $this->icon, + 'chart' => (bool)$this->chart, 'color' => $this->color, 'title' => $this->title, 'subtitle' => $this->subtitle, 'value' => $this->value, + 'data' => $this->data, 'source' => $this->source )); return $this->tpl->fetch(); diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 2ba694b22..c4ddef13c 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -1245,7 +1245,21 @@ class AdminOrdersControllerCore extends AdminController $kpis = array(); /* The data generation is located in AdminStatsControllerCore */ - + + $helper = new HelperKpi(); + $helper->id = 'box-conversion-rate'; + $helper->chart = true; + $helper->color = 'color1'; + $helper->title = $this->l('Conversion Rate'); + $helper->subtitle = $this->l('30 days'); + if (Configuration::get('PS_KPI_CONVERSION_RATE') !== false) + $helper->value = Configuration::get('PS_KPI_CONVERSION_RATE'); + if (Configuration::get('PS_KPI_CONVERSION_RATE_CHART') !== false) + $helper->data = Configuration::get('PS_KPI_CONVERSION_RATE_CHART'); + if (Configuration::get('PS_KPI_CONVERSION_RATE_EXPIRE') < $time) + $helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=conversion_rate'; + $kpis[] = $helper->generate(); + $helper = new HelperKpi(); $helper->id = 'box-carts'; $helper->icon = 'icon-shopping-cart'; @@ -1257,7 +1271,7 @@ class AdminOrdersControllerCore extends AdminController 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'; @@ -1269,12 +1283,12 @@ class AdminOrdersControllerCore extends AdminController 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 HelperKpi(); $helper->id = 'box-net-profit-visitor'; $helper->icon = 'icon-user'; $helper->color = 'color4'; - $helper->title = $this->l('Net Profit per Visitor '); + $helper->title = $this->l('Net Profit per Visitor'); $helper->subtitle = $this->l('30 days'); if (Configuration::get('PS_KPI_NETPROFIT_VISITOR') !== false) $helper->value = Configuration::get('PS_KPI_NETPROFIT_VISITOR'); diff --git a/controllers/admin/AdminStatsController.php b/controllers/admin/AdminStatsController.php index 5df49e2e8..8b5caf854 100644 --- a/controllers/admin/AdminStatsController.php +++ b/controllers/admin/AdminStatsController.php @@ -31,6 +31,64 @@ class AdminStatsControllerCore extends AdminStatsTabController $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); switch (Tools::getValue('kpi')) { + case 'conversion_rate': + $visits = array(); + $gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false; + if (Validate::isLoadedObject($gapi) && $gapi->isConfigured()) + { + if ($result = $gapi->requestReportData('ga:date', 'ga:visits', date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day')), null, null, 1, 30)) + foreach ($result as $row) + $visits[strtotime(preg_replace('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', '$1-$2-$3', $row['dimensions']['date']))] = $row['metrics']['visits']; + } + else + { + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + SELECT + LEFT(`date_add`, 10) as date, + COUNT(*) as visits + FROM `'._DB_PREFIX_.'connections` + WHERE `date_add` 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(false).' + GROUP BY LEFT(`date_add`, 10)'); + foreach ($result as $row) + $visits[strtotime($row['date'])] = $row['visits']; + } + $orders = array(); + $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' + SELECT + LEFT(`invoice_date`, 10) as date, + COUNT(*) as orders + 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).' + GROUP BY LEFT(`invoice_date`, 10)'); + foreach ($result as $row) + $orders[strtotime($row['date'])] = $row['orders']; + + $data = array(); + $from = strtotime(date('Y-m-d 00:00:00', strtotime('-31 day'))); + $to = strtotime(date('Y-m-d 23:59:59', strtotime('-1 day'))); + for ($date = $from; $date <= $to; $date = strtotime('+1 day', $date)) + { + $data[$date] = 0; + if (isset($visits[$date]) && $visits[$date]) + $data[$date] = round(100 * ((isset($orders[$date]) && $orders[$date]) ? $orders[$date] : 0) / $visits[$date], 2); + } + + $visits_sum = array_sum($visits); + $orders_sum = array_sum($orders); + if ($visits_sum) + $value = round(100 * $orders_sum / $visits_sum, 2); + elseif ($orders_sum) + $value = '∞'; + else + $value = 0; + $value .= '%'; + + Configuration::updateValue('PS_KPI_CONVERSION_RATE_CHART', Tools::jsonEncode($data)); + Configuration::updateValue('PS_KPI_CONVERSION_RATE', $value); + Configuration::updateValue('PS_KPI_CONVERSION_RATE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day')))); + break; case 'abandoned_cart': $value = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT COUNT(*) @@ -54,7 +112,6 @@ class AdminStatsControllerCore extends AdminStatsTabController Configuration::updateValue('PS_KPI_AVG_ORDER_VALUE_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day')))); break; case 'netprofit_visitor': - $gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false; if (Validate::isLoadedObject($gapi) && $gapi->isConfigured()) { @@ -68,7 +125,7 @@ class AdminStatsControllerCore extends AdminStatsTabController SELECT COUNT(DISTINCT id_guest) FROM `'._DB_PREFIX_.'connections` WHERE `date_add` 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(false).''); + '.Shop::addSqlRestriction(false)); } $row_products = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' @@ -114,7 +171,12 @@ class AdminStatsControllerCore extends AdminStatsTabController $value = false; } if ($value !== false) - die(Tools::jsonEncode(array('value' => $value))); + { + $array = array('value' => $value); + if (isset($data)) + $array['data'] = $data; + die(Tools::jsonEncode($array)); + } die(Tools::jsonEncode(array('has_errors' => true))); } } \ No newline at end of file diff --git a/modules/dashtrends/dashtrends.php b/modules/dashtrends/dashtrends.php index 88184c2aa..0bb40c68f 100644 --- a/modules/dashtrends/dashtrends.php +++ b/modules/dashtrends/dashtrends.php @@ -102,7 +102,7 @@ class Dashtrends extends Module $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT LEFT(`date_add`, 10) as date, - COUNT(`id_connections`) as visits_score + COUNT(*) as visits_score FROM `'._DB_PREFIX_.'connections` WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'" '.Shop::addSqlRestriction(false).' @@ -115,7 +115,7 @@ class Dashtrends extends Module $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS(' SELECT LEFT(`invoice_date`, 10) as date, - COUNT(`id_order`) as orders_score, + COUNT(*) as orders_score, SUM(`total_paid_tax_excl` / `conversion_rate`) as total_paid_tax_excl, SUM(`total_discounts_tax_excl` / `conversion_rate`) as total_discounts_tax_excl FROM `'._DB_PREFIX_.'orders`