// Fixed dashboard best sellers
This commit is contained in:
@@ -59,7 +59,6 @@ class Dashproducts extends Module
|
|||||||
$table_most_viewed = $this->getTableMostViewed($params['date_from'], $params['date_to']);
|
$table_most_viewed = $this->getTableMostViewed($params['date_from'], $params['date_to']);
|
||||||
$table_top_10_most_search = $this->getTableTop10MostSearch($params['date_from'], $params['date_to']);
|
$table_top_10_most_search = $this->getTableTop10MostSearch($params['date_from'], $params['date_to']);
|
||||||
$table_top_5_search = $this->getTableTop5Search();
|
$table_top_5_search = $this->getTableTop5Search();
|
||||||
$table_best_sales = $this->getTableBestSales();
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'data_table' => array(
|
'data_table' => array(
|
||||||
@@ -67,8 +66,7 @@ class Dashproducts extends Module
|
|||||||
'table_best_sellers' => $table_best_sellers,
|
'table_best_sellers' => $table_best_sellers,
|
||||||
'table_most_viewed' => $table_most_viewed,
|
'table_most_viewed' => $table_most_viewed,
|
||||||
'table_top_10_most_search' => $table_top_10_most_search,
|
'table_top_10_most_search' => $table_top_10_most_search,
|
||||||
'table_top_5_search' => $table_top_5_search,
|
'table_top_5_search' => $table_top_5_search
|
||||||
'table_best_sales' => $table_best_sales,
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -161,50 +159,63 @@ class Dashproducts extends Module
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$products = ProductSale::getBestSalesLight($this->context->language->id);
|
$products = Db::getInstance()->ExecuteS('
|
||||||
|
SELECT
|
||||||
|
product_id,
|
||||||
|
count(*) as total,
|
||||||
|
AVG(total_price_tax_excl / conversion_rate) as price,
|
||||||
|
SUM(total_price_tax_excl / conversion_rate) as sales,
|
||||||
|
SUM(product_quantity * purchase_supplier_price / conversion_rate) as expenses
|
||||||
|
FROM `'._DB_PREFIX_.'orders` o
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON o.id_order = od.id_order
|
||||||
|
WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
|
||||||
|
AND valid = 1
|
||||||
|
'.Shop::addSqlRestriction(false, 'o').'
|
||||||
|
GROUP BY product_id
|
||||||
|
ORDER BY total DESC
|
||||||
|
LIMIT 10');
|
||||||
|
|
||||||
$body = array();
|
$body = array();
|
||||||
if (is_array($products) && count($products))
|
foreach ($products as $product)
|
||||||
foreach ($products as $product)
|
{
|
||||||
{
|
$product_obj = new Product((int)$product['product_id'], false, $this->context->language->id);
|
||||||
$product_obj = new Product((int)$product['id_product']);
|
if (!Validate::isLoadedObject($product_obj))
|
||||||
if (!Validate::isLoadedObject($product_obj))
|
continue;
|
||||||
continue;
|
$category = new Category($product_obj->getDefaultCategory(), $this->context->language->id);
|
||||||
|
|
||||||
$tr = array();
|
$body[] = array(
|
||||||
$tr[] = array(
|
array(
|
||||||
'id' => 'product',
|
'id' => 'product',
|
||||||
'value' => '<img src="..'._PS_TMP_IMG_.'product_mini_'.$product['id_product'].'.jpg'.'" />',
|
'value' => '<img src="'._PS_TMP_IMG_.'product_mini_'.$product['product_id'].'.jpg'.'" />',
|
||||||
'class' => 'text-center',
|
'class' => 'text-center'
|
||||||
);
|
),
|
||||||
$tr[] = array(
|
array(
|
||||||
'id' => 'product',
|
'id' => 'product',
|
||||||
'value' => Tools::htmlentitiesUTF8($product['name']).'<br/>'.Tools::displayPrice(Product::getPriceStatic((int)$product['id_product'])),
|
'value' => Tools::htmlentitiesUTF8($product_obj->name).'<br/>'.Tools::displayPrice($product['price']),
|
||||||
'class' => 'text-center',
|
'class' => 'text-center'
|
||||||
);
|
),
|
||||||
$category = new Category($product_obj->getDefaultCategory(), $this->context->language->id);
|
array(
|
||||||
$tr[] = array(
|
|
||||||
'id' => 'category',
|
'id' => 'category',
|
||||||
'value' => $category->name,
|
'value' => $category->name,
|
||||||
'class' => 'text-center',
|
'class' => 'text-center'
|
||||||
);
|
),
|
||||||
$tr[] = array(
|
array(
|
||||||
'id' => 'total_sold',
|
'id' => 'total_sold',
|
||||||
'value' => $product['sales'],
|
'value' => $product['total'],
|
||||||
'class' => 'text-center',
|
'class' => 'text-center'
|
||||||
);
|
),
|
||||||
$tr[] = array(
|
array(
|
||||||
'id' => 'sales',
|
'id' => 'sales',
|
||||||
'value' => Tools::displayPrice($this->getTotalProductSales($date_from, $date_to, (int)$product['id_product'])),
|
'value' => Tools::displayPrice($product['sales']),
|
||||||
'class' => 'text-center',
|
'class' => 'text-center'
|
||||||
);
|
),
|
||||||
$tr[] = array(
|
array(
|
||||||
'id' => 'net_profit',
|
'id' => 'net_profit',
|
||||||
'value' => 'coming soon',
|
'value' => Tools::displayPrice($product['sales'] - $product['expenses']),
|
||||||
'class' => 'text-center',
|
'class' => 'text-center'
|
||||||
);
|
)
|
||||||
$body[] = $tr;
|
);
|
||||||
}
|
}
|
||||||
return array('header' => $header, 'body' => $body);
|
return array('header' => $header, 'body' => $body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,48 +363,6 @@ class Dashproducts extends Module
|
|||||||
return array('header' => $header, 'body' => $body);
|
return array('header' => $header, 'body' => $body);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTableBestSales()
|
|
||||||
{
|
|
||||||
$header = array(
|
|
||||||
array(
|
|
||||||
'id' => 'reference',
|
|
||||||
'title' => $this->l('Ref.'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'id' => 'name',
|
|
||||||
'title' => $this->l('Name'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'id' => 'totalQuantitySold',
|
|
||||||
'title' => $this->l('Quantity sold'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'id' => 'avg_price_sold',
|
|
||||||
'title' => $this->l('Price sold'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'id' => 'total_price_sold',
|
|
||||||
'title' => $this->l('Sales'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'id' => 'average_quantity_sold',
|
|
||||||
'title' => $this->l('Qty sold in a day.'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'id' => 'total_page_viewed',
|
|
||||||
'title' => $this->l('Page views'),
|
|
||||||
),
|
|
||||||
array(
|
|
||||||
'id' => 'quantity',
|
|
||||||
'title' => $this->l('Available qty for sale.'),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$body = array();
|
|
||||||
|
|
||||||
return array('header' => $header, 'body' => $body);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTotalProductSales($date_from, $date_to, $id_product)
|
public function getTotalProductSales($date_from, $date_to, $id_product)
|
||||||
{
|
{
|
||||||
$sql = 'SELECT SUM(od.`product_quantity` * od.`product_price`) AS total
|
$sql = 'SELECT SUM(od.`product_quantity` * od.`product_price`) AS total
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" id="dash_best_sellers">
|
<div class="tab-pane" id="dash_best_sellers">
|
||||||
<h3>{l s="Top 5 products"}</h3>
|
<h3>{l s="Top 10 products"}</h3>
|
||||||
<table class="table data_table" id="table_best_sellers">
|
<table class="table data_table" id="table_best_sellers">
|
||||||
<thead>
|
<thead>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -102,14 +102,5 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" id="dash_best_sales">
|
|
||||||
<h3>{l s="Coming soon"}</h3>
|
|
||||||
<table class="table data_table" id="table_best_sales">
|
|
||||||
<thead>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
Reference in New Issue
Block a user