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