Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
filterable_attribute_rollback.php
Go to the documentation of this file.
1 <?php
6 /* Create attribute */
9  \Magento\Catalog\Setup\CategorySetup::class,
10  ['resourceName' => 'catalog_setup']
11 );
14  \Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
15 );
16 $attribute->loadByCode(\Magento\Catalog\Model\Product::ENTITY, 'select_attribute');
17 
20  \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class
21 );
23 
24 $registry->unregister('isSecureArea');
25 $registry->register('isSecureArea', true);
26 
27 $selectOptions->setAttributeFilter($attribute->getId());
28 /* Delete simple products per each select(dropdown) option */
29 foreach ($selectOptions as $option) {
32  \Magento\Catalog\Model\Product::class
33  );
34  $product = $product->loadByAttribute('sku', 'simple_product_' . $option->getId());
35  if ($product->getId()) {
36  $product->delete();
37  }
38 }
39 if ($attribute->getId()) {
40  $attribute->delete();
41 }
42 
43 $attribute->loadByCode($installer->getEntityTypeId('catalog_product'), 'multiselect_attribute');
44 if ($attribute->getId()) {
45  $attribute->delete();
46 }
47 
48 $registry->unregister('isSecureArea');
49 $registry->register('isSecureArea', false);