@@ -417,39 +417,78 @@ public function testAddConfigurableProductToCartWithCustomOption()
417
417
}
418
418
419
419
/**
420
+ * @magentoConfigFixture default_store checkout/cart/configurable_product_image itself
420
421
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_child_products_with_images.php
421
422
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
422
423
*/
423
- public function testAddConfigurableProductWithImageToCart ()
424
+ public function testAddConfigurableProductWithImageToCartItselfImage (): void
424
425
{
425
426
$ searchResponse = $ this ->graphQlQuery ($ this ->getFetchProductQuery ('configurable ' ));
426
427
$ product = current ($ searchResponse ['products ' ]['items ' ]);
427
-
428
+
428
429
$ quantity = 1 ;
429
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
430
430
$ parentSku = $ product ['sku ' ];
431
431
$ sku = 'simple_20 ' ;
432
- $ attributeId = (int ) $ product ['configurable_options ' ][0 ]['attribute_id ' ];
433
- $ optionId = $ product ['configurable_options ' ][0 ]['values ' ][1 ]['value_index ' ];
434
432
435
433
$ query = $ this ->graphQlQueryForVariant (
436
- $ maskedQuoteId ,
434
+ $ this -> getMaskedQuoteIdByReservedOrderId -> execute ( ' test_order_1 ' ) ,
437
435
$ parentSku ,
438
436
$ sku ,
439
437
$ quantity
440
438
);
441
-
439
+
442
440
$ response = $ this ->graphQlMutation ($ query );
443
-
441
+
444
442
$ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
445
443
self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
446
444
self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
447
445
self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
448
446
449
447
$ variant = $ cartItem ['configured_variant ' ];
450
- $ expectedThumbnailUrl = "magento_thumbnail.jpg " ;
448
+ $ expectedThumbnailUrl = 'magento_thumbnail.jpg ' ;
449
+ $ expectedThumbnailLabel = 'Thumbnail Image ' ;
451
450
$ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
452
- $ this ->assertEquals ($ expectedThumbnailUrl , $ variantImage );
451
+
452
+ self ::assertEquals ($ expectedThumbnailUrl , $ variantImage );
453
+ self ::assertEquals ($ expectedThumbnailLabel , $ variant ['thumbnail ' ]['label ' ]);
454
+ self ::assertEquals ($ sku , $ variant ['sku ' ]);
455
+ }
456
+
457
+ /**
458
+ * @magentoConfigFixture default_store checkout/cart/configurable_product_image parent
459
+ * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_child_products_with_images.php
460
+ * @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
461
+ */
462
+ public function testAddConfigurableProductWithImageToCartParentImage (): void
463
+ {
464
+ $ searchResponse = $ this ->graphQlQuery ($ this ->getFetchProductQuery ('configurable ' ));
465
+ $ product = current ($ searchResponse ['products ' ]['items ' ]);
466
+
467
+ $ quantity = 1 ;
468
+ $ parentSku = $ product ['sku ' ];
469
+
470
+ $ query = $ this ->graphQlQueryForVariant (
471
+ $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' ),
472
+ $ parentSku ,
473
+ 'simple_20 ' ,
474
+ $ quantity
475
+ );
476
+
477
+ $ response = $ this ->graphQlMutation ($ query );
478
+
479
+ $ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
480
+ self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
481
+ self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
482
+ self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
483
+
484
+ $ variant = $ cartItem ['configured_variant ' ];
485
+ $ expectedThumbnailUrl = 'thumbnail.jpg ' ;
486
+ $ expectedThumbnailLabel = 'Configurable Product ' ;
487
+ $ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
488
+
489
+ self ::assertEquals ($ expectedThumbnailUrl , $ variantImage );
490
+ self ::assertEquals ($ expectedThumbnailLabel , $ variant ['thumbnail ' ]['label ' ]);
491
+ self ::assertEquals ($ parentSku , $ variant ['sku ' ]);
453
492
}
454
493
455
494
/**
@@ -497,12 +536,12 @@ private function getQuery(string $maskedQuoteId, string $parentSku, string $sku,
497
536
QUERY ;
498
537
}
499
538
500
- /**
539
+ /**
501
540
* @param string $maskedQuoteId
502
541
* @param string $parentSku
503
542
* @param string $sku
504
543
* @param int $quantity
505
- * @return cart items with variants details
544
+ * @return string
506
545
*/
507
546
private function graphQlQueryForVariant (string $ maskedQuoteId , string $ parentSku , string $ sku , int $ quantity ): string
508
547
{
@@ -582,6 +621,7 @@ private function getFetchProductQuery(string $term): string
582
621
*
583
622
* @param string $productSku
584
623
* @return array
624
+ * @throws Exception
585
625
*/
586
626
private function getAvailableProductCustomOption (string $ productSku ): array
587
627
{
0 commit comments