Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
enable_manage_stock_for_products.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
11 
12 $objectManager = Bootstrap::getObjectManager();
13 
15 $productRepository = $objectManager->get(ProductRepositoryInterface::class);
16 $stockItemRepository = $objectManager->get(StockItemRepositoryInterface::class);
17 
18 $skus = ['SKU-1', 'SKU-2', 'SKU-3'];
19 
20 foreach ($skus as $sku) {
21  $product = $productRepository->get($sku);
22 
23  $stockItem = $product->getExtensionAttributes()->getStockItem();
24  $stockItem->setUseConfigManageStock(false);
25  $stockItem->setManageStock(true);
26 
28 }