Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
categories_rollback.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
11 $registry = $objectManager->get(\Magento\Framework\Registry::class);
12 
13 $registry->unregister('isSecureArea');
14 $registry->register('isSecureArea', true);
15 
16 //Remove categories
18 $collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Category\Collection::class);
19 $collection->addAttributeToFilter('level', ['gt' => 1]);
20 
21 foreach ($collection as $category) {
23  if ($category->getLevel() !== 1) {
24  $category->delete();
25  }
26 }
27 
28 $registry->unregister('isSecureArea');
29 $registry->register('isSecureArea', false);
$objectManager