9
9
10
10
use Magento \Framework \Escaper ;
11
11
use Magento \Sales \Api \Data \InvoiceInterface ;
12
+ use Magento \Sales \Api \Data \OrderItemInterface ;
12
13
use Magento \Sales \Model \Order ;
14
+ use Magento \Sales \Model \ResourceModel \Order \Item ;
13
15
use PHPUnit \Framework \Constraint \StringContains ;
14
16
15
17
/**
@@ -28,6 +30,9 @@ class SaveTest extends AbstractInvoiceControllerTest
28
30
/** @var Escaper */
29
31
private $ escaper ;
30
32
33
+ /** @var Item */
34
+ private $ orderItemResource ;
35
+
31
36
/**
32
37
* @inheritdoc
33
38
*/
@@ -36,6 +41,7 @@ protected function setUp(): void
36
41
parent ::setUp ();
37
42
38
43
$ this ->escaper = $ this ->_objectManager ->get (Escaper::class);
44
+ $ this ->orderItemResource = $ this ->_objectManager ->get (Item::class);
39
45
}
40
46
41
47
/**
@@ -173,6 +179,39 @@ public function testInvoiceWithoutQty(): void
173
179
$ this ->assertErrorResponse ($ this ->escaper ->escapeHtml ($ expectedMessage ));
174
180
}
175
181
182
+ /**
183
+ * @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
184
+ *
185
+ * @return void
186
+ */
187
+ public function testPartialInvoiceWitConfigurableProduct (): void
188
+ {
189
+ $ order = $ this ->getOrder ('100000001 ' );
190
+ $ post = $ this ->hydratePost ([$ order ->getItemsCollection ()->getFirstItem ()->getId () => '1 ' ]);
191
+ $ this ->prepareRequest ($ post , ['order_id ' => $ order ->getEntityId ()]);
192
+ $ this ->dispatch ('backend/sales/order_invoice/save ' );
193
+ $ this ->assertSessionMessages ($ this ->containsEqual ((string )__ ('The invoice has been created. ' )));
194
+ $ orderItems = $ this ->getOrderItemsQtyInvoiced ((int )$ order ->getEntityId ());
195
+ $ this ->assertCount (2 , $ orderItems );
196
+ $ this ->assertEquals ($ orderItems [0 ]['qty_invoiced ' ], $ orderItems [1 ]['qty_invoiced ' ]);
197
+ }
198
+
199
+ /**
200
+ * Get order items qty invoiced
201
+ *
202
+ * @param int $orderId
203
+ * @return array
204
+ */
205
+ private function getOrderItemsQtyInvoiced (int $ orderId ): array
206
+ {
207
+ $ connection = $ this ->orderItemResource ->getConnection ();
208
+ $ select = $ connection ->select ()
209
+ ->from ($ this ->orderItemResource ->getMainTable (), OrderItemInterface::QTY_INVOICED )
210
+ ->where (OrderItemInterface::ORDER_ID . ' = ? ' , $ orderId );
211
+
212
+ return $ connection ->fetchAll ($ select );
213
+ }
214
+
176
215
/**
177
216
* @inheritdoc
178
217
*/
0 commit comments