comment of insert in ps_product_ps_cache in livestats cron
This commit is contained in:
parent
a13a8813ea
commit
5c5ea81e90
@ -10,14 +10,14 @@ $_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
|
|||||||
include dirname(__FILE__).'/../../config/config.inc.php';
|
include dirname(__FILE__).'/../../config/config.inc.php';
|
||||||
include dirname(__FILE__).'/../../modules/privatesales/Sale.php';
|
include dirname(__FILE__).'/../../modules/privatesales/Sale.php';
|
||||||
|
|
||||||
Db::getInstance()->ExecuteS('
|
// Db::getInstance()->ExecuteS('
|
||||||
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
|
// INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
|
||||||
SELECT `id_product`, `id_sale`
|
// SELECT `id_product`, `id_sale`
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
// FROM `'._DB_PREFIX_.'product` p
|
||||||
LEFT JOIN `'._DB_PREFIX_.'privatesale_category` c
|
// LEFT JOIN `'._DB_PREFIX_.'privatesale_category` c
|
||||||
ON p.`id_category_default` = c.`id_category`
|
// ON p.`id_category_default` = c.`id_category`
|
||||||
)
|
// )
|
||||||
');
|
// ');
|
||||||
|
|
||||||
// echo date('Y-m-d', strtotime(date('Y-m-d 00:00:00').' - '.(int) $argv[1].' day'))."\n";
|
// echo date('Y-m-d', strtotime(date('Y-m-d 00:00:00').' - '.(int) $argv[1].' day'))."\n";
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ foreach ($langs as $iso => $id_lang) {
|
|||||||
|
|
||||||
foreach($sales as $sale) {
|
foreach($sales as $sale) {
|
||||||
$period[(int) $sale['id_sale']] = array(0, 0);
|
$period[(int) $sale['id_sale']] = array(0, 0);
|
||||||
|
|
||||||
$ids_product = array();
|
$ids_product = array();
|
||||||
foreach (Db::getInstance()->ExecuteS('
|
foreach (Db::getInstance()->ExecuteS('
|
||||||
SELECT `id_product`
|
SELECT `id_product`
|
||||||
@ -67,7 +67,7 @@ foreach ($langs as $iso => $id_lang) {
|
|||||||
$ids_product[] = $value['id_product'];
|
$ids_product[] = $value['id_product'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = Db::getInstance()->getRow('
|
$total = Db::getInstance()->getRow('
|
||||||
SELECT SUM(d.`product_quantity`) AS `total_products`, SUM(ROUND(((d.`product_price` * (1 - d.`reduction_percent` / 100) - d.`reduction_amount`) * (1 - d.`group_reduction` / 100) * (1 + d.`tax_rate` / 100)) * d.`product_quantity`, 6)) AS `total_sales_wt`
|
SELECT SUM(d.`product_quantity`) AS `total_products`, SUM(ROUND(((d.`product_price` * (1 - d.`reduction_percent` / 100) - d.`reduction_amount`) * (1 - d.`group_reduction` / 100) * (1 + d.`tax_rate` / 100)) * d.`product_quantity`, 6)) AS `total_sales_wt`
|
||||||
FROM `'._DB_PREFIX_.'order_detail` d
|
FROM `'._DB_PREFIX_.'order_detail` d
|
||||||
LEFT JOIN `'._DB_PREFIX_.'orders` o
|
LEFT JOIN `'._DB_PREFIX_.'orders` o
|
||||||
@ -81,7 +81,7 @@ foreach ($langs as $iso => $id_lang) {
|
|||||||
|
|
||||||
$ids_total[(int) $id_lang][(int) $sale['id_sale']] = array();
|
$ids_total[(int) $id_lang][(int) $sale['id_sale']] = array();
|
||||||
$ids_actual[(int) $sale['id_sale']] = array();
|
$ids_actual[(int) $sale['id_sale']] = array();
|
||||||
|
|
||||||
$ids = Db::getInstance()->ExecuteS('
|
$ids = Db::getInstance()->ExecuteS('
|
||||||
SELECT DISTINCT d.`id_order`, CAST(o.`date_add` as DATE) as `date_add`
|
SELECT DISTINCT d.`id_order`, CAST(o.`date_add` as DATE) as `date_add`
|
||||||
FROM `'._DB_PREFIX_.'order_detail` d
|
FROM `'._DB_PREFIX_.'order_detail` d
|
||||||
@ -94,11 +94,11 @@ foreach ($langs as $iso => $id_lang) {
|
|||||||
|
|
||||||
foreach ($ids as $key => $id) {
|
foreach ($ids as $key => $id) {
|
||||||
$ids_total[(int) $id_lang][(int) $sale['id_sale']][] = $id['id_order'];
|
$ids_total[(int) $id_lang][(int) $sale['id_sale']][] = $id['id_order'];
|
||||||
if ($id['date_add'] == $day_from) {
|
if ($id['date_add'] == $day_from) {
|
||||||
$ids_actual[(int) $sale['id_sale']][] = $id['id_order'];
|
$ids_actual[(int) $sale['id_sale']][] = $id['id_order'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// multi orders by sale
|
// multi orders by sale
|
||||||
$sale_obj = new Sale((int) $sale['id_sale']);
|
$sale_obj = new Sale((int) $sale['id_sale']);
|
||||||
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
|
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
|
||||||
@ -139,13 +139,13 @@ foreach ($langs as $iso => $id_lang) {
|
|||||||
NOW()
|
NOW()
|
||||||
)
|
)
|
||||||
');
|
');
|
||||||
|
|
||||||
// stats for each lang (total_sales_wt, total_products)
|
// stats for each lang (total_sales_wt, total_products)
|
||||||
$total = Db::getInstance()->getRow('
|
$total = Db::getInstance()->getRow('
|
||||||
SELECT SUM(d.`product_quantity`) AS `total_products`, SUM(ROUND(((d.`product_price` * (1 - d.`reduction_percent` / 100) - d.`reduction_amount`) * (1 - d.`group_reduction` / 100) * (1 + d.`tax_rate` / 100)) * d.`product_quantity`, 6)) AS `total_sales_wt`, SUM(d.`product_quantity`) AS `total_products`, SUM(ROUND(((d.`product_price` * (1 - d.`reduction_percent` / 100) - d.`reduction_amount`) * (1 - d.`group_reduction` / 100)), 6)) AS `total_unit_sales`
|
SELECT SUM(d.`product_quantity`) AS `total_products`, SUM(ROUND(((d.`product_price` * (1 - d.`reduction_percent` / 100) - d.`reduction_amount`) * (1 - d.`group_reduction` / 100) * (1 + d.`tax_rate` / 100)) * d.`product_quantity`, 6)) AS `total_sales_wt`, SUM(d.`product_quantity`) AS `total_products`, SUM(ROUND(((d.`product_price` * (1 - d.`reduction_percent` / 100) - d.`reduction_amount`) * (1 - d.`group_reduction` / 100)), 6)) AS `total_unit_sales`
|
||||||
FROM `'._DB_PREFIX_.'order_detail` d
|
FROM `'._DB_PREFIX_.'order_detail` d
|
||||||
INNER JOIN `'._DB_PREFIX_.'orders` o ON o.id_order = d.id_order
|
INNER JOIN `'._DB_PREFIX_.'orders` o ON o.id_order = d.id_order
|
||||||
WHERE d.`product_id` IN ('.implode(',', $ids_product).')
|
WHERE d.`product_id` IN ('.implode(',', $ids_product).')
|
||||||
AND o.valid = 1
|
AND o.valid = 1
|
||||||
AND o.`id_lang` = '.(int) $id_lang.'
|
AND o.`id_lang` = '.(int) $id_lang.'
|
||||||
');
|
');
|
||||||
@ -174,13 +174,13 @@ foreach ($langs as $iso => $id_lang) {
|
|||||||
/**
|
/**
|
||||||
* PART 2
|
* PART 2
|
||||||
* global @data
|
* global @data
|
||||||
*/
|
*/
|
||||||
$sales = array();
|
$sales = array();
|
||||||
foreach(Db::getInstance()->ExecuteS('
|
foreach(Db::getInstance()->ExecuteS('
|
||||||
SELECT p.*, l.`name`
|
SELECT p.*, l.`name`
|
||||||
FROM `'._DB_PREFIX_.'privatesale` p
|
FROM `'._DB_PREFIX_.'privatesale` p
|
||||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` l
|
LEFT JOIN `'._DB_PREFIX_.'category_lang` l
|
||||||
ON p.`id_category` = l.`id_category`
|
ON p.`id_category` = l.`id_category`
|
||||||
WHERE ((CAST(p.`date_start` AS DATE) >= "'.pSQL($day_from).'" AND CAST(p.`date_start` AS DATE) <= "'.pSQL($day_to).'")
|
WHERE ((CAST(p.`date_start` AS DATE) >= "'.pSQL($day_from).'" AND CAST(p.`date_start` AS DATE) <= "'.pSQL($day_to).'")
|
||||||
OR (CAST(p.`date_end` AS DATE) >= "'.pSQL($day_from).'" AND CAST(p.`date_end` AS DATE) <= "'.pSQL($day_to).'")
|
OR (CAST(p.`date_end` AS DATE) >= "'.pSQL($day_from).'" AND CAST(p.`date_end` AS DATE) <= "'.pSQL($day_to).'")
|
||||||
OR (CAST(p.`date_start` AS DATE) <= "'.pSQL($day_from).'" AND CAST(p.`date_end` AS DATE) >= "'.pSQL($day_to).'"))
|
OR (CAST(p.`date_start` AS DATE) <= "'.pSQL($day_from).'" AND CAST(p.`date_end` AS DATE) >= "'.pSQL($day_to).'"))
|
||||||
@ -234,7 +234,7 @@ foreach($sales as $sale) {
|
|||||||
FROM `'._DB_PREFIX_.'product_attribute` a
|
FROM `'._DB_PREFIX_.'product_attribute` a
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||||
ON p.`id_product` = a.`id_product`
|
ON p.`id_product` = a.`id_product`
|
||||||
WHERE a.`id_product` IN ('.implode(',', $ids_product).')
|
WHERE a.`id_product` IN ('.implode(',', $ids_product).')
|
||||||
GROUP BY a.`id_product_attribute`
|
GROUP BY a.`id_product_attribute`
|
||||||
');
|
');
|
||||||
|
|
||||||
@ -385,7 +385,7 @@ foreach($sales as $sale) {
|
|||||||
$multi_total_sale += count($multi_total[(int) $id_lang][(int) $sale['id_sale']]);
|
$multi_total_sale += count($multi_total[(int) $id_lang][(int) $sale['id_sale']]);
|
||||||
$total_sale += count($ids_total[(int) $id_lang][(int) $sale['id_sale']]);
|
$total_sale += count($ids_total[(int) $id_lang][(int) $sale['id_sale']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Db::getInstance()->ExecuteS('
|
Db::getInstance()->ExecuteS('
|
||||||
INSERT INTO `'._DB_PREFIX_.'privatesale_livestats_sale`
|
INSERT INTO `'._DB_PREFIX_.'privatesale_livestats_sale`
|
||||||
VALUES (
|
VALUES (
|
||||||
|
Loading…
Reference in New Issue
Block a user