[-] MO : Fixed double creation of vouchers in loyalty and some redirections #PNM-1317

This commit is contained in:
Damien Metzger
2013-06-07 15:52:56 +02:00
parent 1688c7b0e6
commit 26608cea48
4 changed files with 49 additions and 43 deletions
+8 -5
View File
@@ -197,20 +197,23 @@ class LoyaltyModule extends ObjectModel
if (!Validate::isLoadedObject($cartRule))
die(Tools::displayError('Incorrect object CartRule.'));
$items = self::getAllByIdCustomer((int)$cartRule->id_customer, NULL, true);
$associated = false;
foreach ($items AS $item)
{
$f = new LoyaltyModule((int)$item['id_loyalty']);
$lm = new LoyaltyModule((int)$item['id_loyalty']);
/* Check for negative points for this order */
$negativePoints = (int)Db::getInstance()->getValue('SELECT SUM(points) points FROM '._DB_PREFIX_.'loyalty WHERE id_order = '.(int)$f->id_order.' AND id_loyalty_state = '.(int)LoyaltyStateModule::getCancelId().' AND points < 0');
if ($f->points + $negativePoints <= 0)
if ($lm->points + $negativePoints <= 0)
continue;
$f->id_cart_rule = (int)$cartRule->id;
$f->id_loyalty_state = (int)LoyaltyStateModule::getConvertId();
$f->save();
$lm->id_cart_rule = (int)$cartRule->id;
$lm->id_loyalty_state = (int)LoyaltyStateModule::getConvertId();
$lm->save();
$associated = true;
}
return $associated;
}
public static function getOrdersByIdDiscount($id_cart_rule)