[-] 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)
@@ -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')));
}
/**
+3 -2
View File
@@ -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');
}
+34 -33
View File
@@ -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.'<br />';
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 .= '
<script type="text/javascript">
id_language = Number('.$id_lang_default.');
</script>
@@ -274,12 +275,12 @@ class Loyalty extends Module
<label>'.$this->l('Voucher details').'</label>
<div class="margin-form">';
foreach ($languages as $language)
$html .= '
$this->html .= '
<div id="voucher_details_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="voucher_details_'.$language['id_lang'].'" value="'.Configuration::get('PS_LOYALTY_VOUCHER_DETAILS', (int)($language['id_lang'])).'" />
</div>';
$html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'voucher_details', true);
$html .= ' </div>
$this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'voucher_details', true);
$this->html .= ' </div>
<div class="clear" style="margin-top: 20px"></div>
<label>'.$this->l('Minimum amount in which the voucher can be used').'</label>
<div class="margin-form">
@@ -299,12 +300,12 @@ class Loyalty extends Module
<select id="id_order_state_validation" name="id_order_state_validation">';
foreach ($order_states as $order_state)
{
$html .= '<option value="'.$order_state['id_order_state'].'" style="background-color:'.$order_state['color'].';"';
$this->html .= '<option value="'.$order_state['id_order_state'].'" style="background-color:'.$order_state['color'].';"';
if ((int)$this->loyaltyStateValidation->id_order_state == $order_state['id_order_state'])
$html .= ' selected="selected"';
$html .= '>'.$order_state['name'].'</option>';
$this->html .= ' selected="selected"';
$this->html .= '>'.$order_state['name'].'</option>';
}
$html .= '</select>
$this->html .= '</select>
</div>
<div class="clear"></div>
<label>'.$this->l('Points are cancelled when the order is').'</label>
@@ -312,12 +313,12 @@ class Loyalty extends Module
<select id="id_order_state_cancel" name="id_order_state_cancel">';
foreach ($order_states as $order_state)
{
$html .= '<option value="'.$order_state['id_order_state'].'" style="background-color:'.$order_state['color'].';"';
$this->html .= '<option value="'.$order_state['id_order_state'].'" style="background-color:'.$order_state['color'].';"';
if ((int)$this->loyaltyStateCancel->id_order_state == $order_state['id_order_state'])
$html .= ' selected="selected"';
$html .= '>'.$order_state['name'].'</option>';
$this->html .= ' selected="selected"';
$this->html .= '>'.$order_state['name'].'</option>';
}
$html .= '</select>
$this->html .= '</select>
</div>
<div class="clear"></div>
<label>'.$this->l('Vouchers created by the loyalty system can be used in the following categories :').'</label>';
@@ -325,67 +326,67 @@ class Loyalty extends Module
$indexedCategories = isset($_POST['categoryBox']) ? $_POST['categoryBox'] : $index;
$helper = new Helper();
$html .= '<div class="margin-form">'.$helper->renderCategoryTree(null, $indexedCategories).'</div>';
$html .= '
$this->html .= '<div class="margin-form">'.$helper->renderCategoryTree(null, $indexedCategories).'</div>';
$this->html .= '
<p style="padding-left:200px;">'.$this->l('Mark the box(es) of categories in which loyalty vouchers are usable.').'</p>
<div class="clear"></div>
<h3 style="margin-top:20px">'.$this->l('Loyalty points progression').'</h3>
<label>'.$this->l('Initial').'</label>
<div class="margin-form">';
foreach ($languages as $language)
$html .= '
$this->html .= '
<div id="default_loyalty_state_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="default_loyalty_state_'.$language['id_lang'].'" value="'.(isset($this->loyaltyStateDefault->name[(int)($language['id_lang'])]) ? $this->loyaltyStateDefault->name[(int)($language['id_lang'])] : $this->loyaltyStateDefault->name[(int)$id_lang_default]).'" />
</div>';
$html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'default_loyalty_state', true);
$html .= ' </div>
$this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'default_loyalty_state', true);
$this->html .= ' </div>
<div class="clear"></div>
<label>'.$this->l('Unavailable').'</label>
<div class="margin-form">';
foreach ($languages as $language)
$html .= '
$this->html .= '
<div id="none_award_loyalty_state_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="none_award_loyalty_state_'.$language['id_lang'].'" value="'.(isset($this->loyaltyStateNoneAward->name[(int)($language['id_lang'])]) ? $this->loyaltyStateNoneAward->name[(int)($language['id_lang'])] : $this->loyaltyStateNoneAward->name[(int)$id_lang_default]).'" />
</div>';
$html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'none_award_loyalty_state', true);
$html .= ' </div>
$this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'none_award_loyalty_state', true);
$this->html .= ' </div>
<div class="clear"></div>
<label>'.$this->l('Converted').'</label>
<div class="margin-form">';
foreach ($languages as $language)
$html .= '
$this->html .= '
<div id="convert_loyalty_state_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="convert_loyalty_state_'.$language['id_lang'].'" value="'.(isset($this->loyaltyStateConvert->name[(int)($language['id_lang'])]) ? $this->loyaltyStateConvert->name[(int)($language['id_lang'])] : $this->loyaltyStateConvert->name[(int)$id_lang_default]).'" />
</div>';
$html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'convert_loyalty_state', true);
$html .= ' </div>
$this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'convert_loyalty_state', true);
$this->html .= ' </div>
<div class="clear"></div>
<label>'.$this->l('Validation').'</label>
<div class="margin-form">';
foreach ($languages as $language)
$html .= '
$this->html .= '
<div id="validation_loyalty_state_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="validation_loyalty_state_'.$language['id_lang'].'" value="'.(isset($this->loyaltyStateValidation->name[(int)($language['id_lang'])]) ? $this->loyaltyStateValidation->name[(int)($language['id_lang'])] : $this->loyaltyStateValidation->name[(int)$id_lang_default]).'" />
</div>';
$html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'validation_loyalty_state', true);
$html .= ' </div>
$this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'validation_loyalty_state', true);
$this->html .= ' </div>
<div class="clear"></div>
<label>'.$this->l('Cancelled').'</label>
<div class="margin-form">';
foreach ($languages as $language)
$html .= '
$this->html .= '
<div id="cancel_loyalty_state_'.$language['id_lang'].'" style="display: '.($language['id_lang'] == $id_lang_default ? 'block' : 'none').'; float: left;">
<input size="33" type="text" name="cancel_loyalty_state_'.$language['id_lang'].'" value="'.(isset($this->loyaltyStateCancel->name[(int)($language['id_lang'])]) ? $this->loyaltyStateCancel->name[(int)($language['id_lang'])] : $this->loyaltyStateCancel->name[(int)$id_lang_default]).'" />
</div>';
$html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'cancel_loyalty_state', true);
$html .= ' </div>
$this->html .= $this->displayFlags($languages, $id_lang_default, $languageIds, 'cancel_loyalty_state', true);
$this->html .= ' </div>
<div class="clear center">
<input type="submit" style="margin-top:20px" name="submitLoyalty" id="submitLoyalty" value="'.$this->l(' Save ').'" class="button" />
</div>
</fieldset>
</form>';
return $html;
return $this->html;
}
public static function recurseCategoryForInclude($id_obj, $indexedCategories, $categories, $current, $id_category = 1, $id_category_default = null, $has_suite = array())