Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
set_simples_out_of_stock.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
13 
15 $sourceItemRepository = Bootstrap::getObjectManager()->create(SourceItemRepositoryInterface::class);
16 
18 $getSourceItemsBySku = Bootstrap::getObjectManager()->create(GetSourceItemsBySkuInterface::class);
19 
21 $sourceItemSave = Bootstrap::getObjectManager()->create(SourceItemsSave::class);
22 
23 $skuList = ['simple_11', 'simple_21', 'simple_31'];
24 foreach ($skuList as $sku) {
25  $sourceItems = $getSourceItemsBySku->execute($sku);
26  $changesSourceItems = [];
27  foreach ($sourceItems as $sourceItem) {
28  $sourceItem->setStatus(SourceItemInterface::STATUS_OUT_OF_STOCK);
29  $changesSourceItems[] = $sourceItem;
30  }
31  $sourceItemSave->execute($changesSourceItems);
32 }
$sourceItems