I would like to "prune" my attribute sets. That is - I would like to delete all attribute sets that have been setup, but that do not have any products in that attribute set.

Is there a way - some script that has been developed that will identify unused attribute sets? That is no products in the database that use those attribute sets?

Please advise.

  • can you share your script?
    – Abdul
    Nov 16, 2015 at 4:34

1 Answer 1


Try below script

        $entityType = Mage::getModel('catalog/product')->getResource()->getEntityType();
        $collection = Mage::getResourceModel('eav/entity_attribute_set_collection')

        foreach ($collection as $attributeSet) {
            if($attributeSetId = $attributeSet->getId()) {

                /** @var $catalogProductsCollection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */
                $catalogProductsCollection = Mage::getModel('catalog/product')->getCollection()
                            ->addFieldToFilter('attribute_set_id', $attributeSetId);
                if (count($catalogProductsCollection) == 0 ) {
                    $attributeSet = Mage::getModel('eav/entity_attribute_set')->load($attributeSetId);
                    try {
                    } catch (Exception $e) {
                        echo $e->getMessage();

Note : first backup your database after run script

  • How i can used this code in magento 2 Dec 18, 2019 at 5:08

Your Answer

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

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