@@ -295,6 +295,57 @@ public function testSaveStockItemQty()
295
295
unset($ stockItems , $ stockItem );
296
296
}
297
297
298
+ /**
299
+ * Test that is_in_stock set to 0 when item quantity is 0
300
+ *
301
+ * @magentoDataFixture Magento/Catalog/_files/multiple_products.php
302
+ * @magentoAppIsolation enabled
303
+ */
304
+ public function testSaveIsInStockByZeroQty ()
305
+ {
306
+ /** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
307
+ $ productRepository = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
308
+ \Magento \Catalog \Api \ProductRepositoryInterface::class
309
+ );
310
+ $ id1 = $ productRepository ->get ('simple1 ' )->getId ();
311
+ $ id2 = $ productRepository ->get ('simple2 ' )->getId ();
312
+ $ id3 = $ productRepository ->get ('simple3 ' )->getId ();
313
+ $ existingProductIds = [$ id1 , $ id2 , $ id3 ];
314
+
315
+ $ filesystem = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()
316
+ ->create (\Magento \Framework \Filesystem::class);
317
+ $ directory = $ filesystem ->getDirectoryWrite (DirectoryList::ROOT );
318
+ $ source = $ this ->objectManager ->create (
319
+ \Magento \ImportExport \Model \Import \Source \Csv::class,
320
+ [
321
+ 'file ' => __DIR__ . '/_files/products_to_import_zero_qty.csv ' ,
322
+ 'directory ' => $ directory
323
+ ]
324
+ );
325
+ $ errors = $ this ->_model ->setParameters (
326
+ ['behavior ' => \Magento \ImportExport \Model \Import::BEHAVIOR_APPEND , 'entity ' => 'catalog_product ' ]
327
+ )->setSource (
328
+ $ source
329
+ )->validateData ();
330
+
331
+ $ this ->assertTrue ($ errors ->getErrorsCount () == 0 );
332
+
333
+ $ this ->_model ->importData ();
334
+
335
+ /** @var $stockItmBeforeImport \Magento\CatalogInventory\Model\Stock\Item */
336
+ foreach ($ existingProductIds as $ productId ) {
337
+ /** @var $stockRegistry StockRegistry */
338
+ $ stockRegistry = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->create (
339
+ StockRegistry::class
340
+ );
341
+
342
+ $ stockItemAfterImport = $ stockRegistry ->getStockItem ($ productId , 1 );
343
+
344
+ $ this ->assertEquals (0 , $ stockItemAfterImport ->getIsInStock ());
345
+ unset($ stockItemAfterImport );
346
+ }
347
+ }
348
+
298
349
/**
299
350
* Test if stock state properly changed after import
300
351
*
0 commit comments