Merge branch 'fix-loyalty'
This commit is contained in:
commit
18708e534f
@ -244,6 +244,12 @@ class Loyalty extends Module
|
||||
echo $this->displayError($errors);
|
||||
}
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('submitUpdateLoyaltyOrders'))
|
||||
{
|
||||
$count_orders = $this->updateLoyaltyOrders();
|
||||
echo $this->displayConfirmation($count_orders.' '.$this->l('Loyalty Orders updated.'));
|
||||
}
|
||||
}
|
||||
|
||||
private function voucherCategories($categories)
|
||||
@ -405,9 +411,48 @@ 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>
|
||||
</form>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function updateLoyaltyOrders()
|
||||
{
|
||||
include_once(dirname(__FILE__).'/LoyaltyStateModule.php');
|
||||
include_once(dirname(__FILE__).'/LoyaltyModule.php');
|
||||
|
||||
$count_orders = 0;
|
||||
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();
|
||||
$count_orders++;
|
||||
}
|
||||
return $count_orders;
|
||||
}
|
||||
|
||||
public static function recurseCategoryForInclude($id_obj, $indexedCategories, $categories, $current, $id_category = 1, $id_category_default = NULL, $has_suite = array())
|
||||
{
|
||||
global $done;
|
||||
|
Loading…
Reference in New Issue
Block a user