diff --git a/modules/loyalty/LoyaltyModule.php b/modules/loyalty/LoyaltyModule.php
index 6f43551cb..5d8ef5c9a 100644
--- a/modules/loyalty/LoyaltyModule.php
+++ b/modules/loyalty/LoyaltyModule.php
@@ -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)
diff --git a/modules/loyalty/controllers/front/default.php b/modules/loyalty/controllers/front/default.php
index 6f926fadb..9195706c4 100644
--- a/modules/loyalty/controllers/front/default.php
+++ b/modules/loyalty/controllers/front/default.php
@@ -112,10 +112,11 @@ class LoyaltyDefaultModuleFrontController extends ModuleFrontController
$cart_rule->add();
// Register order(s) which contributed to create this voucher
- LoyaltyModule::registerDiscount($cart_rule);
-
- Tools::redirect($this->context->link->getModuleLink('loyalty', 'default', array('process' => 'summary')));
+ if (!LoyaltyModule::registerDiscount($cart_rule))
+ $cart_rule->delete();
}
+
+ Tools::redirect($this->context->link->getModuleLink('loyalty', 'default', array('process' => 'summary')));
}
/**
diff --git a/modules/loyalty/loyalty-program.php b/modules/loyalty/loyalty-program.php
index 3843add03..08ff17756 100644
--- a/modules/loyalty/loyalty-program.php
+++ b/modules/loyalty/loyalty-program.php
@@ -42,7 +42,7 @@ if (!$context->customer->isLogged())
$context->controller->addJqueryPlugin(array('dimensions', 'cluetip'));
-$customerPoints = (int)(LoyaltyModule::getPointsByCustomer((int)($cookie->id_customer)));
+$customerPoints = (int)LoyaltyModule::getPointsByCustomer((int)$cookie->id_customer);
/* transform point into voucher if needed */
if (Tools::getValue('transform-points') == 'true' AND $customerPoints > 0)
@@ -99,7 +99,8 @@ if (Tools::getValue('transform-points') == 'true' AND $customerPoints > 0)
$cartRule->add();
/* Register order(s) which contributed to create this voucher */
- LoyaltyModule::registerDiscount($cartRule);
+ if (!LoyaltyModule::registerDiscount($cartRule))
+ $cartRule->delete();
Tools::redirect('modules/loyalty/loyalty-program.php');
}
diff --git a/modules/loyalty/loyalty.php b/modules/loyalty/loyalty.php
index 8d63cf678..fc562a5f9 100644
--- a/modules/loyalty/loyalty.php
+++ b/modules/loyalty/loyalty.php
@@ -36,6 +36,8 @@ if (!defined('_PS_VERSION_'))
class Loyalty extends Module
{
+ protected $html = '';
+
public function __construct()
{
$this->name = 'loyalty';
@@ -219,16 +221,15 @@ class Loyalty extends Module
$this->loyaltyStateNoneAward->name[$id_lang_default] = ' ';
$this->loyaltyStateNoneAward->save();
- echo $this->displayConfirmation($this->l('Settings updated.'));
+ $this->html .= $this->displayConfirmation($this->l('Settings updated.'));
}
else
{
$errors = '';
foreach ($this->_errors as $error)
$errors .= $error.'
';
- echo $this->displayError($errors);
+ $this->html .= $this->displayError($errors);
}
-// redirect($this->context->link);
}
}
@@ -252,7 +253,7 @@ class Loyalty extends Module
$languages = Language::getLanguages(false);
$languageIds = 'voucher_details¤default_loyalty_state¤none_award_loyalty_state¤convert_loyalty_state¤validation_loyalty_state¤cancel_loyalty_state';
- $html = '
+ $this->html .= '
@@ -274,12 +275,12 @@ class Loyalty extends Module
'.$this->l('Mark the box(es) of categories in which loyalty vouchers are usable.').'