Skip to content

Commit a4a8e42

Browse files
committed
MC-37484: Cart query error when trying to switch store view
1 parent 6f24462 commit a4a8e42

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/AddSimpleProductsToCart.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6363
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
6464
$this->addProductsToCart->execute($cart, $cartItems);
6565

66+
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId(), $storeId);
6667
return [
6768
'cart' => [
6869
'model' => $cart,

dev/tests/api-functional/testsuite/Magento/GraphQl/Quote/Guest/AddSimpleProductToCartTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,56 @@ public function testAddSimpleProductToCart()
8181
self::assertEquals('USD', $rowTotalIncludingTax['currency']);
8282
}
8383

84+
/**
85+
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
86+
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
87+
* @magentoApiDataFixture Magento/Store/_files/second_store.php
88+
*/
89+
public function testAddSimpleProductWithDifferentStoreHeader()
90+
{
91+
$sku = 'simple_product';
92+
$quantity = 2;
93+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');
94+
95+
$headerMap = ['Store' => 'fixture_second_store'];
96+
$query = $this->getQuery($maskedQuoteId, $sku, $quantity);
97+
$response = $this->graphQlMutation($query, [], '', $headerMap);
98+
self::assertArrayHasKey('cart', $response['addSimpleProductsToCart']);
99+
100+
self::assertArrayHasKey('shipping_addresses', $response['addSimpleProductsToCart']['cart']);
101+
self::assertEmpty($response['addSimpleProductsToCart']['cart']['shipping_addresses']);
102+
self::assertEquals($quantity, $response['addSimpleProductsToCart']['cart']['items'][0]['quantity']);
103+
self::assertEquals($sku, $response['addSimpleProductsToCart']['cart']['items'][0]['product']['sku']);
104+
self::assertArrayHasKey('prices', $response['addSimpleProductsToCart']['cart']['items'][0]);
105+
self::assertArrayHasKey('id', $response['addSimpleProductsToCart']['cart']);
106+
self::assertEquals($maskedQuoteId, $response['addSimpleProductsToCart']['cart']['id']);
107+
108+
self::assertArrayHasKey('price', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
109+
$price = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['price'];
110+
self::assertArrayHasKey('value', $price);
111+
self::assertEquals(10, $price['value']);
112+
self::assertArrayHasKey('currency', $price);
113+
self::assertEquals('USD', $price['currency']);
114+
115+
self::assertArrayHasKey('row_total', $response['addSimpleProductsToCart']['cart']['items'][0]['prices']);
116+
$rowTotal = $response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total'];
117+
self::assertArrayHasKey('value', $rowTotal);
118+
self::assertEquals(20, $rowTotal['value']);
119+
self::assertArrayHasKey('currency', $rowTotal);
120+
self::assertEquals('USD', $rowTotal['currency']);
121+
122+
self::assertArrayHasKey(
123+
'row_total_including_tax',
124+
$response['addSimpleProductsToCart']['cart']['items'][0]['prices']
125+
);
126+
$rowTotalIncludingTax =
127+
$response['addSimpleProductsToCart']['cart']['items'][0]['prices']['row_total_including_tax'];
128+
self::assertArrayHasKey('value', $rowTotalIncludingTax);
129+
self::assertEquals(20, $rowTotalIncludingTax['value']);
130+
self::assertArrayHasKey('currency', $rowTotalIncludingTax);
131+
self::assertEquals('USD', $rowTotalIncludingTax['currency']);
132+
}
133+
84134
/**
85135
* @magentoApiDataFixture Magento/Catalog/_files/product_with_image_no_options.php
86136
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php

0 commit comments

Comments
 (0)