@@ -417,41 +417,79 @@ public function testAddConfigurableProductToCartWithCustomOption()
417
417
}
418
418
419
419
/**
420
- * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
420
+ * @magentoConfigFixture default_store checkout/cart/configurable_product_image itself
421
+ * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_child_products_with_images.php
421
422
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
422
- * @magentoApiDataFixture Magento/Store/_files/second_store.php
423
423
*/
424
- public function testAddConfigurableProductToCartWithDifferentStoreHeader ()
424
+ public function testAddConfigurableProductWithImageToCartItselfImage (): void
425
425
{
426
426
$ searchResponse = $ this ->graphQlQuery ($ this ->getFetchProductQuery ('configurable ' ));
427
427
$ product = current ($ searchResponse ['products ' ]['items ' ]);
428
428
429
- $ quantity = 2 ;
430
- $ maskedQuoteId = $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' );
429
+ $ quantity = 1 ;
431
430
$ parentSku = $ product ['sku ' ];
432
431
$ sku = 'simple_20 ' ;
433
- $ attributeId = (int ) $ product ['configurable_options ' ][0 ]['attribute_id ' ];
434
- $ optionId = $ product ['configurable_options ' ][0 ]['values ' ][1 ]['value_index ' ];
435
432
436
- $ query = $ this ->getQuery (
437
- $ maskedQuoteId ,
433
+ $ query = $ this ->graphQlQueryForVariant (
434
+ $ this -> getMaskedQuoteIdByReservedOrderId -> execute ( ' test_order_1 ' ) ,
438
435
$ parentSku ,
439
436
$ sku ,
440
437
$ quantity
441
438
);
442
- $ headerMap = [ ' Store ' => ' fixture_second_store ' ];
443
- $ response = $ this ->graphQlMutation ($ query, [], '' , $ headerMap );
439
+
440
+ $ response = $ this ->graphQlMutation ($ query );
444
441
445
442
$ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
446
443
self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
447
444
self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
448
- self ::assertArrayHasKey ('configurable_options ' , $ cartItem );
445
+ self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
449
446
450
- $ option = current ($ cartItem ['configurable_options ' ]);
451
- self ::assertEquals ($ attributeId , $ option ['id ' ]);
452
- self ::assertEquals ($ optionId , $ option ['value_id ' ]);
453
- self ::assertArrayHasKey ('option_label ' , $ option );
454
- self ::assertArrayHasKey ('value_label ' , $ option );
447
+ $ variant = $ cartItem ['configured_variant ' ];
448
+ $ expectedThumbnailUrl = 'magento_thumbnail.jpg ' ;
449
+ $ expectedThumbnailLabel = 'Thumbnail Image ' ;
450
+ $ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
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
+ $ sku = 'simple_20 ' ;
470
+
471
+ $ query = $ this ->graphQlQueryForVariant (
472
+ $ this ->getMaskedQuoteIdByReservedOrderId ->execute ('test_order_1 ' ),
473
+ $ parentSku ,
474
+ 'simple_20 ' ,
475
+ $ quantity
476
+ );
477
+
478
+ $ response = $ this ->graphQlMutation ($ query );
479
+
480
+ $ cartItem = current ($ response ['addConfigurableProductsToCart ' ]['cart ' ]['items ' ]);
481
+ self ::assertEquals ($ quantity , $ cartItem ['quantity ' ]);
482
+ self ::assertEquals ($ parentSku , $ cartItem ['product ' ]['sku ' ]);
483
+ self ::assertArrayHasKey ('configured_variant ' , $ cartItem );
484
+
485
+ $ variant = $ cartItem ['configured_variant ' ];
486
+ $ expectedThumbnailUrl = 'magento_thumbnail.jpg ' ;
487
+ $ expectedThumbnailLabel = 'Thumbnail Image ' ;
488
+ $ variantImage = basename ($ variant ['thumbnail ' ]['url ' ]);
489
+
490
+ self ::assertEquals ($ expectedThumbnailUrl , $ variantImage );
491
+ self ::assertEquals ($ expectedThumbnailLabel , $ variant ['thumbnail ' ]['label ' ]);
492
+ self ::assertEquals ($ sku , $ variant ['sku ' ]);
455
493
}
456
494
457
495
/**
@@ -499,6 +537,52 @@ private function getQuery(string $maskedQuoteId, string $parentSku, string $sku,
499
537
QUERY ;
500
538
}
501
539
540
+ /**
541
+ * @param string $maskedQuoteId
542
+ * @param string $parentSku
543
+ * @param string $sku
544
+ * @param int $quantity
545
+ * @return string
546
+ */
547
+ private function graphQlQueryForVariant (string $ maskedQuoteId , string $ parentSku , string $ sku , int $ quantity ): string
548
+ {
549
+ return <<<QUERY
550
+ mutation {
551
+ addConfigurableProductsToCart(
552
+ input:{
553
+ cart_id:" {$ maskedQuoteId }"
554
+ cart_items:{
555
+ parent_sku: " {$ parentSku }"
556
+ data:{
557
+ sku:" {$ sku }"
558
+ quantity: {$ quantity }
559
+ }
560
+ }
561
+ }
562
+ ) {
563
+ cart {
564
+ items {
565
+ id
566
+ quantity
567
+ product {
568
+ sku
569
+ }
570
+ ... on ConfigurableCartItem {
571
+ configured_variant {
572
+ sku
573
+ thumbnail {
574
+ label
575
+ url
576
+ }
577
+ }
578
+ }
579
+ }
580
+ }
581
+ }
582
+ }
583
+ QUERY ;
584
+ }
585
+
502
586
private function getFetchProductQuery (string $ term ): string
503
587
{
504
588
return <<<QUERY
@@ -538,6 +622,7 @@ private function getFetchProductQuery(string $term): string
538
622
*
539
623
* @param string $productSku
540
624
* @return array
625
+ * @throws Exception
541
626
*/
542
627
private function getAvailableProductCustomOption (string $ productSku ): array
543
628
{
0 commit comments