Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CreateInvoiceStep.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Mtf\TestStep\TestStepInterface;
12 use Magento\Sales\Test\Page\Adminhtml\OrderIndex;
13 use Magento\Sales\Test\Page\Adminhtml\OrderInvoiceNew;
14 use Magento\Sales\Test\Page\Adminhtml\OrderInvoiceView;
15 use Magento\Sales\Test\Page\Adminhtml\SalesOrderView;
16 use Magento\Sales\Test\TestStep\Utils\CompareQtyTrait;
17 use Magento\Shipping\Test\Page\Adminhtml\OrderShipmentView;
18 
22 class CreateInvoiceStep implements TestStepInterface
23 {
24  use CompareQtyTrait;
25 
31  private $orderIndex;
32 
38  private $salesOrderView;
39 
45  private $orderInvoiceNew;
46 
52  private $orderInvoiceView;
53 
59  private $orderShipmentView;
60 
66  private $order;
67 
73  private $paymentAction;
74 
80  private $cart;
81 
92  public function __construct(
93  Cart $cart,
94  OrderIndex $orderIndex,
95  SalesOrderView $salesOrderView,
96  OrderInvoiceNew $orderInvoiceNew,
97  OrderInvoiceView $orderInvoiceView,
98  OrderInjectable $order,
99  OrderShipmentView $orderShipmentView,
100  $paymentAction = 'authorize'
101  ) {
102  $this->cart = $cart;
103  $this->orderIndex = $orderIndex;
104  $this->salesOrderView = $salesOrderView;
105  $this->orderInvoiceNew = $orderInvoiceNew;
106  $this->orderInvoiceView = $orderInvoiceView;
107  $this->order = $order;
108  $this->orderShipmentView = $orderShipmentView;
109  $this->paymentAction = $paymentAction;
110  }
111 
117  public function run()
118  {
119  if ($this->paymentAction == 'sale') {
120  return null;
121  }
122  $this->orderIndex->open();
123  $this->orderIndex->getSalesOrderGrid()->searchAndOpen(['id' => $this->order->getId()]);
124  $invoicesData = $this->order->getInvoice() !== null ? $this->order->getInvoice() : ['invoiceData' => []];
125  foreach ($invoicesData as $invoiceData) {
126  $this->salesOrderView->getPageActions()->invoice();
127 
128  $items = $this->getItems();
129  $this->orderInvoiceNew->getFormBlock()->fillProductData($invoiceData, $items);
130  if ($this->compare($this->cart->getItems(), $invoiceData)) {
131  $this->orderInvoiceNew->getFormBlock()->updateQty();
132  }
133 
134  $this->orderInvoiceNew->getFormBlock()->fillFormData($invoiceData);
135  $this->orderInvoiceNew->getFormBlock()->submit();
136  $shipmentIds = $this->getShipmentIds();
137  }
138  $invoiceIds = $this->getInvoiceIds();
139 
140  return [
141  'ids' => [
142  'invoiceIds' => $invoiceIds,
143  'shipmentIds' => isset($shipmentIds) ? $shipmentIds : null,
144  ]
145  ];
146  }
147 
153  protected function getInvoiceIds()
154  {
155  $this->salesOrderView->getOrderForm()->openTab('invoices');
156  return $this->salesOrderView->getOrderForm()->getTab('invoices')->getGridBlock()->getIds();
157  }
158 
164  protected function getShipmentIds()
165  {
166  $this->salesOrderView->getOrderForm()->openTab('shipments');
167  return $this->salesOrderView->getOrderForm()->getTab('shipments')->getGridBlock()->getIds();
168  }
169 
175  protected function getItems()
176  {
177  return $this->cart->getItems();
178  }
179 }
$order
Definition: order.php:55
__construct(Cart $cart, OrderIndex $orderIndex, SalesOrderView $salesOrderView, OrderInvoiceNew $orderInvoiceNew, OrderInvoiceView $orderInvoiceView, OrderInjectable $order, OrderShipmentView $orderShipmentView, $paymentAction='authorize')
$items