@@ -60,16 +60,21 @@ protected function setUp(): void
60
60
public function testUpdateBundleProductWithOptions (): void
61
61
{
62
62
// 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
+ );
64
67
$ wishlistId = (int ) $ wishlist ['addProductsToWishlist ' ]['wishlist ' ]['id ' ];
65
68
$ wishlistItemId = (int ) $ wishlist ['addProductsToWishlist ' ]['wishlist ' ]['items_v2 ' ]['items ' ][0 ]['id ' ];
66
69
$ previousItemsCount = $ wishlist ['addProductsToWishlist ' ]['wishlist ' ]['items_count ' ];
67
70
68
71
// Set the new values to update the wishlist item with
69
72
$ newQuantity = 5 ;
70
73
$ 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
+ );
73
78
74
79
// Update the newly added wishlist item as the fixture customer
75
80
$ query = $ this ->getUpdateQuery (
@@ -179,19 +184,19 @@ private function getUpdateQuery(
179
184
}
180
185
181
186
/**
182
- * Add a product to the to the wishlist.
187
+ * Add the specified bundle product with the specified selected option to the wishlist.
183
188
*
189
+ * @param $bundleProductSku
190
+ * @param $selectedOptionSku
184
191
* @return array
185
192
* @throws AuthenticationException
186
193
*/
187
- private function addProductToWishlist ( ): array
194
+ private function addBundleProductToWishlist ( $ bundleProductSku , $ selectedOptionSku ): array
188
195
{
189
- $ bundleProductSku = 'bundle-product-dropdown-options ' ;
190
- $ bundleProductOptions = $ this ->getBundleProductOptions ($ bundleProductSku );
191
- $ initialBundleOptionUid = $ bundleProductOptions [0 ]["uid " ];
196
+ $ bundleOptionUid = $ this ->getBundleProductOptionUid ($ bundleProductSku , $ selectedOptionSku );
192
197
$ initialQuantity = 2 ;
193
198
194
- $ query = $ this ->getAddQuery ($ bundleProductSku , $ initialQuantity , $ initialBundleOptionUid );
199
+ $ query = $ this ->getAddQuery ($ bundleProductSku , $ initialQuantity , $ bundleOptionUid );
195
200
return $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
196
201
}
197
202
@@ -260,20 +265,31 @@ private function getAddQuery(
260
265
}
261
266
262
267
/**
263
- * Get the available options for the specified bundle product.
268
+ * Get the uid for the specified bundle product option .
264
269
*
265
270
* @param string $bundleProductSku
266
- * @return array
271
+ * @param string $selectedOptionSku
272
+ * @return string|null
267
273
*/
268
- private function getBundleProductOptions (string $ bundleProductSku )
274
+ private function getBundleProductOptionUid (string $ bundleProductSku, string $ selectedOptionSku )
269
275
{
270
276
$ query = $ this ->getBundleProductSearchQuery ($ bundleProductSku );
271
277
$ response = $ this ->graphQlQuery ($ query );
272
278
273
279
$ bundleProduct = $ response ["products " ]["items " ][0 ];
274
280
$ bundleProductOptions = $ bundleProduct ["items " ][0 ]["options " ];
281
+ $ bundleProductOptionUid = null ;
275
282
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 ;
277
293
}
278
294
279
295
/**
@@ -299,6 +315,9 @@ private function getBundleProductSearchQuery(string $bundleProductSku): string
299
315
options {
300
316
id
301
317
uid
318
+ product {
319
+ sku
320
+ }
302
321
}
303
322
}
304
323
}
0 commit comments