* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 6594 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class StatsRegistrations extends ModuleGraph { private $_html = ''; private $_query = ''; function __construct() { $this->name = 'statsregistrations'; $this->tab = 'analytics_stats'; $this->version = 1.0; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('Customer accounts'); $this->description = $this->l('Display the progress of customer registration.'); } public function install() { return (parent::install() AND $this->registerHook('AdminStatsModules')); } public function getTotalRegistrations() { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(`id_customer`) as total FROM `'._DB_PREFIX_.'customer` WHERE `date_add` BETWEEN '.ModuleGraph::getDateBetween()); return isset($result['total']) ? $result['total'] : 0; } public function getBlockedVisitors() { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(DISTINCT c.`id_guest`) as blocked FROM `'._DB_PREFIX_.'page_type` pt LEFT JOIN `'._DB_PREFIX_.'page` p ON p.id_page_type = pt.id_page_type LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON p.id_page = cp.id_page LEFT JOIN `'._DB_PREFIX_.'connections` c ON c.id_connections = cp.id_connections LEFT JOIN `'._DB_PREFIX_.'guest` g ON c.id_guest = g.id_guest WHERE pt.name = "authentication.php" AND (g.id_customer IS NULL OR g.id_customer = 0) AND c.`date_add` BETWEEN '.ModuleGraph::getDateBetween()); return $result['blocked']; } public function getFirstBuyers() { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT COUNT(DISTINCT o.`id_customer`) as buyers FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'guest` g ON o.id_customer = g.id_customer LEFT JOIN `'._DB_PREFIX_.'connections` c ON c.id_guest = g.id_guest WHERE o.`date_add` BETWEEN '.ModuleGraph::getDateBetween().' AND o.valid = 1 AND ABS(TIMEDIFF(o.date_add, c.date_add)+0) < 120000'); return $result['buyers']; } public function hookAdminStatsModules($params) { $totalRegistrations = $this->getTotalRegistrations(); $totalBlocked = $this->getBlockedVisitors(); $totalBuyers = $this->getFirstBuyers(); if (Tools::getValue('export')) $this->csvExport(array('layers' => 0, 'type' => 'line')); $this->_html = '
'.$this->displayName.'

'.$this->l('Visitors who have stopped at the registering step:').' '.(int)($totalBlocked).($totalRegistrations ? ' ('.number_format(100*$totalBlocked/($totalRegistrations+$totalBlocked), 2).'%)' : '').'
'.$this->l('Visitors who have placed an order directly after registration:').' '.(int)($totalBuyers).($totalRegistrations ? ' ('.number_format(100*$totalBuyers/($totalRegistrations), 2).'%)' : '').'

'.$this->l('Total customer accounts:').' '.$totalRegistrations.'

'.ModuleGraph::engine(array('type' => 'line')).'

'.$this->l('CSV Export').'


'.$this->l('Guide').'

'.$this->l('Number of customer accounts created').'

'.$this->l('The total number of accounts created is not in itself important information. However, it is beneficial to analyze the number created over time. This will indicate whether or not things are on the right track.').'


'.$this->l('How to act on the registrations\' evolution?').'

'.$this->l('If you let your shop run without changing anything, the number of customer registrations should stay stable or may slightly decline.').' '.$this->l('A significant increase or decrease shows that there has probably been a change to your shop.Therefore, you have to identify it in order to backtrack if this change makes the number of registrations decrease, or continue with it if it increases registration.').'
'.$this->l('Here is summary of what may affect the creation of customer accounts:').'


'; return $this->_html; } protected function getData($layers) { $this->_query = ' SELECT `date_add` FROM `'._DB_PREFIX_.'customer` WHERE `date_add` BETWEEN'; $this->_titles['main'] = $this->l('Number of customer accounts created'); $this->setDateGraph($layers, true); } protected function setAllTimeValues($layers) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query.$this->getDate()); foreach ($result AS $row) $this->_values[(int)(substr($row['date_add'], 0, 4))]++; } protected function setYearValues($layers) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query.$this->getDate()); foreach ($result AS $row) { $mounth = (int)substr($row['date_add'], 5, 2); if (!isset($this->_values[$mounth])) $this->_values[$mounth] = 0; $this->_values[$mounth]++; } } protected function setMonthValues($layers) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query.$this->getDate()); foreach ($result AS $row) $this->_values[(int)(substr($row['date_add'], 8, 2))]++; } protected function setDayValues($layers) { $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($this->_query.$this->getDate()); foreach ($result AS $row) $this->_values[(int)(substr($row['date_add'], 11, 2))]++; } }