Merge branch 'ticket/r16348-credit-expired'

This commit is contained in:
Michael RICOIS 2018-03-08 14:59:05 +01:00
commit fc107f5d6d
2 changed files with 23 additions and 13 deletions

View File

@ -210,9 +210,12 @@ class LoyaltyModule extends ObjectModel
SELECT f.`id_loyalty`,f.`id_loyalty_state`,f.`discount_value`
FROM `'._DB_PREFIX_.'loyalty` f
WHERE f.`id_customer` = '.(int)($id_customer);
if ($notCancel === true)
if ($notCancel === true) {
$query .= ' AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId();
}
$query .= ' AND f.date_add > (NOW() - INTERVAL 1 YEAR)';
return Db::getInstance()->ExecuteS($query);
}
@ -238,11 +241,15 @@ class LoyaltyModule extends ObjectModel
AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `ps_order_history` moh WHERE moh.`id_order` = f.`id_order` GROUP BY moh.`id_order`)
AND oh.`id_order_state` != 8
'.(($onlyValidate)? '' : ' AND f.id_loyalty_state != '.(int)LoyaltyStateModule::getCancelId());
if ($onlyValidate) {
$query .= ' AND (f.id_loyalty_state = '.(int)LoyaltyStateModule::getCancelId().' OR f.id_loyalty_state = '.(int)LoyaltyStateModule::getValidationId().')';
} elseif ($onlyDefault){
$query .= ' AND f.id_loyalty_state = '.(int)LoyaltyStateModule::getDefaultId();
}
$query .= ' AND f.date_add > (NOW() - INTERVAL 1 YEAR)';
$query .= ' GROUP BY f.id_loyalty '.
($pagination ? 'LIMIT '.(((int)($page) - 1) * (int)($nb)).', '.(int)($nb) : '');
@ -268,10 +275,11 @@ class LoyaltyModule extends ObjectModel
public static function registerDiscountCustom($discount, $orders)
{
if (!Validate::isLoadedObject($discount))
if (!Validate::isLoadedObject($discount)) {
die(Tools::displayError('Incorrect object Discount.'));
foreach ($orders AS $item)
{
}
foreach ($orders AS $item) {
$f = new LoyaltyModule((int)$item['id_loyalty']);
if ($f->discount_value == 0) {

View File

@ -54,7 +54,7 @@ if ($displayorders && !empty($displayorders)) {
if (!empty($allOrders)) {
$nb_orders = count($allOrders);
foreach ($allOrders as $key => $order) {
if ((int)$order['id_loyalty_state'] !=2){
if ((int)$order['id_loyalty_state'] != 2){
continue;
}
$total_discount += (float)$order['discount_value'];
@ -92,17 +92,18 @@ if (Tools::getValue('transform-points') == 'true' AND $total_discount > 0)
/* If merchandise returns are allowed, the voucher musn't be usable before this max return date */
$dateFrom = Db::getInstance()->getValue('
SELECT UNIX_TIMESTAMP(date_add) n
FROM '._DB_PREFIX_.'loyalty
WHERE id_discount = 0 AND id_customer = '.(int)$cookie->id_customer.'
ORDER BY date_add DESC');
SELECT UNIX_TIMESTAMP(date_add) n
FROM '._DB_PREFIX_.'loyalty
WHERE id_discount = 0 AND id_customer = '.(int)$cookie->id_customer.'
ORDER BY date_add DESC
');
if (Configuration::get('PS_ORDER_RETURN'))
if (Configuration::get('PS_ORDER_RETURN')) {
$dateFrom += 60 * 60 * 24 * (int)Configuration::get('PS_ORDER_RETURN_NB_DAYS');
}
$voucher->date_from = date('Y-m-d H:i:s', $dateFrom);
$voucher->date_to = date('Y-m-d H:i:s', $dateFrom + 31536000); // + 1 year
$voucher->date_to = date('Y-m-d H:i:s', $dateFrom + (60 * 60 * 24 * 365)); // + 1 year
$voucher->minimal = (float)Configuration::get('PS_LOYALTY_MINIMAL');
$voucher->active = 1;
@ -130,7 +131,8 @@ if (Tools::getValue('transform-points') == 'true' AND $total_discount > 0)
$voucher->add();
/* Register order(s) which contributed to create this voucher */
$orderToConvert = LoyaltyModule::getAllByIdCustomerCustom((int)($cookie->id_customer), (int)($cookie->id_lang), true, false, $nb = 10, $page = 1);
$orderToConvert = LoyaltyModule::getAllByIdCustomerCustom(
(int)($cookie->id_customer), (int)($cookie->id_lang), true, false, $nb = 10, $page = 1);
LoyaltyModule::registerDiscountCustom($voucher, $orderToConvert);
Tools::redirect('modules/loyalty/loyalty-program.php');