Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_with_layered_navigation_swatch_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 
42  ->create(\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class);
43 
44 $attribute->loadByCode(4, 'color_swatch');
45 
46 if ($attribute->getId()) {
47  $attribute->delete();
48 }
49 
50 $registry->unregister('isSecureArea');
51 $registry->register('isSecureArea', false);
foreach(['simple1', 'simple2', 'simple3'] as $sku) $productCollection