13
13
use Magento \CatalogInventory \Api \Data \StockItemInterface ;
14
14
use Magento \Framework \Api \SearchCriteriaBuilder ;
15
15
use Magento \Framework \Exception \AuthenticationException ;
16
+ use Magento \GraphQl \GetCustomerAuthenticationHeader ;
16
17
use Magento \Integration \Api \CustomerTokenServiceInterface ;
17
18
use Magento \Sales \Api \OrderRepositoryInterface ;
18
19
use Magento \Sales \Model \Order ;
19
- use Magento \TestFramework \Helper \Bootstrap ;
20
20
use Magento \Sales \Model \ResourceModel \Order \Collection ;
21
+ use Magento \TestFramework \Helper \Bootstrap ;
21
22
use Magento \TestFramework \TestCase \GraphQlAbstract ;
22
- use Magento \GraphQl \GetCustomerAuthenticationHeader ;
23
23
24
24
/**
25
25
* Class RetrieveOrdersTest
@@ -194,14 +194,198 @@ public function testGetCustomerOrderWithBundleProduct()
194
194
$ this ->assertEquals ("Pending " , $ customerOrderItems ['status ' ]);
195
195
196
196
$ bundledItemInTheOrder = $ customerOrderItems ['items ' ][0 ];
197
- $ this ->assertEquals ('bundle-product-two-dropdown-options ' , $ bundledItemInTheOrder ['product_sku ' ]);
197
+ $ this ->assertEquals ('bundle-product-two-dropdown-options-simple1-simple2 ' , $ bundledItemInTheOrder ['product_sku ' ]);
198
+ $ this ->assertArrayHasKey ('child_items ' , $ bundledItemInTheOrder );
199
+ $ childItemInTheOrder = $ bundledItemInTheOrder ['child_items ' ][0 ];
200
+ $ this ->assertNotEmpty ($ childItemInTheOrder );
201
+ $ this ->assertEquals ('simple1 ' , $ childItemInTheOrder ['product_sku ' ]);
202
+ $ this ->deleteOrder ();
203
+ }
204
+
205
+ /**
206
+ * Test customer order details with bundle products
207
+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
208
+ * @magentoApiDataFixture Magento/Bundle/_files/bundle_product_two_dropdown_options.php
209
+ * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_rule_for_region_1.php
210
+ * @magentoApiDataFixture Magento/SalesRule/_files/cart_rule_10_percent_off_with_discount_on_shipping.php
211
+ * @magentoApiDataFixture Magento/GraphQl/Tax/_files/tax_calculation_shipping_excludeTax_order_display_settings.php
212
+ */
213
+ public function testGetCustomerOrderWithBundleProductWithTaxesAndDiscounts ()
214
+ {
215
+ $ qty = 4 ;
216
+ $ bundleSku = 'bundle-product-two-dropdown-options ' ;
217
+ $ simpleProductSku = 'simple2 ' ;
218
+ /** @var Product $simple */
219
+ $ simple = $ this ->productRepository ->get ($ simpleProductSku );
220
+ $ stockData =[
221
+ StockItemInterface::QTY => 200 ,
222
+ StockItemInterface::MANAGE_STOCK =>true ,
223
+ StockItemInterface::IS_IN_STOCK =>true
224
+ ];
225
+ $ simple ->setQuantityAndStockStatus ($ stockData );
226
+ $ this ->productRepository ->save ($ simple );
227
+ /** @var Product $bundleProduct */
228
+ $ bundleProduct = $ this ->productRepository ->get ($ bundleSku );
229
+ /** @var $typeInstance \Magento\Bundle\Model\Product\Type */
230
+ $ typeInstance = $ bundleProduct ->getTypeInstance ();
231
+ /** @var $option \Magento\Bundle\Model\Option */
232
+ $ option1 = $ typeInstance ->getOptionsCollection ($ bundleProduct )->getFirstItem ();
233
+ $ option2 = $ typeInstance ->getOptionsCollection ($ bundleProduct )->getLastItem ();
234
+ $ optionId1 =(int ) $ option1 ->getId ();
235
+ $ optionId2 =(int ) $ option2 ->getId ();
236
+ /** @var Selection $selection */
237
+ $ selection1 = $ typeInstance ->getSelectionsCollection ([$ option1 ->getId ()], $ bundleProduct )->getFirstItem ();
238
+ $ selectionId1 = (int )$ selection1 ->getSelectionId ();
239
+
240
+ $ selection2 = $ typeInstance ->getSelectionsCollection ([$ option2 ->getId ()], $ bundleProduct )->getLastItem ();
241
+ $ selectionId2 = (int )$ selection2 ->getSelectionId ();
242
+
243
+ $ cartId = $ this ->createEmptyCart ();
244
+ $ this ->addBundleProductToCart ($ cartId , $ qty , $ bundleSku , $ optionId1 , $ selectionId1 , $ optionId2 , $ selectionId2 );
245
+ $ this ->setBillingAddress ($ cartId );
246
+ $ shippingMethod = $ this ->setShippingAddress ($ cartId );
247
+ $ paymentMethod = $ this ->setShippingMethod ($ cartId , $ shippingMethod );
248
+ $ this ->setPaymentMethod ($ cartId , $ paymentMethod );
249
+ $ orderNumber = $ this ->placeOrder ($ cartId );
250
+ $ customerOrderResponse = $ this ->getCustomerOrderQueryBundleProduct ($ orderNumber );
251
+
252
+ $ customerOrderItems = $ customerOrderResponse [0 ];
253
+ $ this ->assertEquals ("Pending " , $ customerOrderItems ['status ' ]);
254
+
255
+ $ bundledItemInTheOrder = $ customerOrderItems ['items ' ][0 ];
256
+ $ this ->assertEquals ('bundle-product-two-dropdown-options-simple1-simple2 ' , $ bundledItemInTheOrder ['product_sku ' ]);
198
257
$ this ->assertArrayHasKey ('child_items ' , $ bundledItemInTheOrder );
199
258
$ childItemInTheOrder = $ bundledItemInTheOrder ['child_items ' ][0 ];
200
259
$ this ->assertNotEmpty ($ childItemInTheOrder );
201
- $ this ->assertEquals ('simple-1 ' , $ childItemInTheOrder ['product_sku ' ]);
260
+ $ this ->assertEquals ('simple1 ' , $ childItemInTheOrder ['product_sku ' ]);
261
+ $ this ->assertEquals (
262
+ 0 ,
263
+ $ childItemInTheOrder ['discounts ' ][0 ]['amount ' ]['value ' ]
264
+ );
265
+ $ this ->assertEquals (
266
+ 'USD ' ,
267
+ $ childItemInTheOrder ['discounts ' ][0 ]['amount ' ]['currency ' ]
268
+ );
269
+ $ this ->assertEquals (
270
+ 'null ' ,
271
+ $ childItemInTheOrder ['discounts ' ][0 ]['label ' ]
272
+ );
273
+ $ this ->assertTotalsOnBundleProductWithTaxesAndDiscounts ($ customerOrderItems );
202
274
$ this ->deleteOrder ();
203
275
}
204
276
277
+ /**
278
+ * Assert order totals including shipping_handling and taxes
279
+ *
280
+ * @param array $customerOrderItem
281
+ */
282
+ private function assertTotalsOnBundleProductWithTaxesAndDiscounts (array $ customerOrderItem ): void
283
+ {
284
+ $ this ->assertEquals (
285
+ 77.4 ,
286
+ $ customerOrderItem ['total ' ]['base_grand_total ' ]['value ' ]
287
+ );
288
+
289
+ $ this ->assertEquals (
290
+ 77.4 ,
291
+ $ customerOrderItem ['total ' ]['grand_total ' ]['value ' ]
292
+ );
293
+ $ this ->assertEquals (
294
+ 60 ,
295
+ $ customerOrderItem ['total ' ]['subtotal ' ]['value ' ]
296
+ );
297
+ $ this ->assertEquals (
298
+ 5.4 ,
299
+ $ customerOrderItem ['total ' ]['total_tax ' ]['value ' ]
300
+ );
301
+
302
+ $ this ->assertEquals (
303
+ 20 ,
304
+ $ customerOrderItem ['total ' ]['total_shipping ' ]['value ' ]
305
+ );
306
+ $ this ->assertEquals (
307
+ 1.35 ,
308
+ $ customerOrderItem ['total ' ]['taxes ' ][0 ]['amount ' ]['value ' ]
309
+ );
310
+ $ this ->assertEquals (
311
+ 'USD ' ,
312
+ $ customerOrderItem ['total ' ]['taxes ' ][0 ]['amount ' ]['currency ' ]
313
+ );
314
+ $ this ->assertEquals (
315
+ 'US-TEST-*-Rate-1 ' ,
316
+ $ customerOrderItem ['total ' ]['taxes ' ][0 ]['title ' ]
317
+ );
318
+ $ this ->assertEquals (
319
+ 7.5 ,
320
+ $ customerOrderItem ['total ' ]['taxes ' ][0 ]['rate ' ]
321
+ );
322
+ $ this ->assertEquals (
323
+ 4.05 ,
324
+ $ customerOrderItem ['total ' ]['taxes ' ][1 ]['amount ' ]['value ' ]
325
+ );
326
+ $ this ->assertEquals (
327
+ 'USD ' ,
328
+ $ customerOrderItem ['total ' ]['taxes ' ][1 ]['amount ' ]['currency ' ]
329
+ );
330
+ $ this ->assertEquals (
331
+ 'US-TEST-*-Rate-1 ' ,
332
+ $ customerOrderItem ['total ' ]['taxes ' ][1 ]['title ' ]
333
+ );
334
+ $ this ->assertEquals (
335
+ 7.5 ,
336
+ $ customerOrderItem ['total ' ]['taxes ' ][1 ]['rate ' ]
337
+ );
338
+ $ this ->assertEquals (
339
+ 21.5 ,
340
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['amount_including_tax ' ]['value ' ]
341
+ );
342
+ $ this ->assertEquals (
343
+ 20 ,
344
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['amount_excluding_tax ' ]['value ' ]
345
+ );
346
+ $ this ->assertEquals (
347
+ 20 ,
348
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['total_amount ' ]['value ' ]
349
+ );
350
+
351
+ $ this ->assertEquals (
352
+ 1.35 ,
353
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['taxes ' ][0 ]['amount ' ]['value ' ]
354
+ );
355
+ $ this ->assertEquals (
356
+ 'US-TEST-*-Rate-1 ' ,
357
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['taxes ' ][0 ]['title ' ]
358
+ );
359
+ $ this ->assertEquals (
360
+ 7.5 ,
361
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['taxes ' ][0 ]['rate ' ]
362
+ );
363
+ $ this ->assertEquals (
364
+ 2 ,
365
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['amount ' ]['value ' ]
366
+ );
367
+ $ this ->assertEquals (
368
+ 'USD ' ,
369
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['amount ' ]['currency ' ]
370
+ );
371
+ $ this ->assertEquals (
372
+ 'null ' ,
373
+ $ customerOrderItem ['total ' ]['shipping_handling ' ]['discounts ' ][0 ]['label ' ]
374
+ );
375
+ $ this ->assertEquals (
376
+ -8 ,
377
+ $ customerOrderItem ['total ' ]['discounts ' ][0 ]['amount ' ]['value ' ]
378
+ );
379
+ $ this ->assertEquals (
380
+ 'USD ' ,
381
+ $ customerOrderItem ['total ' ]['discounts ' ][0 ]['amount ' ]['currency ' ]
382
+ );
383
+ $ this ->assertEquals (
384
+ 'null ' ,
385
+ $ customerOrderItem ['total ' ]['discounts ' ][0 ]['label ' ]
386
+ );
387
+ }
388
+
205
389
/**
206
390
* @magentoApiDataFixture Magento/Customer/_files/customer.php
207
391
* @magentoApiDataFixture Magento/Sales/_files/orders_with_customer.php
@@ -995,7 +1179,7 @@ private function addProductToCart(string $cartId, float $qty, string $sku): void
995
1179
* @param int $selectionId
996
1180
* @throws AuthenticationException
997
1181
*/
998
- public function addBundleProductToCart (string $ cartId , float $ qty , string $ sku , int $ optionId1 , int $ selectionId1 ,int $ optionId2 , int $ selectionId2 )
1182
+ public function addBundleProductToCart (string $ cartId , float $ qty , string $ sku , int $ optionId1 , int $ selectionId1 , int $ optionId2 , int $ selectionId2 )
999
1183
{
1000
1184
$ query = <<<QUERY
1001
1185
mutation {
@@ -1034,7 +1218,6 @@ public function addBundleProductToCart(string $cartId, float $qty, string $sku,
1034
1218
$ this ->assertArrayHasKey ('cart ' , $ response ['addBundleProductsToCart ' ]);
1035
1219
}
1036
1220
1037
-
1038
1221
/**
1039
1222
* @param string $cartId
1040
1223
* @param array $auth
@@ -1287,6 +1470,13 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
1287
1470
__typename
1288
1471
... on BundleOrderItem{
1289
1472
child_items{
1473
+ discounts{
1474
+ amount{
1475
+ value
1476
+ currency
1477
+ }
1478
+ label
1479
+ }
1290
1480
__typename
1291
1481
product_sku
1292
1482
product_name
@@ -1304,13 +1494,27 @@ private function getCustomerOrderQueryBundleProduct($orderNumber)
1304
1494
total_tax{value}
1305
1495
subtotal { value currency }
1306
1496
taxes {amount{value currency} title rate}
1497
+ discounts{
1498
+ amount{
1499
+ value
1500
+ currency
1501
+ }
1502
+ label
1503
+ }
1307
1504
total_shipping{value}
1308
1505
shipping_handling
1309
1506
{
1310
1507
amount_including_tax{value}
1311
1508
amount_excluding_tax{value}
1312
1509
total_amount{value}
1313
1510
taxes {amount{value} title rate}
1511
+ discounts{
1512
+ amount{
1513
+ value
1514
+ currency
1515
+ }
1516
+ label
1517
+ }
1314
1518
}
1315
1519
}
1316
1520
}
0 commit comments