// Added configuration checks to the Google Analytics modules

// Implemented the first real data in the dashboard
This commit is contained in:
Damien Metzger
2013-09-02 20:18:51 +02:00
parent 268183f4d2
commit 1fc507d8d2
2 changed files with 61 additions and 25 deletions
+37 -15
View File
@@ -54,23 +54,45 @@ class Dashtrends extends Module
public function hookDashboardDatas($params)
{
$gapi = Module::isInstalled('gapi') ? Module::getInstanceByName('gapi') : false;
if (Validate::isLoadedObject($gapi))
{
$visits_score = 0;
if ($result = $gapi->requestReportData('', 'ga:visits', $this->context->employee->stats_date_from, $this->context->employee->stats_date_to, null, null, 1, 1))
$visits_score = $result[0]['metrics']['visits'];
}
else
{
$visits_score = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(c.`id_connections`)
FROM `'._DB_PREFIX_.'connections` c
WHERE c.`date_add` BETWEEN '.ModuleGraph::getDateBetween().'
'.Shop::addSqlRestriction(false, 'c'));
}
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(o.`id_order`) as orders_score, SUM(o.`total_paid_tax_excl` / o.conversion_rate) as sales_score
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`invoice_date` BETWEEN '.ModuleGraph::getDateBetween().'
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o'));
extract($row);
return array(
'data_value' => array(
'sales_score' => Tools::displayPrice(151.365),
'orders_score' => 120,
'cart_value_score' => Tools::displayPrice(35),
'visits_score' => 12,
'convertion_rate_score' => 4,
'net_profits_score' => Tools::displayPrice(42),
),
'sales_score' => Tools::displayPrice((float)$sales_score),
'orders_score' => $orders_score,
'cart_value_score' => Tools::displayPrice($orders_score ? $sales_score / $orders_score : 0),
'visits_score' => $visits_score,
'convertion_rate_score' => $visits_score ? 100 * $orders_score / $visits_score : 0,
'net_profits_score' => Tools::displayPrice(0),
),
'data_trends' => array(
'sales_score_trends' => array('way' => 'up', 'value' => 0.66),
'orders_score_trends' => array('way' => 'down', 'value' => 0.66),
'cart_value_score_trends' => array('way' => 'up', 'value' => 0.66),
'visits_score_trends' => array('way' => 'down', 'value' => 0.66),
'convertion_rate_score_trends' => array('way' => 'up', 'value' => 0.66),
'net_profits_score_trends' => array('way' => 'up', 'value' => 0.66)
)
);
'sales_score_trends' => array('way' => 'up', 'value' => 0.42),
'orders_score_trends' => array('way' => 'down', 'value' => 0.42),
'cart_value_score_trends' => array('way' => 'up', 'value' => 0.42),
'visits_score_trends' => array('way' => 'down', 'value' => 0.42),
'convertion_rate_score_trends' => array('way' => 'up', 'value' => 0.42),
'net_profits_score_trends' => array('way' => 'up', 'value' => 0.42)
)
);
}
}