Use class \Magento\CatalogInventory\Api\StockRegistryInterface
protected $_stockRegistry; public function __construct( ... \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry ){ $this->_stockRegistry = $stockRegistry; }
Load item by its sku, then update it status
$stockItem = $this->_stockRegistry->getStockItemBySku($sku); $stockItem->setIsInStock($value); $this->_stockRegistry->updateStockItemBySku($sku, $stockItem);