5
5
*/
6
6
namespace Magento \Quote \Api ;
7
7
8
+ use Magento \Catalog \Model \Product ;
8
9
use Magento \CatalogInventory \Api \StockRegistryInterface ;
9
10
use Magento \CatalogInventory \Model \Stock ;
11
+ use Magento \Quote \Model \Quote ;
12
+ use Magento \Quote \Model \QuoteIdMask ;
13
+ use Magento \Quote \Model \QuoteIdMaskFactory ;
14
+ use Magento \Store \Model \StoreManagerInterface ;
10
15
use Magento \TestFramework \Helper \Bootstrap ;
11
16
use Magento \TestFramework \ObjectManager ;
12
17
use Magento \TestFramework \TestCase \WebapiAbstract ;
@@ -40,14 +45,14 @@ protected function setUp(): void
40
45
*/
41
46
public function testGetList ()
42
47
{
43
- /** @var \Magento\ Quote\Model\Quote $quote */
44
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
48
+ /** @var Quote $quote */
49
+ $ quote = $ this ->objectManager ->create (Quote::class);
45
50
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
46
51
$ cartId = $ quote ->getId ();
47
52
48
- /** @var \Magento\Quote\Model\ QuoteIdMask $quoteIdMask */
49
- $ quoteIdMask = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
50
- ->create (\ Magento \ Quote \ Model \ QuoteIdMaskFactory::class)
53
+ /** @var QuoteIdMask $quoteIdMask */
54
+ $ quoteIdMask = Bootstrap::getObjectManager ()
55
+ ->create (QuoteIdMaskFactory::class)
51
56
->create ();
52
57
$ quoteIdMask ->load ($ cartId , 'quote_id ' );
53
58
//Use masked cart Id
@@ -92,17 +97,17 @@ public function testGetList()
92
97
*/
93
98
public function testAddItem ()
94
99
{
95
- /** @var \Magento\Catalog\Model\ Product $product */
96
- $ product = $ this ->objectManager ->create (\ Magento \ Catalog \ Model \ Product::class)->load (2 );
100
+ /** @var Product $product */
101
+ $ product = $ this ->objectManager ->create (Product::class)->load (2 );
97
102
$ productSku = $ product ->getSku ();
98
- /** @var \Magento\ Quote\Model\Quote $quote */
99
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
103
+ /** @var Quote $quote */
104
+ $ quote = $ this ->objectManager ->create (Quote::class);
100
105
$ quote ->load ('test_order_1 ' , 'reserved_order_id ' );
101
106
$ cartId = $ quote ->getId ();
102
107
103
- /** @var \Magento\Quote\Model\ QuoteIdMask $quoteIdMask */
104
- $ quoteIdMask = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
105
- ->create (\ Magento \ Quote \ Model \ QuoteIdMaskFactory::class)
108
+ /** @var QuoteIdMask $quoteIdMask */
109
+ $ quoteIdMask = Bootstrap::getObjectManager ()
110
+ ->create (QuoteIdMaskFactory::class)
106
111
->create ();
107
112
$ quoteIdMask ->load ($ cartId , 'quote_id ' );
108
113
//Use masked cart Id
@@ -141,20 +146,20 @@ public function testAddItem()
141
146
*/
142
147
public function testRemoveItem ()
143
148
{
144
- /** @var \Magento\ Quote\Model\Quote $quote */
145
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
149
+ /** @var Quote $quote */
150
+ $ quote = $ this ->objectManager ->create (Quote::class);
146
151
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
147
152
$ cartId = $ quote ->getId ();
148
153
149
- /** @var \Magento\Quote\Model\ QuoteIdMask $quoteIdMask */
150
- $ quoteIdMask = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
151
- ->create (\ Magento \ Quote \ Model \ QuoteIdMaskFactory::class)
154
+ /** @var QuoteIdMask $quoteIdMask */
155
+ $ quoteIdMask = Bootstrap::getObjectManager ()
156
+ ->create (QuoteIdMaskFactory::class)
152
157
->create ();
153
158
$ quoteIdMask ->load ($ cartId , 'quote_id ' );
154
159
//Use masked cart Id
155
160
$ cartId = $ quoteIdMask ->getMaskedId ();
156
161
157
- $ product = $ this ->objectManager ->create (\ Magento \ Catalog \ Model \ Product::class);
162
+ $ product = $ this ->objectManager ->create (Product::class);
158
163
$ productId = $ product ->getIdBySku ('simple_one ' );
159
164
$ product ->load ($ productId );
160
165
$ itemId = $ quote ->getItemByProduct ($ product )->getId ();
@@ -175,7 +180,7 @@ public function testRemoveItem()
175
180
"itemId " => $ itemId ,
176
181
];
177
182
$ this ->assertTrue ($ this ->_webApiCall ($ serviceInfo , $ requestData ));
178
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
183
+ $ quote = $ this ->objectManager ->create (Quote::class);
179
184
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
180
185
$ this ->assertFalse ($ quote ->hasProductId ($ productId ));
181
186
}
@@ -189,20 +194,20 @@ public function testRemoveItem()
189
194
public function testUpdateItem (array $ stockData , string $ errorMessage = null )
190
195
{
191
196
$ this ->updateStockData ('simple_one ' , $ stockData );
192
- /** @var \Magento\ Quote\Model\Quote $quote */
193
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
197
+ /** @var Quote $quote */
198
+ $ quote = $ this ->objectManager ->create (Quote::class);
194
199
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
195
200
$ cartId = $ quote ->getId ();
196
201
197
- /** @var \Magento\Quote\Model\ QuoteIdMask $quoteIdMask */
198
- $ quoteIdMask = \ Magento \ TestFramework \ Helper \ Bootstrap::getObjectManager ()
199
- ->create (\ Magento \ Quote \ Model \ QuoteIdMaskFactory::class)
202
+ /** @var QuoteIdMask $quoteIdMask */
203
+ $ quoteIdMask = Bootstrap::getObjectManager ()
204
+ ->create (QuoteIdMaskFactory::class)
200
205
->create ();
201
206
$ quoteIdMask ->load ($ cartId , 'quote_id ' );
202
207
//Use masked cart Id
203
208
$ cartId = $ quoteIdMask ->getMaskedId ();
204
209
205
- $ product = $ this ->objectManager ->create (\ Magento \ Catalog \ Model \ Product::class);
210
+ $ product = $ this ->objectManager ->create (Product::class);
206
211
$ productId = $ product ->getIdBySku ('simple_one ' );
207
212
$ product ->load ($ productId );
208
213
$ itemId = $ quote ->getItemByProduct ($ product )->getId ();
@@ -229,14 +234,70 @@ public function testUpdateItem(array $stockData, string $errorMessage = null)
229
234
$ this ->expectExceptionMessage ($ errorMessage );
230
235
}
231
236
$ this ->_webApiCall ($ serviceInfo , $ requestData );
232
- $ quote = $ this ->objectManager ->create (\ Magento \ Quote \ Model \ Quote::class);
237
+ $ quote = $ this ->objectManager ->create (Quote::class);
233
238
$ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
234
239
$ this ->assertTrue ($ quote ->hasProductId (1 ));
235
240
$ item = $ quote ->getItemByProduct ($ product );
236
241
$ this ->assertEquals (5 , $ item ->getQty ());
237
242
$ this ->assertEquals ($ itemId , $ item ->getItemId ());
238
243
}
239
244
245
+ /**
246
+ * Verifies that store id for quote and quote item is being changed accordingly to the requested store code
247
+ *
248
+ * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php
249
+ * @magentoApiDataFixture Magento/Store/_files/second_store.php
250
+ */
251
+ public function testUpdateItemWithChangingStoreId ()
252
+ {
253
+ /** @var Quote $quote */
254
+ $ quote = $ this ->objectManager ->create (Quote::class);
255
+ $ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
256
+ $ cartId = $ quote ->getId ();
257
+
258
+ /** @var QuoteIdMask $quoteIdMask */
259
+ $ quoteIdMask = Bootstrap::getObjectManager ()
260
+ ->create (QuoteIdMaskFactory::class)
261
+ ->create ();
262
+ $ quoteIdMask ->load ($ cartId , 'quote_id ' );
263
+ $ cartId = $ quoteIdMask ->getMaskedId ();
264
+
265
+ $ product = $ this ->objectManager ->create (Product::class);
266
+ $ productId = $ product ->getIdBySku ('simple ' );
267
+ $ product ->load ($ productId );
268
+ $ itemId = $ quote ->getItemByProduct ($ product )->getId ();
269
+ $ serviceInfo = [
270
+ 'rest ' => [
271
+ 'resourcePath ' => self ::RESOURCE_PATH . $ cartId . '/items/ ' . $ itemId ,
272
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_PUT ,
273
+ ],
274
+ 'soap ' => [
275
+ 'service ' => self ::SERVICE_NAME ,
276
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
277
+ 'operation ' => self ::SERVICE_NAME . 'Save ' ,
278
+ ],
279
+ ];
280
+
281
+ $ requestData ['cartItem ' ]['qty ' ] = 5 ;
282
+ if (TESTS_WEB_API_ADAPTER === self ::ADAPTER_SOAP ) {
283
+ $ requestData ['cartItem ' ] += [
284
+ 'quote_id ' => $ cartId ,
285
+ 'itemId ' => $ itemId ,
286
+ ];
287
+ }
288
+ $ this ->_webApiCall ($ serviceInfo , $ requestData , null , 'fixture_second_store ' );
289
+ $ quote = $ this ->objectManager ->create (Quote::class);
290
+ $ quote ->load ('test_order_item_with_items ' , 'reserved_order_id ' );
291
+ $ this ->assertTrue ($ quote ->hasProductId (1 ));
292
+ $ item = $ quote ->getItemByProduct ($ product );
293
+ /** @var StoreManagerInterface $storeManager */
294
+ $ storeManager = $ this ->objectManager ->get (StoreManagerInterface::class);
295
+ $ storeId = $ storeManager ->getStore ('fixture_second_store ' )
296
+ ->getId ();
297
+ $ this ->assertEquals ($ storeId , $ quote ->getStoreId ());
298
+ $ this ->assertEquals ($ storeId , $ item ->getStoreId ());
299
+ }
300
+
240
301
/**
241
302
* @return array
242
303
*/
0 commit comments