@@ -98,6 +98,46 @@ public function testAddBundleProductWithOptions(): void
9898 $ this ->assertEquals (Select::NAME , $ bundleOptions [0 ]['type ' ]);
9999 }
100100
101+ /**
102+ * @magentoApiDataFixture Magento/Bundle/_files/product_with_multiple_options_and_custom_quantity.php
103+ * @magentoApiDataFixture Magento/Customer/_files/customer.php
104+ *
105+ * @throws Exception
106+ */
107+ public function testAddingBundleItemWithCustomOptionQuantity ()
108+ {
109+ $ response = $ this ->graphQlQuery ($ this ->getProductQuery ("bundle-product " ));
110+ $ bundleItem = $ response ['products ' ]['items ' ][0 ];
111+ $ sku = $ bundleItem ['sku ' ];
112+ $ bundleOptions = $ bundleItem ['items ' ];
113+ $ customerId = 1 ;
114+ $ uId0 = $ bundleOptions [0 ]['options ' ][0 ]['uid ' ];
115+ $ uId1 = $ bundleOptions [1 ]['options ' ][0 ]['uid ' ];
116+ $ query = $ this ->getQueryWithCustomOptionQuantity ($ sku , 5 , $ uId0 , $ uId1 );
117+ $ response = $ this ->graphQlMutation ($ query , [], '' , $ this ->getHeaderMap ());
118+ $ wishlist = $ this ->wishlistFactory ->create ()->loadByCustomerId ($ customerId , true );
119+ /** @var Item $item */
120+ $ item = $ wishlist ->getItemCollection ()->getFirstItem ();
121+
122+ $ this ->assertArrayHasKey ('addProductsToWishlist ' , $ response );
123+ $ this ->assertArrayHasKey ('wishlist ' , $ response ['addProductsToWishlist ' ]);
124+ $ response = $ response ['addProductsToWishlist ' ]['wishlist ' ];
125+ $ this ->assertEquals ($ wishlist ->getItemsCount (), $ response ['items_count ' ]);
126+ $ this ->assertEquals ($ wishlist ->getSharingCode (), $ response ['sharing_code ' ]);
127+ $ this ->assertEquals ($ wishlist ->getUpdatedAt (), $ response ['updated_at ' ]);
128+ $ this ->assertEquals ($ item ->getData ('qty ' ), $ response ['items_v2 ' ][0 ]['quantity ' ]);
129+ $ this ->assertEquals ($ item ->getDescription (), $ response ['items_v2 ' ][0 ]['description ' ]);
130+ $ this ->assertEquals ($ item ->getAddedAt (), $ response ['items_v2 ' ][0 ]['added_at ' ]);
131+ $ this ->assertNotEmpty ($ response ['items_v2 ' ][0 ]['bundle_options ' ]);
132+ $ bundleOptions = $ response ['items_v2 ' ][0 ]['bundle_options ' ];
133+ $ this ->assertEquals ('Option 1 ' , $ bundleOptions [0 ]['label ' ]);
134+ $ bundleOptionOneValues = $ bundleOptions [0 ]['values ' ];
135+ $ this ->assertEquals (7 , $ bundleOptionOneValues [0 ]['quantity ' ]);
136+ $ this ->assertEquals ('Option 2 ' , $ bundleOptions [1 ]['label ' ]);
137+ $ bundleOptionTwoValues = $ bundleOptions [1 ]['values ' ];
138+ $ this ->assertEquals (1 , $ bundleOptionTwoValues [0 ]['quantity ' ]);
139+ }
140+
101141 /**
102142 * Authentication header map
103143 *
@@ -179,6 +219,118 @@ private function getQuery(
179219MUTATION ;
180220 }
181221
222+ /**
223+ * Query with custom option quantity
224+ *
225+ * @param string $sku
226+ * @param int $qty
227+ * @param string $uId0
228+ * @param string $uId1
229+ * @param int $wishlistId
230+ * @return string
231+ */
232+ private function getQueryWithCustomOptionQuantity (
233+ string $ sku ,
234+ int $ qty ,
235+ string $ uId0 ,
236+ string $ uId1 ,
237+ int $ wishlistId = 0
238+ ): string {
239+ return <<<MUTATION
240+ mutation {
241+ addProductsToWishlist(
242+ wishlistId: {$ wishlistId },
243+ wishlistItems: [
244+ {
245+ sku: " {$ sku }"
246+ quantity: {$ qty }
247+ entered_options: [
248+ {
249+ uid:" {$ uId0 }",
250+ value:"7"
251+ },
252+ {
253+ uid:" {$ uId1 }",
254+ value:"7"
255+ }
256+ ]
257+ }
258+ ]
259+ ) {
260+ user_errors {
261+ code
262+ message
263+ }
264+ wishlist {
265+ id
266+ sharing_code
267+ items_count
268+ updated_at
269+ items_v2 {
270+ id
271+ description
272+ quantity
273+ added_at
274+ ... on BundleWishlistItem {
275+ bundle_options {
276+ id
277+ label
278+ type
279+ values {
280+ id
281+ label
282+ quantity
283+ price
284+ }
285+ }
286+ }
287+ }
288+ }
289+ }
290+ }
291+ MUTATION ;
292+ }
293+
294+ /**
295+ * Returns GraphQL query for retrieving a product with customizable options
296+ *
297+ * @param string $sku
298+ * @return string
299+ */
300+ private function getProductQuery (string $ sku ): string
301+ {
302+ return <<<QUERY
303+ {
304+ products(search: " {$ sku }") {
305+ items {
306+ sku
307+ ... on BundleProduct {
308+ items {
309+ sku
310+ option_id
311+ required
312+ type
313+ title
314+ options {
315+ uid
316+ label
317+ product {
318+ sku
319+ }
320+ can_change_quantity
321+ id
322+ price
323+
324+ quantity
325+ }
326+ }
327+ }
328+ }
329+ }
330+ }
331+ QUERY ;
332+ }
333+
182334 /**
183335 * @param int $optionId
184336 * @param int $selectionId
0 commit comments