2

I want to fetch all attributes under default attribute set with their groups in magento. I used below code for fetching the attributes but how can i split with their Groups.

$attributes = Mage::getModel('catalog/product_attribute_api')->items('4');
foreach ($attributes as $_attribute)
{
    echo '<pre>' . print_r($_attribute);
}

Thanks in advance!.

1 Answer 1

3

Please use below code,

$setId = 10; // Attribute set Id
        $groups = Mage::getModel('eav/entity_attribute_group')
            ->getResourceCollection()
            ->setAttributeSetFilter($setId)
            ->setSortOrder()
            ->load();

        $attributeCodes = array();
        foreach ($groups as $group) {
            $groupName          = $group->getAttributeGroupName();
            $groupId            = $group->getAttributeGroupId();

            $attributes = Mage::getResourceModel('catalog/product_attribute_collection')
                ->setAttributeGroupFilter($group->getId())
                ->addVisibleFilter()
                ->checkConfigurableProducts()
                ->load();
                if ($attributes->getSize() > 0) {
                    foreach ($attributes->getItems() as $attribute) {
                        /* @var $child Mage_Eav_Model_Entity_Attribute */
                        $attributeCodes[] = $attribute->getAttributeCode();                     
                    }
                } 

        }
        print_r($attributeCodes);
1
  • What I do for configurable product? Commented Jan 26, 2016 at 6:09

Your Answer

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