Skip to content

Commit 6af1f80

Browse files
30350:Unable to update the items of a bundle-product in a wishlist- Updated the functional tests to add product into wishlist and update
1 parent 068286f commit 6af1f80

File tree

1 file changed

+136
-40
lines changed

1 file changed

+136
-40
lines changed

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

Lines changed: 136 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,52 @@ protected function setUp(): void
5050
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
5151
}
5252

53+
/**
54+
* @magentoConfigFixture default_store wishlist/general/active 1
55+
* @magentoApiDataFixture Magento/Customer/_files/customer.php
56+
* @magentoApiDataFixture Magento/Bundle/_files/product_1.php
57+
*
58+
* @throws Exception
59+
*/
60+
public function testUpdateBundleProductWithOptions(): void
61+
{
62+
$qty = 2;
63+
$optionQty = 1;
64+
$sku = 'bundle-product';
65+
$product = $this->productRepository->get($sku);
66+
/** @var Type $typeInstance */
67+
$typeInstance = $product->getTypeInstance();
68+
$typeInstance->setStoreFilter($product->getStoreId(), $product);
69+
/** @var Option $option */
70+
$option = $typeInstance->getOptionsCollection($product)->getLastItem();
71+
/** @var Product $selection */
72+
$selection = $typeInstance->getSelectionsCollection([$option->getId()], $product)->getLastItem();
73+
$optionId = $option->getId();
74+
$selectionId = $selection->getSelectionId();
75+
$bundleOptions = $this->generateBundleOptionUid((int) $optionId, (int) $selectionId, $optionQty);
76+
77+
// Add product to wishlist
78+
$this->addProductToWishlist();
79+
80+
$wishlist = $this->getBundleWishlist();
81+
$wishlistId = $wishlist['customer']['wishlists'][0]['id'];
82+
$wishlistItemId = $wishlist['customer']['wishlists'][0]['items_v2'][0]['id'];
83+
$itemsCount = $wishlist['customer']['wishlists'][0]['items_count'];
84+
85+
$query = $this->getBundleQuery((int)$wishlistItemId, $qty, $bundleOptions, (int)$wishlistId);
86+
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
87+
88+
$this->assertArrayHasKey('updateProductsInWishlist', $response);
89+
$this->assertArrayHasKey('wishlist', $response['updateProductsInWishlist']);
90+
$response = $response['updateProductsInWishlist']['wishlist'];
91+
$this->assertEquals($itemsCount, $response['items_count']);
92+
$this->assertEquals($qty, $response['items_v2'][0]['quantity']);
93+
$this->assertNotEmpty($response['items_v2'][0]['bundle_options']);
94+
$bundleOptions = $response['items_v2'][0]['bundle_options'];
95+
$this->assertEquals('Bundle Product Items', $bundleOptions[0]['label']);
96+
$this->assertEquals(Select::NAME, $bundleOptions[0]['type']);
97+
}
98+
5399
/**
54100
* Authentication header map
55101
*
@@ -111,73 +157,134 @@ private function getCustomerBundleWishlistQuery(): string
111157
QUERY;
112158
}
113159

160+
/**
161+
* Returns GraphQl mutation string
162+
*
163+
* @param int $wishlistItemId
164+
* @param int $qty
165+
* @param string $bundleOptions
166+
* @param int $wishlistId
167+
*
168+
* @return string
169+
*/
170+
private function getBundleQuery(
171+
int $wishlistItemId,
172+
int $qty,
173+
string $bundleOptions,
174+
int $wishlistId = 0
175+
): string {
176+
return <<<MUTATION
177+
mutation {
178+
updateProductsInWishlist(
179+
wishlistId: {$wishlistId},
180+
wishlistItems: [
181+
{
182+
wishlist_item_id: "{$wishlistItemId}"
183+
quantity: {$qty}
184+
selected_options: [
185+
"{$bundleOptions}"
186+
]
187+
}
188+
]
189+
) {
190+
user_errors {
191+
code
192+
message
193+
}
194+
wishlist {
195+
id
196+
sharing_code
197+
items_count
198+
updated_at
199+
items_v2 {
200+
id
201+
description
202+
quantity
203+
... on BundleWishlistItem {
204+
bundle_options {
205+
id
206+
label
207+
type
208+
values {
209+
id
210+
label
211+
quantity
212+
price
213+
}
214+
}
215+
}
216+
}
217+
}
218+
}
219+
}
220+
MUTATION;
221+
}
222+
223+
/**
224+
* @param int $optionId
225+
* @param int $selectionId
226+
*
227+
* @param int $quantity
228+
*
229+
* @return string
230+
*/
231+
private function generateBundleOptionUid(int $optionId, int $selectionId, int $quantity): string
232+
{
233+
return base64_encode("bundle/$optionId/$selectionId/$quantity");
234+
}
235+
114236
/**
115237
* @magentoConfigFixture default_store wishlist/general/active 1
116238
* @magentoApiDataFixture Magento/Customer/_files/customer.php
117239
* @magentoApiDataFixture Magento/Bundle/_files/product_1.php
118240
*
119241
* @throws Exception
120242
*/
121-
public function testUpdateBundleProductWithOptions(): void
243+
private function addProductToWishlist(): void
122244
{
123-
$wishlist = $this->getBundleWishlist();
245+
$sku = 'bundle-product';
246+
$product = $this->productRepository->get($sku);
124247
$qty = 2;
125248
$optionQty = 1;
126-
$optionId = $wishlist['customer']['wishlists'][0]['items_v2'][0]['bundle_options'][0]['id'];
127249

128-
$sku = 'bundle-product';
129-
$product = $this->productRepository->get($sku);
130250
/** @var Type $typeInstance */
131251
$typeInstance = $product->getTypeInstance();
132252
$typeInstance->setStoreFilter($product->getStoreId(), $product);
133253
/** @var Option $option */
134-
$option = $typeInstance->getOptionsCollection($product)->getLastItem();
254+
$option = $typeInstance->getOptionsCollection($product)->getFirstItem();
135255
/** @var Product $selection */
136-
$selection = $typeInstance->getSelectionsCollection([$option->getId()], $product)->getLastItem();
256+
$selection = $typeInstance->getSelectionsCollection([$option->getId()], $product)->getFirstItem();
137257
$optionId = $option->getId();
138258
$selectionId = $selection->getSelectionId();
139259
$bundleOptions = $this->generateBundleOptionUid((int) $optionId, (int) $selectionId, $optionQty);
140260

141-
$wishlistId = $wishlist['customer']['wishlists'][0]['id'];
142-
$wishlistItemId = $wishlist['customer']['wishlists'][0]['items_v2'][0]['id'];
143-
$itemsCount = $wishlist['customer']['wishlists'][0]['items_count'];
144-
$query = $this->getBundleQuery((int)$wishlistItemId, $qty, $bundleOptions, (int)$wishlistId);
145-
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());
146-
147-
$this->assertArrayHasKey('updateProductsInWishlist', $response);
148-
$this->assertArrayHasKey('wishlist', $response['updateProductsInWishlist']);
149-
$response = $response['updateProductsInWishlist']['wishlist'];
150-
$this->assertEquals($itemsCount, $response['items_count']);
151-
$this->assertEquals($qty, $response['items_v2'][0]['quantity']);
152-
$this->assertNotEmpty($response['items_v2'][0]['bundle_options']);
153-
$bundleOptions = $response['items_v2'][0]['bundle_options'];
154-
$this->assertEquals('Bundle Product Items', $bundleOptions[0]['label']);
155-
$this->assertEquals(Select::NAME, $bundleOptions[0]['type']);
261+
$query = $this->addQuery($sku, $qty, $bundleOptions);
262+
$this->graphQlMutation($query, [], '', $this->getHeaderMap());
156263
}
157264

