Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_advanced_rollback.php
Go to the documentation of this file.
1 <?php
7 $prices = [5, 10, 15, 20, 50, 100, 150];
8 
11 
12 $registry->unregister('isSecureArea');
13 $registry->register('isSecureArea', true);
14 
17  \Magento\Catalog\Api\ProductRepositoryInterface::class
18 );
19 
22 foreach ($prices as $price) {
25  \Magento\Catalog\Model\Product::class
26  );
28  try {
29  $product = $productRepository->get('simple-' . $productId, false, null, true);
31  } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
32  //Product already removed
33  }
34 
36 }
37 
40  ->create(\Magento\Catalog\Model\ResourceModel\Category\Collection::class);
42  ->addAttributeToFilter('level', 2)
43  ->load()
44  ->delete();
45 
46 $registry->unregister('isSecureArea');
47 $registry->register('isSecureArea', false);
$price