Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateCreditMemoStep.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Mtf\TestStep\TestStepInterface;
12 use Magento\Sales\Test\Page\Adminhtml\OrderCreditMemoNew;
13 use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
14 use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
15 use Magento\Sales\Test\TestStep\Utils\CompareQtyTrait;
16 
20 class CreateCreditMemoStep implements TestStepInterface
21 {
22  use CompareQtyTrait;
23 
29  protected $orderIndex;
30 
36  protected $salesOrderView;
37 
44 
50  protected $order;
51 
57  private $cart;
58 
66  public function __construct(
67  Cart $cart,
68  OrderIndex $orderIndex,
69  SalesOrderView $salesOrderView,
70  OrderInjectable $order,
71  OrderCreditMemoNew $orderCreditMemoNew
72  ) {
73  $this->cart = $cart;
74  $this->orderIndex = $orderIndex;
75  $this->salesOrderView = $salesOrderView;
76  $this->order = $order;
77  $this->orderCreditMemoNew = $orderCreditMemoNew;
78  }
79 
85  public function run()
86  {
87  $this->orderIndex->open();
88  $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]);
89  $refundsData = $this->order->getRefund() !== null ? $this->order->getRefund() : ['refundData' => []];
90  foreach ($refundsData as $refundData) {
91  $this->salesOrderView->getPageActions()->orderCreditMemo();
92 
93  $items = $this->cart->getItems();
94  $this->orderCreditMemoNew->getFormBlock()->fillProductData($refundData, $items);
95  if ($this->compare($items, $refundData)) {
96  $this->orderCreditMemoNew->getFormBlock()->updateQty();
97  }
98 
99  $this->orderCreditMemoNew->getFormBlock()->fillFormData($refundData);
100  $this->orderCreditMemoNew->getFormBlock()->submit();
101  }
102 
103  return [
104  'ids' => ['creditMemoIds' => $this->getCreditMemoIds()],
105  'customer' => $this->order->getDataFieldConfig('customer_id')['source']->getCustomer()
106  ];
107  }
108 
114  protected function getCreditMemoIds()
115  {
116  $this->salesOrderView->getOrderForm()->openTab('creditmemos');
117  return $this->salesOrderView->getOrderForm()->getTab('creditmemos')->getGridBlock()->getIds();
118  }
119 }
__construct(Cart $cart, OrderIndex $orderIndex, SalesOrderView $salesOrderView, OrderInjectable $order, OrderCreditMemoNew $orderCreditMemoNew)
$items