Merge branch 'fix-loyalty' into develop

This commit is contained in:
Marion Muszynski 2016-09-14 12:17:41 +02:00
commit 813fb43ea3

View File

@ -244,6 +244,12 @@ class Loyalty extends Module
echo $this->displayError($errors);
}
}
if (Tools::isSubmit('submitUpdateLoyaltyOrders'))
{
$this->updateLoyaltyOrders();
echo $this->displayConfirmation($this->l('Loyalty Orders updated.'));
}
}
private function voucherCategories($categories)
@ -405,9 +411,47 @@ class Loyalty extends Module
</fieldset>
</form>';
$html .='<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
<div class="clear center">
<input type="submit" style="margin-top:20px" name="submitUpdateLoyaltyOrders" id="submitUpdateLoyaltyOrders" value="'.$this->l(' Update Loyalty Orders ').'" class="button" />
</div>
</fieldset>
</form>';
return $html;
}
public function updateLoyaltyOrders()
{
include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
include_once(dirname(__FILE__).'/LoyaltyModule.php');
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'] == $this->loyaltyStateValidation->id_order_state)
{
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
if ((float)($loyalty->discount_value) == 0) {
$loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($order);
}
}
$loyalty->save();
}
return true;
}
public static function recurseCategoryForInclude($id_obj, $indexedCategories, $categories, $current, $id_category = 1, $id_category_default = NULL, $has_suite = array())
{
global $done;