Skip to content

Commit eb02e7a

Browse files
AC-5986::Unable to update cart item custom option values with REST API
1 parent 2854866 commit eb02e7a

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

app/code/Magento/Quote/Model/Quote/Item/CartItemPersister.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public function save(CartInterface $quote, CartItemInterface $item)
7777
/** Update item product options */
7878
if ($currentItem->getQty() !== $buyRequestData->getQty()) {
7979
$item = $quote->updateItem($itemId, $buyRequestData);
80+
} else {
81+
$item = $quote->updateItem($itemId, $buyRequestData);
8082
}
8183
} else {
8284
if ($item->getQty() !== $currentItem->getQty()) {

dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartAddingItemsTest.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,96 @@ public function testPriceForCreatingQuoteFromEmptyCart()
117117
$quote->load($quoteId);
118118
$quote->delete();
119119
}
120+
121+
/**
122+
* Test add to product with custom option and test with updating custom options.
123+
*
124+
* @magentoApiDataFixture Magento/Catalog/_files/product_simple_with_custom_options.php
125+
* @return void
126+
*/
127+
public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
128+
{
129+
// Creating empty cart
130+
$serviceInfoForCreatingEmptyCart = [
131+
'rest' => [
132+
'resourcePath' => self::RESOURCE_PATH,
133+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
134+
],
135+
'soap' => [
136+
'service' => self::SERVICE_NAME,
137+
'serviceVersion' => self::SERVICE_VERSION,
138+
'operation' => self::SERVICE_NAME . 'CreateEmptyCart',
139+
],
140+
];
141+
$quoteId = $this->_webApiCall($serviceInfoForCreatingEmptyCart);
142+
143+
// Adding item to the cart
144+
$serviceInfoForAddingProduct = [
145+
'rest' => [
146+
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items',
147+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
148+
],
149+
'soap' => [
150+
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
151+
'serviceVersion' => self::SERVICE_VERSION,
152+
'operation' => GuestCartItemRepositoryTest::SERVICE_NAME . 'Save',
153+
],
154+
];
155+
$requestData = [
156+
'cartItem' => [
157+
'quote_id' => $quoteId,
158+
'sku' => 'simple_with_custom_options',
159+
'qty' => 1,
160+
'product_option' => [
161+
'extension_attributes' => [
162+
'custom_options' => [
163+
['option_id' => 1, 'option_value' => 1],
164+
['option_id' => 2, 'option_value' => 1],
165+
['option_id' => 3, 'option_value' => 'test']
166+
]
167+
]
168+
]
169+
]
170+
];
171+
$item = $this->_webApiCall($serviceInfoForAddingProduct, $requestData);
172+
$this->assertNotEmpty($item);
173+
174+
$requestData = [
175+
'cartItem' => [
176+
'quote_id' => $quoteId,
177+
'sku' => 'simple_with_custom_options',
178+
'qty' => 1,
179+
'product_option' => [
180+
'extension_attributes' => [
181+
'custom_options' => [
182+
['option_id' => 1, 'option_value' => 2],
183+
['option_id' => 2, 'option_value' => 2],
184+
['option_id' => 3, 'option_value' => 'test2']
185+
]
186+
]
187+
]
188+
]
189+
];
190+
191+
// Delete the item for the cart
192+
$serviceInfoForUpdateProduct = [
193+
'rest' => [
194+
'resourcePath' => self::RESOURCE_PATH . $quoteId . '/items/' . $item['item_id'],
195+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
196+
],
197+
'soap' => [
198+
'service' => GuestCartItemRepositoryTest::SERVICE_NAME,
199+
'serviceVersion' => self::SERVICE_VERSION,
200+
'operation' => GuestCartItemRepositoryTest::SERVICE_NAME . 'Save',
201+
],
202+
];
203+
204+
$item = $this->_webApiCall($serviceInfoForUpdateProduct, $requestData);
205+
$this->assertNotEmpty($item);
206+
207+
/** @var \Magento\Quote\Model\Quote $quote */
208+
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
209+
$quote->load($quoteId);
210+
$quote->delete();
211+
}
120212
}

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_custom_options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'use_config_manage_stock' => 1,
3636
'qty' => 100,
3737
'is_qty_decimal' => 0,
38-
'is_in_stock' => 1,
38+
'is_in_stock' => 2,
3939
]
4040
)->setCanSaveCustomOptions(true)
4141
->setHasOptions(true);

0 commit comments

Comments
 (0)