public function hookUpdateOrderStatus($params) { include_once dirname(__FILE__) . '/LoyaltyStateModule.php'; include_once dirname(__FILE__) . '/LoyaltyModule.php'; if (!Validate::isLoadedObject($params['newOrderStatus'])) { die(Tools::displayError('Missing parameters')); } $newOrder = $params['newOrderStatus']; $order = new Order((int) $params['id_order']); if ($order and !Validate::isLoadedObject($order)) { die(Tools::displayError('Incorrect object Order.')); } $this->instanceDefaultStates(); $return = false; if ($newOrder->id == $this->loyaltyStateValidation->id_order_state or $newOrder->id == $this->loyaltyStateCancel->id_order_state) { if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId($order->id)))) { return false; } if ((int) Configuration::get('PS_LOYALTY_NONE_AWARD') and $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) { return true; } if ($newOrder->id == $this->loyaltyStateValidation->id_order_state) { $loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId(); if ((int) $loyalty->points < 0) { $loyalty->points = abs((int) $loyalty->points); } $return &= $loyalty->save(); } elseif ($newOrder->id == $this->loyaltyStateCancel->id_order_state) { $loyalties = LoyaltyModule::getAllByOrderId($order->id); if (is_array($loyalties)) { foreach ($loyalties as $entity) { $loyalty = new LoyaltyModule($entity['id_loyalty']); $loyalty->id_loyalty_state = LoyaltyStateModule::getCancelId(); $loyalty->points = 0; $return &= $loyalty->save(); } } } return $loyalty->save(); } return $return; }