Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_grouped_with_simple_rollback.php
Go to the documentation of this file.
1 <?php
7 
9 $registry = $objectManager->get(\Magento\Framework\Registry::class);
10 
11 $registry->unregister('isSecureArea');
12 $registry->register('isSecureArea', true);
13 
16  ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
17 
18 $skuList = ['simple_11', 'simple_22', 'grouped'];
19 foreach ($skuList as $sku) {
20  try {
21  $product = $productRepository->get($sku, false, null, true);
22 
23  $stockStatus = $objectManager->create(\Magento\CatalogInventory\Model\Stock\Status::class);
24  $stockStatus->load($product->getEntityId(), 'product_id');
25  $stockStatus->delete();
26 
28  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
29  //Product already removed
30  }
31 }
32 
33 $registry->unregister('isSecureArea');
34 $registry->register('isSecureArea', false);