Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CancelGuaranteeAbility.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
22  private $caseManagement;
23 
27  private $orderRepository;
28 
33  public function __construct(
34  CaseManagement $caseManagement,
35  OrderRepositoryInterface $orderRepository
36  ) {
37  $this->caseManagement = $caseManagement;
38  $this->orderRepository = $orderRepository;
39  }
40 
47  public function isAvailable($orderId)
48  {
49  $case = $this->caseManagement->getByOrderId($orderId);
50  if ($case === null) {
51  return false;
52  }
53 
54  if (in_array($case->getGuaranteeDisposition(), [null, $case::GUARANTEE_CANCELED])) {
55  return false;
56  }
57 
58  $order = $this->getOrder($orderId);
59  if (null === $order) {
60  return false;
61  }
62 
63  return true;
64  }
65 
72  private function getOrder($orderId)
73  {
74  try {
75  $order = $this->orderRepository->get($orderId);
76  } catch (InputException $e) {
77  return null;
78  } catch (NoSuchEntityException $e) {
79  return null;
80  }
81 
82  return $order;
83  }
84 }
$orderRepository
Definition: order.php:69
$case
$order
Definition: order.php:55
__construct(CaseManagement $caseManagement, OrderRepositoryInterface $orderRepository)