Get all attributes under default attributes set with their groups in Magento
-
12-12-2019 - |
Question
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!.
Solution
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);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange