Merge branch 'ticket-9599' into develop
This commit is contained in:
commit
78bc31c542
@ -1831,6 +1831,63 @@ class Sale {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the percentage or amount in a promotion string
|
||||
* for each sale with the maximum reduction percentage or amount
|
||||
* of its products.
|
||||
*
|
||||
* @param string $date_day the sales starting day (to express in "Y-m-d")
|
||||
*/
|
||||
public static function updateSalesReductionAtDate()
|
||||
{
|
||||
$id_field = 2; // id=2 for the extra field sale "pourcentage"
|
||||
|
||||
// for all sales at "date_day" and hour > "from_hour"
|
||||
// return the maximal reduction applied from all products of each sale
|
||||
$sql = "SELECT MAX(sp.reduction) as reduc,
|
||||
s.id_sale, sf.value, sf.id_field, sf.id_lang
|
||||
FROM `"._DB_PREFIX_."specific_price` sp
|
||||
JOIN `"._DB_PREFIX_."category_product` cp
|
||||
ON cp.id_product = sp.id_product
|
||||
JOIN `"._DB_PREFIX_."privatesale_category` psc
|
||||
ON psc.id_category = cp.id_category
|
||||
JOIN `"._DB_PREFIX_."privatesale` s
|
||||
ON s.id_sale = psc.id_sale
|
||||
JOIN `"._DB_PREFIX_."privatesale_extrafield_sale` sf
|
||||
ON sf.id_sale = s.id_sale
|
||||
WHERE
|
||||
sp.reduction_type='percentage'
|
||||
AND CAST(s.date_start AS DATE) = CAST(NOW() AS DATE)
|
||||
AND sf.id_field = ".$id_field."
|
||||
AND sf.`value` IS NOT NULL
|
||||
AND sf.`value` <> ''
|
||||
GROUP BY s.id_sale, sf.value, sf.id_field, sf.id_lang
|
||||
";
|
||||
|
||||
$results = Db::getInstance()->ExecuteS($sql);
|
||||
|
||||
|
||||
// update the sentence with the max reduction, if any, for
|
||||
// each sale
|
||||
foreach ($results as $result) {
|
||||
|
||||
$reduction_in_percent = round($result['reduc']*100);
|
||||
$new_value = preg_replace(
|
||||
'/\d+\s*%/',
|
||||
$reduction_in_percent."%",
|
||||
$result['value']
|
||||
);
|
||||
|
||||
$sql = "UPDATE `"._DB_PREFIX_."privatesale_extrafield_sale`
|
||||
SET value=\"".$new_value."\"
|
||||
WHERE id_field = ".$id_field."
|
||||
AND id_lang = '".$result['id_lang']."'
|
||||
AND id_sale = '".$result['id_sale']."'
|
||||
";
|
||||
Db::getInstance()->Execute($sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -5,7 +5,6 @@ $_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
|
||||
include(dirname(__FILE__).'/../../config/config.inc.php');
|
||||
include(dirname(__FILE__).'/Sale.php');
|
||||
|
||||
$sales = Sale::getSales(TRUE, NULL, NULL, FALSE);
|
||||
|
||||
$file = fopen('lastupdate.txt', 'w');
|
||||
@ -15,3 +14,5 @@ fclose($file);
|
||||
foreach($sales as $sale) {
|
||||
$sale->end(TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
12
modules/privatesales/cron_salesreduction.php
Normal file
12
modules/privatesales/cron_salesreduction.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
if(isset($_SERVER['REMOTE_ADDR'])) exit;
|
||||
$_SERVER['SERVER_PORT'] = 80;
|
||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||
|
||||
include(dirname(__FILE__).'/../../config/config.inc.php');
|
||||
include(dirname(__FILE__).'/Sale.php');
|
||||
|
||||
Sale::updateSalesReductionAtDate();
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user