/home/sharedstore/public_html/prestashop.sharedstore.ma/modules/statscarrier
Edit: /home/sharedstore/public_html/prestashop.sharedstore.ma/modules/statscarrier/statscarrier.php (5909B)
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
*/
if (!defined('_PS_VERSION_')) {
exit;
}
class statscarrier extends ModuleGraph
{
private $html = '';
private $option = '';
public function __construct()
{
$this->name = 'statscarrier';
$this->tab = 'analytics_stats';
$this->version = '2.0.1';
$this->author = 'PrestaShop';
$this->need_instance = 0;
parent::__construct();
$this->displayName = $this->trans('Carrier distribution', array(), 'Modules.Statscarrier.Admin');
$this->description = $this->trans('Enrich your stats, add a pie chart illustrating your carriers’ distribution.', array(), 'Modules.Statscarrier.Admin');
$this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_);
}
public function install()
{
return (parent::install() && $this->registerHook('displayAdminStatsModules'));
}
public function hookDisplayAdminStatsModules($params)
{
$sql = 'SELECT COUNT(o.`id_order`) as total
FROM `'._DB_PREFIX_.'orders` o
WHERE o.`date_add` BETWEEN '.ModuleGraph::getDateBetween().'
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
'.((int)Tools::getValue('id_order_state') ? 'AND (SELECT oh.id_order_state FROM `'._DB_PREFIX_.'order_history` oh WHERE o.id_order = oh.id_order ORDER BY oh.date_add DESC, oh.id_order_history DESC LIMIT 1) = '.(int)Tools::getValue('id_order_state') : '');
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
$states = OrderState::getOrderStates($this->context->language->id);
if (Tools::getValue('export')) {
$this->csvExport(array('type' => 'pie', 'option' => Tools::getValue('id_order_state')));
}
$this->html = '
'.$this->displayName.'
'.$this->trans('This graph represents the carrier distribution for your orders. You can also narrow the focus of the graph to display distribution for a particular order status.', array(), 'Modules.Statscarrier.Admin').'
'.($result['total'] ? $this->engine(array(
'type' => 'pie',
'option' => Tools::getValue('id_order_state')
)).'
';
return $this->html;
}
public function setOption($option, $layers = 1)
{
$this->option = (int)$option;
}
protected function getData($layers)
{
$state_query = '';
if ((int)$this->option) {
$state_query = 'AND (
SELECT oh.id_order_state FROM `'._DB_PREFIX_.'order_history` oh
WHERE o.id_order = oh.id_order
ORDER BY oh.date_add DESC, oh.id_order_history DESC
LIMIT 1) = '.(int)$this->option;
}
$this->_titles['main'] = $this->trans('Percentage of orders listed by carrier.', array(), 'Modules.Statscarrier.Admin');
$sql = 'SELECT c.name, COUNT(DISTINCT o.`id_order`) as total
FROM `'._DB_PREFIX_.'carrier` c
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.id_carrier = c.id_carrier
WHERE o.`date_add` BETWEEN '.ModuleGraph::getDateBetween().'
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o').'
'.$state_query.'
GROUP BY c.`id_carrier`';
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
foreach ($result as $row) {
$this->_values[] = $row['total'];
$this->_legend[] = $row['name'];
}
}
}