0

Due to some shoddy code from a previous employee I have inherited a Magento 2 store with thousands of erroneous product attributes and hundreds of attribute sets.

I've been able to delete the attributes and move all the products back on to the Default attribute set, but now I'm left with hundreds of empty, unused product attribute sets that I can't find how to delete easily?

2
  • 1
    Via terminal you can run this command catalog:product:attributes:cleanup for removes unused product attributes. Commented Sep 28, 2018 at 5:02
  • Hint: that only cleans up values from the entity tables. It doesn not delete attributesets or attributes. The following tables are cleaned up: catalog_product_entity_varchar catalog_product_entity_text catalog_product_entity_decimal catalog_product_entity_datetime catalog_product_entity_int Commented Feb 12, 2021 at 10:20

1 Answer 1

1

You can remove an attribute set using Magento\Catalog\Api\AttributeSetRepositoryInterface method deleteById

namespace {NameSpace};


class Test
{
    /**
     * @var \Magento\Catalog\Api\AttributeSetRepositoryInterface
     */
    protected $attributeSetRepository;

    public function __construct(
        \Magento\Catalog\Api\AttributeSetRepositoryInterface $attributeSetRepository
    )
    {
        $this->a

ttributeSetRepository = $attributeSetRepository;
        }
        public function deleteAttributeSet()
        {
            $attributeSetId = 15;
            $this->attributeSetRepository->deleteById($attributeSetId);
        }
    }

Via Object manager:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $attributeSetRepository = $objectManager->create('\Magento\Catalog\Api\AttributeSetRepositoryInterface');
        $attributeSetRepository->deleteById($attributeSetId);
1
  • "The default attribute set can't be deleted" error is displayed Commented Jan 3, 2020 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.