Skip to content

Commit efdf73b

Browse files
authored
ENGCOM-5705: Clone product before adding to cart #855
2 parents d7c9265 + 86ffc1d commit efdf73b

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/AddSimpleProductToCart.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function execute(Quote $cart, array $cartItemData): void
5555
$sku = $this->extractSku($cartItemData);
5656

5757
try {
58-
$product = $this->productRepository->get($sku);
58+
$product = $this->productRepository->get($sku, false, null, true);
5959
} catch (NoSuchEntityException $e) {
6060
throw new GraphQlNoSuchEntityException(__('Could not find a product with SKU "%sku"', ['sku' => $sku]));
6161
}

dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/AddConfigurableProductToCartTest.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,78 @@ public function testAddConfigurableProductToCart()
6767
self::assertArrayHasKey('value_label', $option);
6868
}
6969

70+
/**
71+
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
72+
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
73+
*/
74+
public function testAddMultipleConfigurableProductToCart()
75+
{
76+
$searchResponse = $this->graphQlQuery($this->getFetchProductQuery('configurable'));
77+
$product = current($searchResponse['products']['items']);
78+
79+
$quantityOne = 1;
80+
$quantityTwo = 2;
81+
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_order_1');
82+
$parentSku = $product['sku'];
83+
$skuOne = 'simple_10';
84+
$skuTwo = 'simple_20';
85+
$valueIdOne = $product['configurable_options'][0]['values'][0]['value_index'];
86+
87+
$query = <<<QUERY
88+
mutation {
89+
addConfigurableProductsToCart(input:{
90+
cart_id:"{$maskedQuoteId}"
91+
cart_items:[
92+
{
93+
parent_sku:"{$parentSku}"
94+
data:{
95+
sku:"{$skuOne}"
96+
quantity:{$quantityOne}
97+
}
98+
}
99+
{
100+
parent_sku:"{$parentSku}"
101+
data:{
102+
sku:"{$skuTwo}"
103+
quantity:{$quantityTwo}
104+
}
105+
}
106+
]
107+
}) {
108+
cart {
109+
items {
110+
id
111+
quantity
112+
product {
113+
sku
114+
}
115+
... on ConfigurableCartItem {
116+
configurable_options {
117+
option_label
118+
value_label
119+
value_id
120+
}
121+
}
122+
}
123+
}
124+
}
125+
}
126+
QUERY;
127+
128+
$response = $this->graphQlMutation($query);
129+
130+
$cartItems = $response['addConfigurableProductsToCart']['cart']['items'];
131+
self::assertCount(2, $cartItems);
132+
133+
foreach ($cartItems as $cartItem) {
134+
if ($cartItem['configurable_options'][0]['value_id'] === $valueIdOne) {
135+
self::assertEquals($quantityOne, $cartItem['quantity']);
136+
} else {
137+
self::assertEquals($quantityTwo, $cartItem['quantity']);
138+
}
139+
}
140+
}
141+
70142
/**
71143
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable_sku.php
72144
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php

0 commit comments

Comments
 (0)