Skip to content

Commit bc76180

Browse files
committed
MAGETWO-70743: Custom options are not listed in API call
1 parent 495d0c4 commit bc76180

File tree

3 files changed

+80
-21
lines changed

3 files changed

+80
-21
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public function getCartItemProcessors()
4242
return $this->cartItemProcessors;
4343
}
4444

45-
$arguments = $this->objectManagerConfig->getArguments(\Magento\Quote\Model\Quote\Item\Repository::class);
45+
$typePreference = $this->objectManagerConfig->getPreference(Repository::class);
46+
$arguments = $this->objectManagerConfig->getArguments($typePreference);
4647
if (isset($arguments['cartItemProcessors'])) {
4748
// Workaround for compiled mode.
4849
$processors = isset($arguments['cartItemProcessors']['_vac_'])

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

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77
namespace Magento\Quote\Api;
88

9+
use Magento\Catalog\Model\CustomOptions\CustomOptionProcessor;
10+
use Magento\Framework\Webapi\Rest\Request;
11+
use Magento\Quote\Model\Quote;
912
use Magento\TestFramework\TestCase\WebapiAbstract;
1013

1114
class CartItemRepositoryTest extends WebapiAbstract
@@ -25,33 +28,43 @@ protected function setUp()
2528
}
2629

