Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
categories_with_products_rollback.php
Go to the documentation of this file.
1 <?php
8 $registry->unregister('isSecureArea');
9 $registry->register('isSecureArea', true);
10 
13  ->create(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
14 
15 $productCollection->load()->delete();
16 
17 $productSkuList = ['simple', '12345'];
18 foreach ($productSkuList as $sku) {
19  try {
21  ->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
22  $product = $productRepository->get($sku, true);
23  if ($product->getId()) {
25  }
26  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
27  //Product already removed
28  }
29 }
30 
31 $registry->unregister('isSecureArea');
32 $registry->register('isSecureArea', false);
33 
34 require __DIR__ . '/categories_rollback.php';
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60