Skip to content

Commit 5dcf4f0

Browse files
Merge remote-tracking branch 'honey-badgers/PWA-1567' into PWA-1740-PR
2 parents 645e1a5 + 1448b79 commit 5dcf4f0

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

dev/tests/api-functional/testsuite/Magento/GraphQl/Wishlist/UpdateBundleProductsFromWishlistTest.php

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,21 @@ protected function setUp(): void
6060
public function testUpdateBundleProductWithOptions(): void
6161
{
6262
// Add the fixture bundle product to the fixture customer's wishlist
63-
$wishlist = $this->addProductToWishlist();
63+
$wishlist = $this->addBundleProductToWishlist(
64+
'bundle-product-dropdown-options',
65+
'simple-1'
66+
);
6467
$wishlistId = (int) $wishlist['addProductsToWishlist']['wishlist']['id'];
6568
$wishlistItemId = (int) $wishlist['addProductsToWishlist']['wishlist']['items_v2']['items'][0]['id'];
6669
$previousItemsCount = $wishlist['addProductsToWishlist']['wishlist']['items_count'];
6770

6871
// Set the new values to update the wishlist item with
6972
$newQuantity = 5;
7073
$newDescription = 'This is a test.';
71-
$bundleProductOptions = $this->getBundleProductOptions('bundle-product-dropdown-options');
72-
$newBundleOptionUid = $bundleProductOptions[1]["uid"];
74+
$newBundleOptionUid = $this->getBundleProductOptionUid(
75+
'bundle-product-dropdown-options',
76+
'simple2'
77+
);
7378

7479
// Update the newly added wishlist item as the fixture customer
7580
$query = $this->getUpdateQuery(
@@ -179,19 +184,19 @@ private function getUpdateQuery(
179184
}
180185

181186
/**
182-
* Add a product to the to the wishlist.
187+
* Add the specified bundle product with the specified selected option to the wishlist.
183188
*
189+
* @param $bundleProductSku
190+
* @param $selectedOptionSku
184191
* @return array
185192
* @throws AuthenticationException
186193
*/
187-
private function addProductToWishlist(): array
194+
private function addBundleProductToWishlist($bundleProductSku, $selectedOptionSku): array
188195
{
189-
$bundleProductSku = 'bundle-product-dropdown-options';
190-
$bundleProductOptions = $this->getBundleProductOptions($bundleProductSku);
191-
$initialBundleOptionUid = $bundleProductOptions[0]["uid"];
196+
$bundleOptionUid = $this->getBundleProductOptionUid($bundleProductSku, $selectedOptionSku);
192197
$initialQuantity = 2;
193198

194-
$query = $this->getAddQuery($bundleProductSku, $initialQuantity, $initialBundleOptionUid);
199+
$query = $this->getAddQuery($bundleProductSku, $initialQuantity, $bundleOptionUid);
195200
return $this->graphQlMutation($query, [], '', $this->getHeaderMap());
196201
}
197202

@@ -260,20 +265,31 @@ private function getAddQuery(
260265
}
261266

262267
/**
263-
* Get the available options for the specified bundle product.
268+
* Get the uid for the specified bundle product option.
264269
*
265270
* @param string $bundleProductSku
266-
* @return array
271+
* @param string $selectedOptionSku
272+
* @return string|null
267273
*/
268-
private function getBundleProductOptions(string $bundleProductSku)
274+
private function getBundleProductOptionUid(string $bundleProductSku, string $selectedOptionSku)
269275
{
270276
$query = $this->getBundleProductSearchQuery($bundleProductSku);
271277
$response = $this->graphQlQuery($query);
272278

273279
$bundleProduct = $response["products"]["items"][0];
274280
$bundleProductOptions = $bundleProduct["items"][0]["options"];
281+
$bundleProductOptionUid = null;
275282

276-
return $bundleProductOptions;
283+
// Search the specified bundle product for the specified option based on the product sku
284+
foreach ($bundleProductOptions as $bundleProductOption) {
285+
if (isset($bundleProductOption['product'])
286+
&& $bundleProductOption['product']['sku'] === $selectedOptionSku) {
287+
$bundleProductOptionUid = $bundleProductOption['uid'];
288+
break;
289+
}
290+
}
291+
292+
return $bundleProductOptionUid;
277293
}
278294

279295
/**
@@ -299,6 +315,9 @@ private function getBundleProductSearchQuery(string $bundleProductSku): string
299315
options {
300316
id
301317
uid
318+
product {
319+
sku
320+
}
302321
}
303322
}
304323
}

0 commit comments

Comments
 (0)