Skip to content

Commit f6bd430

Browse files
committed
MC-41810: Cannot add bundle product with more than 1 checkbox option to the cart via Graphql
1 parent ee9cd39 commit f6bd430

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,8 @@ public function getIdentities(\Magento\Catalog\Model\Product $product)
12311231
protected function getQty($selection, $qtys, $selectionOptionId)
12321232
{
12331233
if ($selection->getSelectionCanChangeQty() && isset($qtys[$selectionOptionId])) {
1234-
$qty = (float)$qtys[$selectionOptionId] > 0 ? $qtys[$selectionOptionId] : 1;
1234+
$selectionQty = $qtys[$selectionOptionId][$selection->getSelectionId()];
1235+
$qty = (float)$selectionQty > 0 ? $selectionQty : 1;
12351236
} else {
12361237
$qty = (float)$selection->getSelectionQty() ? $selection->getSelectionQty() : 1;
12371238
}

app/code/Magento/QuoteBundleOptions/Model/Cart/BuyRequest/BundleDataProvider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function execute(CartItem $cartItem): array
3838

3939
[$optionType, $optionId, $optionValueId, $optionQuantity] = $optionData;
4040
if ($optionType == self::OPTION_TYPE) {
41-
$bundleOptionsData['bundle_option'][$optionId] = $optionValueId;
42-
$bundleOptionsData['bundle_option_qty'][$optionId] = $optionQuantity;
41+
$bundleOptionsData['bundle_option'][$optionId][$optionValueId] = $optionValueId;
42+
$bundleOptionsData['bundle_option_qty'][$optionId][$optionValueId] = $optionQuantity;
4343
}
4444
}
4545
//for bundle options with custom quantity
@@ -55,8 +55,8 @@ public function execute(CartItem $cartItem): array
5555
[$optionType, $optionId, $optionValueId] = $optionData;
5656
if ($optionType == self::OPTION_TYPE) {
5757
$optionQuantity = $option->getValue();
58-
$bundleOptionsData['bundle_option'][$optionId] = $optionValueId;
59-
$bundleOptionsData['bundle_option_qty'][$optionId] = $optionQuantity;
58+
$bundleOptionsData['bundle_option'][$optionId][$optionValueId] = $optionValueId;
59+
$bundleOptionsData['bundle_option_qty'][$optionId][$optionValueId] = $optionQuantity;
6060
}
6161
}
6262

dev/tests/api-functional/testsuite/Magento/GraphQl/Bundle/AddBundleProductToCartSingleMutationTest.php

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,16 @@ public function testAddBundleToCartWithWrongBundleOptions()
232232
/**
233233
* @magentoApiDataFixture Magento/Bundle/_files/product_with_multiple_options_and_custom_quantity.php
234234
* @magentoApiDataFixture Magento/Checkout/_files/active_quote.php
235+
* @dataProvider bundleItemOptionsDataProvider
236+
* @return void
235237
*/
236-
public function testAddBundleItemWithCustomOptionQuantity()
238+
public function testAddBundleItemWithCustomOptionQuantity(
239+
string $optionQty0,
240+
string $optionQty1,
241+
string $expectedOptionQty0,
242+
string $expectedOptionQty1
243+
): void
237244
{
238-
239245
$this->quoteResource->load(
240246
$this->quote,
241247
'test_order_1',
@@ -250,11 +256,34 @@ public function testAddBundleItemWithCustomOptionQuantity()
250256
$uId0 = $bundleOptions[0]['options'][0]['uid'];
251257
$uId1 = $bundleOptions[1]['options'][0]['uid'];
252258
$response = $this->graphQlMutation(
253-
$this->getMutationsQuery($maskedQuoteId, $uId0, $uId1, $sku)
259+
$this->getMutationsQuery($maskedQuoteId, $uId0, $uId1, $sku, $optionQty0, $optionQty1)
254260
);
255261
$bundleOptions = $response['addProductsToCart']['cart']['items'][0]['bundle_options'];
256-
$this->assertEquals(5, $bundleOptions[0]['values'][0]['quantity']);
257-
$this->assertEquals(1, $bundleOptions[1]['values'][0]['quantity']);
262+
$this->assertEquals($expectedOptionQty0, $bundleOptions[0]['values'][0]['quantity']);
263+
$this->assertEquals($expectedOptionQty1, $bundleOptions[1]['values'][0]['quantity']);
264+
}
265+
266+
/**
267+
* Data provider for testAddBundleItemWithCustomOptionQuantity
268+
*
269+
* @return array
270+
*/
271+
public function bundleItemOptionsDataProvider(): array
272+
{
273+
return [
274+
[
275+
'optionQty0' => '10',
276+
'optionQty1' => '1',
277+
'expectedOptionQty0' => '10',
278+
'expectedOptionQty1' => '1',
279+
],
280+
[
281+
'optionQty0' => '5',
282+
'optionQty1' => '5',
283+
'expectedOptionQty0' => '5',
284+
'expectedOptionQty1' => '1',
285+
],
286+
];
258287
}
259288

260289
/**
@@ -298,11 +327,22 @@ private function getProductQuery(string $sku): string
298327
QUERY;
299328
}
300329

330+
/**
331+
* @param string $maskedQuoteId
332+
* @param string $optionUid0
333+
* @param string $optionUid1
334+
* @param string $sku
335+
* @param string $optionQty0
336+
* @param string $optionQty1
337+
* @return string
338+
*/
301339
private function getMutationsQuery(
302340
string $maskedQuoteId,
303341
string $optionUid0,
304342
string $optionUid1,
305-
string $sku
343+
string $sku,
344+
string $optionQty0,
345+
string $optionQty1
306346
): string {
307347
return <<<QUERY
308348
mutation {
@@ -313,15 +353,15 @@ private function getMutationsQuery(
313353
sku: "{$sku}"
314354
quantity: 2
315355
selected_options: [
316-
"{$optionUid1}", "{$optionUid0}"
356+
"{$optionUid0}", "{$optionUid1}"
317357
],
318358
entered_options: [{
319359
uid: "{$optionUid0}"
320-
value: "5"
360+
value: "{$optionQty0}"
321361
},
322362
{
323363
uid: "{$optionUid1}"
324-
value: "5"
364+
value: "{$optionQty1}"
325365
}]
326366
}
327367
]

0 commit comments

Comments
 (0)