@@ -416,6 +416,42 @@ public function testAddConfigurableProductToCartWithCustomOption()
416
416
$ this ->assertResponseFields ($ item ['customizable_options ' ], $ expectedOptions ['customizable_options ' ]);
417
417
}
418
418
419
+ /**
420
+ * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_child_products_with_images.php
421
+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
422
+ */
423
+ public function testAddConfigurableProductWithImageToCart ()
424
+ {
425
+ $ searchResponse = $ this ->graphQlQuery ($ this ->getFetchProductQuery ('configurable ' ));
426
+ $ product = current ($ searchResponse ['products ' ]['items ' ]);
427
+
428
+ $ quantity = 1 ;
429
+ $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
430
+ $ parentSku = $ product ['sku ' ];
431
+ $ sku = 'simple_20 ' ;
432
+ $ attributeId = (int ) $ product ['configurable_options ' ][0 ]['attribute_id ' ];
433
+ $ optionId = $ product ['configurable_options ' ][0 ]['values ' ][1 ]['value_index ' ];
434
+
435
+ $ query = $ this ->graphQlQueryForVariant (
436
+ $ maskedQuoteId ,
437
+ $ parentSku ,
438
+ $ sku ,
439
+ $ quantity
440
+ );
441
+
442
+ $ response = $ this ->graphQlMutation ($ query );
443
+
444
+ $ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
445
+ self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
446
+ self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
447
+ self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
448
+
449
+ $ variant = $ cartItem ['configured_variant ' ];
450
+ $ expectedThumbnailUrl = "magento_thumbnail.jpg " ;
451
+ $ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
452
+ $ this ->assertEquals ($ expectedThumbnailUrl , $ variantImage );
453
+ }
454
+
419
455
/**
420
456
* @param string $maskedQuoteId
421
457
* @param string $parentSku
@@ -458,6 +494,52 @@ private function getQuery(string $maskedQuoteId, string $parentSku, string $sku,
458
494
}
459
495
}
460
496
}
497
+ QUERY ;
498
+ }
499
+
500
+ /**
501
+ * @param string $maskedQuoteId
502
+ * @param string $parentSku
503
+ * @param string $sku
504
+ * @param int $quantity
505
+ * @return cart items with variants details
506
+ */
507
+ private function graphQlQueryForVariant (string $ maskedQuoteId , string $ parentSku , string $ sku , int $ quantity ): string
508
+ {
509
+ return <<<QUERY
510
+ mutation {
511
+ addConfigurableProductsToCart(
512
+ input:{
513
+ cart_id:" {$ maskedQuoteId }"
514
+ cart_items:{
515
+ parent_sku: " {$ parentSku }"
516
+ data:{
517
+ sku:" {$ sku }"
518
+ quantity: {$ quantity }
519
+ }
520
+ }
521
+ }
522
+ ) {
523
+ cart {
524
+ items {
525
+ id
526
+ quantity
527
+ product {
528
+ sku
529
+ }
530
+ ... on ConfigurableCartItem {
531
+ configured_variant {
532
+ sku
533
+ thumbnail {
534
+ label
535
+ url
536
+ }
537
+ }
538
+ }
539
+ }
540
+ }
541
+ }
542
+ }
461
543
QUERY ;
462
544
}
463
545
0 commit comments