Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get attributes by attribute group Magento

Tags:

magento

I have product:

<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>

I have name (not ID) of attribute group.

I need to list all attributes names and values in this attribute group (does not matter on attribute set).

How can i get attributes and values from attribute group, if i know only product and a attribute group name?

like image 963
Martin Avatar asked Feb 09 '26 18:02

Martin


1 Answers

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

        $attributeCodes = array();
        foreach ($groups as $group) {
            if($group->getAttributeGroupName() == 'Somename'){ // set name
            //$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);
like image 195
Martin Avatar answered Feb 13 '26 18:02

Martin