Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReturnToStockOrder.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
22  private $returnProcessor;
23 
27  private $creditmemoRepository;
28 
32  private $orderRepository;
33 
37  private $stockConfiguration;
38 
47  public function __construct(
48  ReturnProcessor $returnProcessor,
49  CreditmemoRepositoryInterface $creditmemoRepository,
50  OrderRepositoryInterface $orderRepository,
51  StockConfigurationInterface $stockConfiguration
52  ) {
53  $this->returnProcessor = $returnProcessor;
54  $this->creditmemoRepository = $creditmemoRepository;
55  $this->orderRepository = $orderRepository;
56  $this->stockConfiguration = $stockConfiguration;
57  }
58 
71  public function afterExecute(
72  RefundOrderInterface $refundService,
73  $resultEntityId,
74  $orderId,
75  array $items = [],
76  $notify = false,
77  $appendComment = false,
78  \Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment = null,
79  \Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface $arguments = null
80  ) {
81  $order = $this->orderRepository->get($orderId);
82 
83  $returnToStockItems = [];
84  if ($arguments !== null
85  && $arguments->getExtensionAttributes() !== null
86  && $arguments->getExtensionAttributes()->getReturnToStockItems() !== null
87  ) {
88  $returnToStockItems = $arguments->getExtensionAttributes()->getReturnToStockItems();
89  }
90  $isAutoReturn = $this->stockConfiguration->isAutoReturnEnabled();
91  if ($isAutoReturn || !empty($returnToStockItems)) {
92  $creditmemo = $this->creditmemoRepository->get($resultEntityId);
93  $this->returnProcessor->execute($creditmemo, $order, $returnToStockItems, $isAutoReturn);
94  }
95  return $resultEntityId;
96  }
97 }
$orderRepository
Definition: order.php:69
$order
Definition: order.php:55
__construct(ReturnProcessor $returnProcessor, CreditmemoRepositoryInterface $creditmemoRepository, OrderRepositoryInterface $orderRepository, StockConfigurationInterface $stockConfiguration)
$arguments
afterExecute(RefundOrderInterface $refundService, $resultEntityId, $orderId, array $items=[], $notify=false, $appendComment=false, \Magento\Sales\Api\Data\CreditmemoCommentCreationInterface $comment=null, \Magento\Sales\Api\Data\CreditmemoCreationArgumentsInterface $arguments=null)
$items