* @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 statscheckup extends Module { private $html = ''; public function __construct() { $this->name = 'statscheckup'; $this->tab = 'administration'; $this->version = '2.0.3'; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->trans('Catalog evaluation', [], 'Modules.Statscheckup.Admin'); $this->description = $this->trans('Enrich your stats, give your catalog a quick evaluation to better analyze your activity.', [], 'Modules.Statscheckup.Admin'); $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_]; } public function install() { $confs = [ 'CHECKUP_DESCRIPTIONS_LT' => 100, 'CHECKUP_DESCRIPTIONS_GT' => 400, 'CHECKUP_IMAGES_LT' => 1, 'CHECKUP_IMAGES_GT' => 2, 'CHECKUP_SALES_LT' => 1, 'CHECKUP_SALES_GT' => 2, 'CHECKUP_STOCK_LT' => 1, 'CHECKUP_STOCK_GT' => 3, ]; foreach ($confs as $confname => $confdefault) { if (!Configuration::get($confname)) { Configuration::updateValue($confname, (int) $confdefault); } } return parent::install() && $this->registerHook('displayAdminStatsModules'); } public function hookDisplayAdminStatsModules() { if (Tools::isSubmit('submitCheckup')) { $confs = [ 'CHECKUP_DESCRIPTIONS_LT', 'CHECKUP_DESCRIPTIONS_GT', 'CHECKUP_IMAGES_LT', 'CHECKUP_IMAGES_GT', 'CHECKUP_SALES_LT', 'CHECKUP_SALES_GT', 'CHECKUP_STOCK_LT', 'CHECKUP_STOCK_GT', ]; foreach ($confs as $confname) { Configuration::updateValue($confname, (int) Tools::getValue($confname)); } echo '
',
1 => '
',
2 => '
',
];
$token_products = Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Context::getContext()->employee->id);
$divisor = 4;
$totals = ['products' => 0, 'active' => 0, 'images' => 0, 'sales' => 0, 'stock' => 0];
foreach ($languages as $language) {
++$divisor;
$totals['description_' . $language['iso_code']] = 0;
}
$order_by = 'p.id_product';
if ($this->context->cookie->checkup_order == 2) {
$order_by = 'pl.name';
} elseif ($this->context->cookie->checkup_order == 3) {
$order_by = 'nbSales DESC';
}
// Get products stats
$sql = 'SELECT p.id_product, product_shop.active, pl.name, (
SELECT COUNT(*)
FROM ' . _DB_PREFIX_ . 'image i
' . Shop::addSqlAssociation('image', 'i') . '
WHERE i.id_product = p.id_product
) as nbImages, (
SELECT SUM(od.product_quantity)
FROM ' . _DB_PREFIX_ . 'orders o
LEFT JOIN ' . _DB_PREFIX_ . 'order_detail od ON o.id_order = od.id_order
WHERE od.product_id = p.id_product
AND o.invoice_date BETWEEN ' . ModuleGraph::getDateBetween() . '
' . Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o') . '
) as nbSales,
IFNULL(stock.quantity, 0) as stock
FROM ' . _DB_PREFIX_ . 'product p
' . Shop::addSqlAssociation('product', 'p') . '
' . Product::sqlStock('p', 0) . '
LEFT JOIN ' . _DB_PREFIX_ . 'product_lang pl
ON (p.id_product = pl.id_product AND pl.id_lang = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('pl') . ')
ORDER BY ' . $order_by;
$result = $db->executeS($sql);
if (!$result) {
return $this->trans('No product was found.', [], 'Modules.Statscheckup.Admin');
}
$array_conf = [
'DESCRIPTIONS' => ['name' => $this->trans('Descriptions', [], 'Modules.Statscheckup.Admin'), 'text' => $this->trans('chars (without HTML)', [], 'Modules.Statscheckup.Admin')],
'IMAGES' => ['name' => $this->trans('Images', [], 'Admin.Global'), 'text' => $this->trans('images', [], 'Admin.Global')],
'SALES' => ['name' => $this->trans('Sales', [], 'Admin.Global'), 'text' => $this->trans('orders / month', [], 'Modules.Statscheckup.Admin')],
'STOCK' => ['name' => $this->trans('Available quantity for sale', [], 'Admin.Global'), 'text' => $this->trans('items', [], 'Modules.Statscheckup.Admin')],
];
$this->html = '
| ' . $this->trans('ID', [], 'Admin.Global') . ' | ' . $this->trans('Item', [], 'Admin.Global') . ' | ' . $this->trans('Active', [], 'Admin.Global') . ' | '; foreach ($languages as $language) { $this->html .= '' . $this->trans('Desc.', [], 'Modules.Statscheckup.Admin') . ' (' . Tools::strtoupper($language['iso_code']) . ') | '; } $this->html .= '' . $this->trans('Images', [], 'Admin.Global') . ' | ' . $this->trans('Sales', [], 'Admin.Global') . ' | ' . $this->trans('Available quantity for sale', [], 'Admin.Global') . ' | ' . $this->trans('Global', [], 'Modules.Statscheckup.Admin') . ' | |
|---|---|---|---|---|---|---|---|---|
| ' . $row['id_product'] . ' | ' . Tools::substr($row['name'], 0, 42) . ' | ' . $array_colors[$scores['active']] . ' | '; foreach ($languages as $language) { if (isset($row['desclength_' . $language['iso_code']])) { $this->html .= '' . (int) $row['desclength_' . $language['iso_code']] . ' ' . $array_colors[$scores['description_' . $language['iso_code']]] . ' | '; } else { $this->html .= '0 ' . $array_colors[0] . ' | '; } } $this->html .= '' . (int) $row['nbImages'] . ' ' . $array_colors[$scores['images']] . ' | ' . (int) $row['nbSales'] . ' ' . $array_colors[$scores['sales']] . ' | ' . (int) $row['stock'] . ' ' . $array_colors[$scores['stock']] . ' | ' . $array_colors[$scores['average']] . ' |
| ' . $this->trans('Active', [], 'Admin.Global') . ' | '; foreach ($languages as $language) { $this->html .= '' . $this->trans('Desc.', [], 'Modules.Statscheckup.Admin') . ' (' . Tools::strtoupper($language['iso_code']) . ') | '; } $this->html .= '' . $this->trans('Images', [], 'Admin.Global') . ' | ' . $this->trans('Sales', [], 'Admin.Global') . ' | ' . $this->trans('Available quantity for sale', [], 'Admin.Global') . ' | ' . $this->trans('Global', [], 'Modules.Statscheckup.Admin') . ' | |||
| ' . $array_colors[$totals['active']] . ' | '; foreach ($languages as $language) { $this->html .= '' . $array_colors[$totals['description_' . $language['iso_code']]] . ' | '; } $this->html .= '' . $array_colors[$totals['images']] . ' | ' . $array_colors[$totals['sales']] . ' | ' . $array_colors[$totals['stock']] . ' | ' . $array_colors[$totals['average']] . ' | |||