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?

  • 1
    Via terminal you can run this command catalog:product:attributes:cleanup for removes unused product attributes. – Himanshu Sep 28 '18 at 5:02
0

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.