diff --git a/modules/dashtrends/dashtrends.php b/modules/dashtrends/dashtrends.php index 124281d73..f7ad51266 100644 --- a/modules/dashtrends/dashtrends.php +++ b/modules/dashtrends/dashtrends.php @@ -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) + ) + ); } } \ No newline at end of file diff --git a/modules/gapi/gapi.php b/modules/gapi/gapi.php index 75dfceab6..50c07e5ec 100644 --- a/modules/gapi/gapi.php +++ b/modules/gapi/gapi.php @@ -44,8 +44,28 @@ class Gapi extends Module public function getContent() { + $html = ''; + + // Check configuration + $allow_url_fopen = ini_get('allow_url_fopen'); + $openssl = extension_loaded('openssl'); + $curl = extension_loaded('curl'); + $ping = (($allow_url_fopen || $curl) && $openssl && Tools::file_get_contents('https://www.google.com/')); + $online = (in_array(Tools::getRemoteAddr(), array('127.0.0.1', '::1')) ? false : true); + + if (!$ping || !$online) + { + $html .= $this->displayError('