158265
/**
159-
* Returns GraphQl mutation string
266+
* Returns GraphQl add mutation string
160267
*
161-
* @param int $wishlistItemId
268+
* @param string $sku
162269
* @param int $qty
163270
* @param string $bundleOptions
164271
* @param int $wishlistId
165272
*
166273
* @return string
167274
*/
168-
private function getBundleQuery(
169-
int $wishlistItemId,
275+
private function addQuery(
276+
string $sku,
170277
int $qty,
171278
string $bundleOptions,
172279
int $wishlistId = 0
173280
): string {
174281
return <<<MUTATION
175282
mutation {
176-
updateProductsInWishlist(
283+
addProductsToWishlist(
177284
wishlistId: {$wishlistId},
178285
wishlistItems: [
179286
{
180-
wishlist_item_id: "{$wishlistItemId}"
287+
sku: "{$sku}"
181288
quantity: {$qty}
182289
selected_options: [
183290
"{$bundleOptions}"
@@ -198,6 +305,7 @@ private function getBundleQuery(
198305
id
199306
description
200307
quantity
308+
added_at
201309
... on BundleWishlistItem {
202310
bundle_options {
203311
id
@@ -218,16 +326,4 @@ private function getBundleQuery(
218326
MUTATION;
219327
}
220328

221-
/**
222-
* @param int $optionId
223-
* @param int $selectionId
224-
*
225-
* @param int $quantity
226-
*
227-
* @return string
228-
*/
229-
private function generateBundleOptionUid(int $optionId, int $selectionId, int $quantity): string
230-
{
231-
return base64_encode("bundle/$optionId/$selectionId/$quantity");
232-
}
233329
}

0 commit comments

Comments
 (0)