@@ -117,4 +117,96 @@ public function testPriceForCreatingQuoteFromEmptyCart()
117
117
$ quote ->load ($ quoteId );
118
118
$ quote ->delete ();
119
119
}
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
+ }
120
212
}
0 commit comments