6
6
*/
7
7
namespace Magento \Quote \Api ;
8
8
9
+ use Magento \Catalog \Model \CustomOptions \CustomOptionProcessor ;
10
+ use Magento \Framework \Webapi \Rest \Request ;
11
+ use Magento \Quote \Model \Quote ;
9
12
use Magento \TestFramework \TestCase \WebapiAbstract ;
10
13
11
14
class CartItemRepositoryTest extends WebapiAbstract
@@ -25,33 +28,43 @@ protected function setUp()
25
28
}
26
29
27
30
/**
28
- * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved .php
31
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_and_custom_options_saved .php
29
32
*/
30
33
public function testGetList ()
31
34
{
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 ' );
35
38
$ cartId = $ quote ->getId ();
36
39
$ output = [];
40
+ $ customOptionProcessor = $ this ->objectManager ->get (CustomOptionProcessor::class);
41
+
37
42
/** @var \Magento\Quote\Api\Data\CartItemInterface $item */
38
43
foreach ($ quote ->getAllItems () as $ item ) {
44
+ $ customOptionProcessor ->processOptions ($ item );
39
45
$ data = [
40
- 'item_id ' => $ item ->getItemId (),
46
+ 'item_id ' => ( int ) $ item ->getItemId (),
41
47
'sku ' => $ item ->getSku (),
42
48
'name ' => $ item ->getName (),
43
- 'price ' => $ item ->getPrice (),
44
- 'qty ' => $ item ->getQty (),
49
+ 'price ' => ( float ) $ item ->getPrice (),
50
+ 'qty ' => ( float ) $ item ->getQty (),
45
51
'product_type ' => $ item ->getProductType (),
46
- 'quote_id ' => $ item ->getQuoteId ()
52
+ 'quote_id ' => $ item ->getQuoteId (),
47
53
];
48
54
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
+
49
62
$ output [] = $ data ;
50
63
}
51
64
$ serviceInfo = [
52
65
'rest ' => [
53
66
'resourcePath ' => self ::RESOURCE_PATH . $ cartId . '/items ' ,
54
- 'httpMethod ' => \ Magento \ Framework \ Webapi \ Rest \ Request::HTTP_METHOD_GET ,
67
+ 'httpMethod ' => Request::HTTP_METHOD_GET ,
55
68
],
56
69
'soap ' => [
57
70
'service ' => self ::SERVICE_NAME ,
@@ -73,14 +86,14 @@ public function testAddItem()
73
86
/** @var \Magento\Catalog\Model\Product $product */
74
87
$ product = $ this ->objectManager ->create (\Magento \Catalog \Model \Product::class)->load (2 );
75
88
$ 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);
78
91
$ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
79
92
$ cartId = $ quote ->getId ();
80
93
$ serviceInfo = [
81
94
'rest ' => [
82
95
'resourcePath ' => self ::RESOURCE_PATH . $ cartId . '/items ' ,
83
- 'httpMethod ' => \ Magento \ Framework \ Webapi \ Rest \ Request::HTTP_METHOD_POST ,
96
+ 'httpMethod ' => Request::HTTP_METHOD_POST ,
84
97
],
85
98
'soap ' => [
86
99
'service ' => self ::SERVICE_NAME ,
@@ -106,8 +119,8 @@ public function testAddItem()
106
119
*/
107
120
public function testRemoveItem ()
108
121
{
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);
111
124
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
112
125
$ cartId = $ quote ->getId ();
113
126
$ product = $ this ->objectManager ->create (\Magento \Catalog \Model \Product::class);
@@ -117,7 +130,7 @@ public function testRemoveItem()
117
130
$ serviceInfo = [
118
131
'rest ' => [
119
132
'resourcePath ' => self ::RESOURCE_PATH . $ cartId . '/items/ ' . $ itemId ,
120
- 'httpMethod ' => \ Magento \ Framework \ Webapi \ Rest \ Request::HTTP_METHOD_DELETE ,
133
+ 'httpMethod ' => Request::HTTP_METHOD_DELETE ,
121
134
],
122
135
'soap ' => [
123
136
'service ' => self ::SERVICE_NAME ,
@@ -131,7 +144,7 @@ public function testRemoveItem()
131
144
"itemId " => $ itemId ,
132
145
];
133
146
$ this ->assertTrue ($ this ->_webApiCall ($ serviceInfo , $ requestData ));
134
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
147
+ $ quote = $ this ->objectManager ->create (Quote::class);
135
148
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
136
149
$ this ->assertFalse ($ quote ->hasProductId ($ productId ));
137
150
}
@@ -141,8 +154,8 @@ public function testRemoveItem()
141
154
*/
142
155
public function testUpdateItem ()
143
156
{
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);
146
159
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
147
160
$ cartId = $ quote ->getId ();
148
161
$ product = $ this ->objectManager ->create (\Magento \Catalog \Model \Product::class);
@@ -152,7 +165,7 @@ public function testUpdateItem()
152
165
$ serviceInfo = [
153
166
'rest ' => [
154
167
'resourcePath ' => self ::RESOURCE_PATH . $ cartId . '/items/ ' . $ itemId ,
155
- 'httpMethod ' => \ Magento \ Framework \ Webapi \ Rest \ Request::HTTP_METHOD_PUT ,
168
+ 'httpMethod ' => Request::HTTP_METHOD_PUT ,
156
169
],
157
170
'soap ' => [
158
171
'service ' => self ::SERVICE_NAME ,
@@ -178,7 +191,7 @@ public function testUpdateItem()
178
191
];
179
192
}
180
193
$ this ->_webApiCall ($ serviceInfo , $ requestData );
181
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
194
+ $ quote = $ this ->objectManager ->create (Quote::class);
182
195
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
183
196
$ this ->assertTrue ($ quote ->hasProductId (1 ));
184
197
$ item = $ quote ->getItemByProduct ($ product );
0 commit comments