first commit
This commit is contained in:
12
modules/statssearch/config.xml
Normal file
12
modules/statssearch/config.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>statssearch</name>
|
||||
<displayName><![CDATA[Shop search]]></displayName>
|
||||
<version><![CDATA[2.0.2]]></version>
|
||||
<description><![CDATA[Adds a tab showing which keywords have been searched by your store's visitors.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[analytics_stats]]></tab>
|
||||
<is_configurable>0</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
12
modules/statssearch/config_pl.xml
Normal file
12
modules/statssearch/config_pl.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<module>
|
||||
<name>statssearch</name>
|
||||
<displayName><![CDATA[Wyszukiwarka sklepu]]></displayName>
|
||||
<version><![CDATA[2.0.2]]></version>
|
||||
<description><![CDATA[Enrich your stats, add a tab showing what keywords have been searched by your visitors.]]></description>
|
||||
<author><![CDATA[PrestaShop]]></author>
|
||||
<tab><![CDATA[analytics_stats]]></tab>
|
||||
<is_configurable>0</is_configurable>
|
||||
<need_instance>0</need_instance>
|
||||
<limited_countries></limited_countries>
|
||||
</module>
|
||||
35
modules/statssearch/index.php
Normal file
35
modules/statssearch/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop SA and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (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:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* 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 https://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
BIN
modules/statssearch/logo.gif
Normal file
BIN
modules/statssearch/logo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1013 B |
BIN
modules/statssearch/logo.png
Normal file
BIN
modules/statssearch/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
169
modules/statssearch/statssearch.php
Normal file
169
modules/statssearch/statssearch.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop SA and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (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:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* 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 https://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class statssearch extends ModuleGraph
|
||||
{
|
||||
private $html = '';
|
||||
private $query = '';
|
||||
private $query_group_by = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'statssearch';
|
||||
$this->tab = 'analytics_stats';
|
||||
$this->version = '2.0.2';
|
||||
$this->author = 'PrestaShop';
|
||||
$this->need_instance = 0;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->query = 'SELECT `keywords`, COUNT(TRIM(`keywords`)) as occurences, MAX(results) as total
|
||||
FROM `'._DB_PREFIX_.'statssearch`
|
||||
WHERE 1
|
||||
'.Shop::addSqlRestriction().'
|
||||
AND `date_add` BETWEEN ';
|
||||
|
||||
$this->query_group_by = 'GROUP BY `keywords`
|
||||
HAVING occurences > 1
|
||||
ORDER BY occurences DESC';
|
||||
|
||||
$this->displayName = $this->trans('Shop search', array(), 'Modules.Statssearch.Admin');
|
||||
$this->description = $this->trans('Enrich your stats, add a tab showing what keywords have been searched by your visitors.', array(), 'Modules.Statssearch.Admin');
|
||||
$this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_);
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
if (!parent::install() || !$this->registerHook('actionSearch') || !$this->registerHook('displayAdminStatsModules')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return Db::getInstance()->execute('
|
||||
CREATE TABLE `'._DB_PREFIX_.'statssearch` (
|
||||
id_statssearch INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
id_shop INTEGER UNSIGNED NOT NULL DEFAULT \'1\',
|
||||
id_shop_group INTEGER UNSIGNED NOT NULL DEFAULT \'1\',
|
||||
keywords VARCHAR(255) NOT NULL,
|
||||
results INT(6) NOT NULL DEFAULT 0,
|
||||
date_add DATETIME NOT NULL,
|
||||
PRIMARY KEY(id_statssearch)
|
||||
) ENGINE='._MYSQL_ENGINE_.' DEFAULT CHARSET=utf8');
|
||||
}
|
||||
|
||||
public function uninstall()
|
||||
{
|
||||
if (!parent::uninstall()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'statssearch`'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert keywords in statssearch table when a search is launched on FO
|
||||
*/
|
||||
public function hookActionSearch($params)
|
||||
{
|
||||
$sql = 'INSERT INTO `'._DB_PREFIX_.'statssearch` (`id_shop`, `id_shop_group`, `keywords`, `results`, `date_add`)
|
||||
VALUES ('.(int)$this->context->shop->id.', '.(int)$this->context->shop->id_shop_group.', \''.pSQL($params['expr']).'\', '.(int)$params['total'].', NOW())';
|
||||
Db::getInstance()->execute($sql);
|
||||
}
|
||||
|
||||
public function hookDisplayAdminStatsModules()
|
||||
{
|
||||
if (Tools::getValue('export')) {
|
||||
$this->csvExport(array('type' => 'pie'));
|
||||
}
|
||||
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query.ModuleGraph::getDateBetween().$this->query_group_by);
|
||||
$this->html = '
|
||||
<div class="panel-heading">
|
||||
'.$this->displayName.'
|
||||
</div>';
|
||||
$table = '
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><span class="title_box active">'.$this->trans('Keywords', array(), 'Modules.Statssearch.Admin').'</span></th>
|
||||
<th><span class="title_box active">'.$this->trans('Occurrences', array(), 'Modules.Statssearch.Admin').'</span></th>
|
||||
<th><span class="title_box active">'.$this->trans('Results', array(), 'Modules.Statssearch.Admin').'</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
foreach ($result as $row) {
|
||||
if (Tools::strlen($row['keywords']) >= Configuration::get('PS_SEARCH_MINWORDLEN')) {
|
||||
$table .= '<tr>
|
||||
<td>'.$row['keywords'].'</td>
|
||||
<td>'.$row['occurences'].'</td>
|
||||
<td>'.$row['total'].'</td>
|
||||
</tr>';
|
||||
}
|
||||
}
|
||||
$table .= '
|
||||
</tbody>
|
||||
</table>';
|
||||
|
||||
if (count($result)) {
|
||||
$this->html .= '<div>'.$this->engine(array('type' => 'pie')).'</div>
|
||||
<a class="btn btn-default" href="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'&export=1">
|
||||
<i class="icon-cloud-upload"></i> '.$this->trans('CSV Export', array(), 'Modules.Statssearch.Admin').'
|
||||
</a>'.$table;
|
||||
} else {
|
||||
$this->html .= '<p>'.$this->trans('Cannot find any keywords that have been searched for more than once.', array(), 'Modules.Statssearch.Admin').'</p>';
|
||||
}
|
||||
|
||||
return $this->html;
|
||||
}
|
||||
|
||||
protected function getData($layers)
|
||||
{
|
||||
$this->_titles['main'] = $this->trans('Top 10 keywords', array(), 'Modules.Statssearch.Admin');
|
||||
$total_result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query.$this->getDate().$this->query_group_by);
|
||||
$total = 0;
|
||||
$total2 = 0;
|
||||
foreach ($total_result as $total_row) {
|
||||
$total += $total_row['occurences'];
|
||||
}
|
||||
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query.$this->getDate().$this->query_group_by.' LIMIT 9');
|
||||
foreach ($result as $row) {
|
||||
if (!$row['occurences']) {
|
||||
continue;
|
||||
}
|
||||
$this->_legend[] = $row['keywords'];
|
||||
$this->_values[] = $row['occurences'];
|
||||
$total2 += $row['occurences'];
|
||||
}
|
||||
if ($total > $total2) {
|
||||
$this->_legend[] = $this->trans('Others', array(), 'Modules.Statssearch.Admin');
|
||||
$this->_values[] = $total - $total2;
|
||||
}
|
||||
}
|
||||
}
|
||||
35
modules/statssearch/translations/index.php
Normal file
35
modules/statssearch/translations/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* 2007-2020 PrestaShop SA and Contributors
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (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:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* 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 https://www.prestashop.com for more information.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright 2007-2020 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
|
||||
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
|
||||
|
||||
header("Cache-Control: no-store, no-cache, must-revalidate");
|
||||
header("Cache-Control: post-check=0, pre-check=0", false);
|
||||
header("Pragma: no-cache");
|
||||
|
||||
header("Location: ../");
|
||||
exit;
|
||||
0
modules/statssearch/translations/pl.php
Normal file
0
modules/statssearch/translations/pl.php
Normal file
35
modules/statssearch/upgrade/index.php
Normal file
35
modules/statssearch/upgrade/index.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* 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 https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
33
modules/statssearch/upgrade/upgrade-2.0.2.php
Normal file
33
modules/statssearch/upgrade/upgrade-2.0.2.php
Normal file
@@ -0,0 +1,33 @@
|
||||
|
||||
<?php
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/AFL-3.0
|
||||
* 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.
|
||||
*
|
||||
* @author PrestaShop SA <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param Module $module
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function upgrade_module_2_0_2($module)
|
||||
{
|
||||
$module->unregisterHook('AdminStatsModules');
|
||||
$module->registerHook('displayAdminStatsModules');
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user