Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_related_multiple_rollback.php
Go to the documentation of this file.
1 <?php
9 
10 $registry->unregister('isSecureArea');
11 $registry->register('isSecureArea', true);
12 
13 $productSkuList = ['simple', 'simple_with_cross_two', 'simple_with_cross'];
14 foreach ($productSkuList as $sku) {
15  try {
17  ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
18  $product = $productRepository->get($sku, true);
19  if ($product->getId()) {
21  }
22  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
23  //Product already removed
24  }
25 }
26 
27 $registry->unregister('isSecureArea');
28 $registry->register('isSecureArea', false);