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'] == $loyaltyStateValidation->id_order_state) { $loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId(); if ((float)($loyalty->discount_value) == 0) { $loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($order); } } $loyalty->save(); }