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