bebeboutik-scripts/cron_loyalty.php
2017-12-18 17:14:31 +01:00

37 lines
1.5 KiB
PHP

<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
include dirname(__FILE__).'/www/config/config.inc.php';
include dirname(__FILE__).'/www/modules/loyalty/LoyaltyStateModule.php';
include dirname(__FILE__).'/www//modules/loyalty/LoyaltyModule.php';
$loyaltyStateValidation = new LoyaltyStateModule(LoyaltyStateModule::getValidationId());
foreach (Db::getInstance()->ExecuteS('
SELECT lo.`id_order`, oh.`id_order_state`
FROM `'._DB_PREFIX_.'loyalty` lo
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lo.`id_order`)
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lo.`id_order` GROUP BY moh.`id_order`)
AND oh.`id_order_state` = 4 AND lo.`id_loyalty_state` NOT IN (2,4)
') as $order) {
if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId((int)$order['id_order'])))) {
continue;
}
if ((int)Configuration::get('PS_LOYALTY_NONE_AWARD') AND $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) {
continue;
}
if ((int)$order['id_order_state'] == $loyaltyStateValidation->id_order_state)
{
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
if ((float)($loyalty->discount_value) == 0) {
$loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($order);
}
}
$loyalty->save();
}