2730
/**
28-
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
31+
* @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_and_custom_options_saved.php
2932
*/
3033
public function testGetList()
3134
{
32-
/** @var \Magento\Quote\Model\Quote $quote */
33-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
34-
$quote->load('test_order_item_with_items', 'reserved_order_id');
35+
/** @var Quote $quote */
36+
$quote = $this->objectManager->create(Quote::class);
37+
$quote->load('test_order_item_with_items_and_custom_options', 'reserved_order_id');
3538
$cartId = $quote->getId();
3639
$output = [];
40+
$customOptionProcessor = $this->objectManager->get(CustomOptionProcessor::class);
41+
3742
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
3843
foreach ($quote->getAllItems() as $item) {
44+
$customOptionProcessor->processOptions($item);
3945
$data = [
40-
'item_id' => $item->getItemId(),
46+
'item_id' => (int)$item->getItemId(),
4147
'sku' => $item->getSku(),
4248
'name' => $item->getName(),
43-
'price' => $item->getPrice(),
44-
'qty' => $item->getQty(),
49+
'price' => (float)$item->getPrice(),
50+
'qty' => (float)$item->getQty(),
4551
'product_type' => $item->getProductType(),
46-
'quote_id' => $item->getQuoteId()
52+
'quote_id' => $item->getQuoteId(),
4753
];
4854

55+
if ($item->getProductOption() !== null) {
56+
$customOptions = $item->getProductOption()->getExtensionAttributes()->getCustomOptions();
57+
foreach ($customOptions as $option) {
58+
$data['product_option']['extension_attributes']['custom_options'][] = $option->getData();
59+
}
60+
}
61+
4962
$output[] = $data;
5063
}
5164
$serviceInfo = [
5265
'rest' => [
5366
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items',
54-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
67+
'httpMethod' => Request::HTTP_METHOD_GET,
5568
],
5669
'soap' => [
5770
'service' => self::SERVICE_NAME,
@@ -73,14 +86,14 @@ public function testAddItem()
7386
/** @var \Magento\Catalog\Model\Product $product */
7487
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class)->load(2);
7588
$productSku = $product->getSku();
76-
/** @var \Magento\Quote\Model\Quote $quote */
77-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
89+
/** @var Quote $quote */
90+
$quote = $this->objectManager->create(Quote::class);
7891
$quote->load('test_order_1', 'reserved_order_id');
7992
$cartId = $quote->getId();
8093
$serviceInfo = [
8194
'rest' => [
8295
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items',
83-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
96+
'httpMethod' => Request::HTTP_METHOD_POST,
8497
],
8598
'soap' => [
8699
'service' => self::SERVICE_NAME,
@@ -106,8 +119,8 @@ public function testAddItem()
106119
*/
107120
public function testRemoveItem()
108121
{
109-
/** @var \Magento\Quote\Model\Quote $quote */
110-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
122+
/** @var Quote $quote */
123+
$quote = $this->objectManager->create(Quote::class);
111124
$quote->load('test_order_item_with_items', 'reserved_order_id');
112125
$cartId = $quote->getId();
113126
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
@@ -117,7 +130,7 @@ public function testRemoveItem()
117130
$serviceInfo = [
118131
'rest' => [
119132
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items/' . $itemId,
120-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_DELETE,
133+
'httpMethod' => Request::HTTP_METHOD_DELETE,
121134
],
122135
'soap' => [
123136
'service' => self::SERVICE_NAME,
@@ -131,7 +144,7 @@ public function testRemoveItem()
131144
"itemId" => $itemId,
132145
];
133146
$this->assertTrue($this->_webApiCall($serviceInfo, $requestData));
134-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
147+
$quote = $this->objectManager->create(Quote::class);
135148
$quote->load('test_order_item_with_items', 'reserved_order_id');
136149
$this->assertFalse($quote->hasProductId($productId));
137150
}
@@ -141,8 +154,8 @@ public function testRemoveItem()
141154
*/
142155
public function testUpdateItem()
143156
{
144-
/** @var \Magento\Quote\Model\Quote $quote */
145-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
157+
/** @var Quote $quote */
158+
$quote = $this->objectManager->create(Quote::class);
146159
$quote->load('test_order_item_with_items', 'reserved_order_id');
147160
$cartId = $quote->getId();
148161
$product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
@@ -152,7 +165,7 @@ public function testUpdateItem()
152165
$serviceInfo = [
153166
'rest' => [
154167
'resourcePath' => self::RESOURCE_PATH . $cartId . '/items/' . $itemId,
155-
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_PUT,
168+
'httpMethod' => Request::HTTP_METHOD_PUT,
156169
],
157170
'soap' => [
158171
'service' => self::SERVICE_NAME,
@@ -178,7 +191,7 @@ public function testUpdateItem()
178191
];
179192
}
180193
$this->_webApiCall($serviceInfo, $requestData);
181-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
194+
$quote = $this->objectManager->create(Quote::class);
182195
$quote->load('test_order_item_with_items', 'reserved_order_id');
183196
$this->assertTrue($quote->hasProductId(1));
184197
$item = $quote->getItemByProduct($product);
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/../../Checkout/_files/quote_with_address.php';
8+
require __DIR__ . '/../../Catalog/_files/product_simple.php';
9+
10+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
11+
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
12+
$productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
13+
$product = $productRepository->get('simple');
14+
15+
$options = [];
16+
/** @var $option \Magento\Catalog\Model\Product\Option */
17+
foreach ($product->getOptions() as $option) {
18+
switch ($option->getGroupByType()) {
19+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_DATE:
20+
$value = ['year' => 2013, 'month' => 8, 'day' => 9, 'hour' => 13, 'minute' => 35];
21+
break;
22+
case \Magento\Catalog\Api\Data\ProductCustomOptionInterface::OPTION_GROUP_SELECT:
23+
$value = key($option->getValues());
24+
break;
25+
default:
26+
$value = 'test';
27+
break;
28+
}
29+
$options[$option->getId()] = $value;
30+
}
31+
32+
$requestInfo = new \Magento\Framework\DataObject(['qty' => 1, 'options' => $options]);
33+
34+
$quote->setReservedOrderId('test_order_item_with_items_and_custom_options')
35+
->addProduct($product, $requestInfo);
36+
$quote->collectTotals();
37+
$objectManager->get(\Magento\Quote\Model\QuoteRepository::class)->save($quote);
38+
39+
/** @var \Magento\Quote\Model\QuoteIdMask $quoteIdMask */
40+
$quoteIdMask = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
41+
->create(\Magento\Quote\Model\QuoteIdMaskFactory::class)
42+
->create();
43+
$quoteIdMask->setQuoteId($quote->getId());
44+
$quoteIdMask->setDataChanges(true);
45+
$quoteIdMask->save();

0 commit comments

Comments
 (0)