Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_with_layered_navigation_attribute_rollback.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
11 
12 $registry->unregister('isSecureArea');
13 $registry->register('isSecureArea', true);
14 
16 $productRepository = $objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
17 
18 foreach (['simple1', 'simple2', 'simple3'] as $sku) {
19  try {
20  $product = $productRepository->get($sku, false, null, true);
22  } catch (\Magento\Framework\Exception\NoSuchEntityException $exception) {
23  //Product already removed
24  }
25 }
26 
28  ->get(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
29 foreach ($productCollection as $product) {
30  $product->delete();
31 }
32 
35 $category->load(333);
36 if ($category->getId()) {
37  $category->delete();
38 }
39 
41 $attribute = $eavConfig->getAttribute('catalog_product', 'test_configurable');
42 if ($attribute instanceof \Magento\Eav\Model\Entity\Attribute\AbstractAttribute
43  && $attribute->getId()
44 ) {
45  $attribute->delete();
46 }
47 $eavConfig->clear();
48 
49 
50 $registry->unregister('isSecureArea');
51 $registry->register('isSecureArea', false);
foreach(['simple1', 'simple2', 'simple3'] as $sku) $productCollection