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!.

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? – Abdus Salam Jan 26 '16 at 6:09

Your Answer

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