caseManagement = $caseManagement; $this->orderRepository = $orderRepository; } /** * Checks if it is possible to create Guarantee for order and case. * * @param int $orderId * @return bool */ public function isAvailable($orderId) { $case = $this->caseManagement->getByOrderId($orderId); if ($case === null) { return false; } if (in_array($case->getGuaranteeDisposition(), [null, $case::GUARANTEE_CANCELED])) { return false; } $order = $this->getOrder($orderId); if (null === $order) { return false; } return true; } /** * Returns order by id * * @param int $orderId * @return OrderInterface|null */ private function getOrder($orderId) { try { $order = $this->orderRepository->get($orderId); } catch (InputException $e) { return null; } catch (NoSuchEntityException $e) { return null; } return $order; } }