// Added KPIs to the category page and fixed dashboard data
This commit is contained in:
@@ -22,9 +22,9 @@
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
<{if $href}a style="display:block" href="{$href|escape}"{else}div{/if} id="{$id|escape}" class="box-stats {$color|escape}" >
|
||||
{if $icon}<i class="{$icon|escape}"></i>{/if}
|
||||
{if $chart}
|
||||
<{if isset($href) && $href}a style="display:block" href="{$href|escape}"{else}div{/if} id="{$id|escape}" class="box-stats {$color|escape}" >
|
||||
{if isset($icon) && $icon}<i class="{$icon|escape}"></i>{/if}
|
||||
{if isset($chart) && $chart}
|
||||
<div class="boxchart-overlay">
|
||||
<div class="boxchart">
|
||||
</div>
|
||||
@@ -34,7 +34,7 @@
|
||||
<span class="value">{$value|escape}</span>
|
||||
</{if $href}a{else}div{/if}>
|
||||
|
||||
{if $source != ''}
|
||||
{if isset($source) && $source != ''}
|
||||
<script>
|
||||
$.ajax({
|
||||
url: '{$source|addslashes}' + '&rand=' + new Date().getTime(),
|
||||
|
||||
@@ -368,6 +368,29 @@ class AdminCategoriesControllerCore extends AdminController
|
||||
if (ConfigurationKPI::get('EMPTY_CATEGORIES_EXPIRE') < $time)
|
||||
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=empty_categories';
|
||||
$kpis[] = $helper->generate();
|
||||
|
||||
$helper = new HelperKpi();
|
||||
$helper->id = 'box-top-category';
|
||||
$helper->icon = 'icon-money';
|
||||
$helper->color = 'color3';
|
||||
$helper->title = $this->l('Top Category');
|
||||
$helper->subtitle = $this->l('30 days');
|
||||
if (ConfigurationKPI::get('TOP_CATEGORY', $this->context->employee->id_lang) !== false)
|
||||
$helper->value = ConfigurationKPI::get('TOP_CATEGORY', $this->context->employee->id_lang);
|
||||
if (ConfigurationKPI::get('TOP_CATEGORY_EXPIRE', $this->context->employee->id_lang) < $time)
|
||||
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=top_category';
|
||||
$kpis[] = $helper->generate();
|
||||
|
||||
$helper = new HelperKpi();
|
||||
$helper->id = 'box-products-per-category';
|
||||
$helper->icon = 'icon-search';
|
||||
$helper->color = 'color4';
|
||||
$helper->title = $this->l('Average number of products per category');
|
||||
if (ConfigurationKPI::get('PRODUCTS_PER_CATEGORY') !== false)
|
||||
$helper->value = ConfigurationKPI::get('PRODUCTS_PER_CATEGORY');
|
||||
if (ConfigurationKPI::get('PRODUCTS_PER_CATEGORY_EXPIRE') < $time)
|
||||
$helper->source = $this->context->link->getAdminLink('AdminStats').'&ajax=1&action=getKpi&kpi=products_per_category';
|
||||
$kpis[] = $helper->generate();
|
||||
|
||||
$helper = new HelperKpiRow();
|
||||
$helper->kpis = $kpis;
|
||||
|
||||
@@ -153,6 +153,14 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
WHERE c.active = 0');
|
||||
}
|
||||
|
||||
public static function getTotalCategories()
|
||||
{
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
'.Shop::addSqlAssociation('category', 'c'));
|
||||
}
|
||||
|
||||
public static function getDisabledProducts()
|
||||
{
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
@@ -162,6 +170,14 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
WHERE product_shop.active = 0');
|
||||
}
|
||||
|
||||
public static function getTotalProducts()
|
||||
{
|
||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p'));
|
||||
}
|
||||
|
||||
public static function getTotalSales($date_from, $date_to, $granularity = false)
|
||||
{
|
||||
if ($granularity == 'day')
|
||||
@@ -232,6 +248,7 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
if ($products_sales > $total_sales)
|
||||
break;
|
||||
}
|
||||
|
||||
return round(100 * $products / $total_products).'%';
|
||||
}
|
||||
|
||||
@@ -307,6 +324,31 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
return array('type' => 'neutral', 'value' => round(100 * $row['neutral'] / $row['total']));
|
||||
}
|
||||
|
||||
public static function getBestCategory($date_from, $date_to)
|
||||
{
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT ca.`id_category`
|
||||
FROM `'._DB_PREFIX_.'category` ca
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_product` capr ON ca.`id_category` = capr.`id_category`
|
||||
LEFT JOIN (
|
||||
SELECT pr.`id_product`, t.`totalPriceSold`
|
||||
FROM `'._DB_PREFIX_.'product` pr
|
||||
LEFT JOIN (
|
||||
SELECT pr.`id_product`,
|
||||
IFNULL(SUM(cp.`product_quantity`), 0) AS totalQuantitySold,
|
||||
IFNULL(SUM(cp.`product_price` * cp.`product_quantity`), 0) / o.conversion_rate AS totalPriceSold
|
||||
FROM `'._DB_PREFIX_.'product` pr
|
||||
LEFT OUTER JOIN `'._DB_PREFIX_.'order_detail` cp ON pr.`id_product` = cp.`product_id`
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = cp.`id_order`
|
||||
WHERE o.invoice_date BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
|
||||
GROUP BY pr.`id_product`
|
||||
) t ON t.`id_product` = pr.`id_product`
|
||||
) t ON t.`id_product` = capr.`id_product`
|
||||
WHERE ca.`level_depth` > 1
|
||||
GROUP BY ca.`id_category`
|
||||
ORDER BY SUM(t.`totalPriceSold`) DESC');
|
||||
}
|
||||
|
||||
public static function getMainCountry($date_from, $date_to)
|
||||
{
|
||||
$total_orders = AdminStatsController::getOrders($date_from, $date_to);
|
||||
@@ -581,8 +623,8 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
break;
|
||||
|
||||
case '8020_sales_catalog':
|
||||
$value = AdminStatsController::get8020SalesCatalog(date('Y-m-d', strtotime('-31 day')), date('Y-m-d', strtotime('-1 day')));
|
||||
$value .= ' '.$this->l('of your Catalog');
|
||||
$value = AdminStatsController::get8020SalesCatalog(date('Y-m-d', strtotime('-1 month')), date('Y-m-d'));
|
||||
$value = sprintf($this->l('%d%% of your Catalog'), $value);
|
||||
ConfigurationKPI::updateValue('8020_SALES_CATALOG', $value);
|
||||
ConfigurationKPI::updateValue('8020_SALES_CATALOG_EXPIRE', strtotime('+12 hour'));
|
||||
break;
|
||||
@@ -742,6 +784,27 @@ class AdminStatsControllerCore extends AdminStatsTabController
|
||||
ConfigurationKPI::updateValue('NETPROFIT_VISITOR', $value);
|
||||
ConfigurationKPI::updateValue('NETPROFIT_VISITOR_EXPIRE', strtotime(date('Y-m-d 00:00:00', strtotime('+1 day'))));
|
||||
break;
|
||||
|
||||
case 'products_per_category':
|
||||
$products = AdminStatsController::getTotalProducts();
|
||||
$categories = AdminStatsController::getTotalCategories();
|
||||
$value = round($products / $categories);
|
||||
ConfigurationKPI::updateValue('PRODUCTS_PER_CATEGORY', $value);
|
||||
ConfigurationKPI::updateValue('PRODUCTS_PER_CATEGORY_EXPIRE', strtotime('+1 hour'));
|
||||
break;
|
||||
|
||||
case 'top_category':
|
||||
if (!($id_category = AdminStatsController::getBestCategory(date('Y-m-d', strtotime('-1 month')), date('Y-m-d'))))
|
||||
$value = $this->l('No category');
|
||||
else
|
||||
{
|
||||
$category = new Category($id_category, $this->context->language->id);
|
||||
$value = $category->name;
|
||||
}
|
||||
|
||||
ConfigurationKPI::updateValue('TOP_CATEGORY', array($this->context->language->id => $value));
|
||||
ConfigurationKPI::updateValue('TOP_CATEGORY_EXPIRE', array($this->context->language->id => strtotime('+1 day')));
|
||||
break;
|
||||
|
||||
default:
|
||||
$value = false;
|
||||
|
||||
@@ -123,14 +123,14 @@ class Dashactivity extends Module
|
||||
$sql = 'SELECT COUNT(DISTINCT c.id_connections)
|
||||
FROM `'._DB_PREFIX_.'connections` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
|
||||
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 900
|
||||
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), cp.`time_start`)) < 1800
|
||||
AND cp.`time_end` IS NULL
|
||||
'.Shop::addSqlRestriction(false, 'c').'
|
||||
'.($maintenance_ips ? 'AND c.ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
|
||||
else
|
||||
$sql = 'SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'connections`
|
||||
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), `date_add`)) < 900
|
||||
WHERE TIME_TO_SEC(TIMEDIFF(NOW(), `date_add`)) < 1800
|
||||
'.Shop::addSqlRestriction(false).'
|
||||
'.($maintenance_ips ? 'AND ip_address NOT IN ('.preg_replace('/[^,0-9]/', '', $maintenance_ips).')' : '');
|
||||
$online_visitor = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
||||
@@ -145,7 +145,7 @@ class Dashactivity extends Module
|
||||
$abandoned_cart = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'cart`
|
||||
WHERE `date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
|
||||
WHERE `date_upd` BETWEEN "'.pSQL(date('Y-m-d H:i:s', strtotime('-2 DAY'))).'" AND "'.pSQL(date('Y-m-d H:i:s', strtotime('-1 DAY'))).'"
|
||||
AND id_cart NOT IN (SELECT id_cart FROM `'._DB_PREFIX_.'orders`)
|
||||
'.Shop::addSqlRestriction(Shop::SHARE_ORDER));
|
||||
|
||||
@@ -157,18 +157,13 @@ class Dashactivity extends Module
|
||||
'.Shop::addSqlRestriction(Shop::SHARE_ORDER, 'o'));
|
||||
|
||||
$products_out_of_stock = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
SELECT SUM(IF(IFNULL(stock.quantity, 0) > 0, 0, 1))
|
||||
FROM `'._DB_PREFIX_.'product` p
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
'.Product::sqlStock('p').'
|
||||
WHERE IFNULL(stock.quantity, 0) <= 0');
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON p.id_product = pa.id_product
|
||||
'.Product::sqlStock('p', 'pa'));
|
||||
|
||||
$new_messages = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
FROM `'._DB_PREFIX_.'customer_thread` ct
|
||||
LEFT JOIN `'._DB_PREFIX_.'customer_message` cm ON ct.id_customer_thread = cm.id_customer_thread
|
||||
WHERE cm.`date_add` BETWEEN "'.pSQL($params['date_from']).'" AND "'.pSQL($params['date_to']).'"
|
||||
'.Shop::addSqlRestriction(false, 'ct'));
|
||||
$new_messages = AdminStatsController::getPendingMessages();
|
||||
|
||||
$active_shopping_cart = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||
SELECT COUNT(*)
|
||||
|
||||
Reference in New Issue
Block a user