0

I hope somebody can help with this, i need a way of getting all the attributes from multiple groups and sets. I have accomplished getting the attributes from a single group.

public function getRoomDetails()
    {
        $cache = Mage::app()->getCache();


        $attributeSetId     = Mage::getModel('eav/entity_attribute_set')
            ->getCollection()
            ->addFieldToFilter('attribute_set_name', 'Room')
            ->getFirstItem()
            ->getAttributeSetId();

        $temp = $cache->load ('room-details-'.$attributeSetId);
        if($temp === false) {
            $eavcollection = Mage::getModel('eav/entity_attribute_group')->getCollection();
            $eavcollection->addFieldToFilter('attribute_set_id',array('eq'=>$attributeSetId));

            $propertydetails = $eavcollection
                ->addFieldToFilter('attribute_group_name', array('eq' => 'Features'))
                ->getFirstItem()->getId();
            $cache->save(serialize ($propertydetails),'room-details',array(),3600);
            return $propertydetails;
        }else
        {
            return unserialize ($temp);
        }
    }

But i need to get attributes from another group and another set.

2 Answers 2

1

I ended up moving the set of attributes into another group as a full set seemed redundant and just pulling the two groups from that set using the below.

$bills = Mage::getModel('eav/entity_attribute_group')->getCollection()
            ->addFieldToFilter('attribute_group_name', array('eq' => 'Bills Includes'))
            ->getFirstItem()->getId();

        $propertydetails = Mage::getModel('eav/entity_attribute_group')->getCollection()
            ->addFieldToFilter('attribute_group_name', array('eq' => 'Property Details'))
            ->getFirstItem()->getId();

        $attributesCollection = Mage::getResourceModel('catalog/product_attribute_collection');
        $attributesCollection->setAttributeGroupFilter(array($bills,$propertydetails));
        return $attributesCollection;
0

Getting attribute set ids and using these (left the caching behind to leave that complexity)

$attributeSetCollection = Mage::getModel('eav/entity_attribute_set')
        ->getCollection();

$select = $attributeSetCollection->getSelect();

$select->where('attribute_set_name = ?', 'Get A')
        ->orWhere('attribute_set_name = ?', 'Room')
//        ->orWhere('attribute_set_name = ?', 'And Have')
//        ->orWhere('attribute_set_name = ?', 'Fun')
        ->reset(Zend_Db_Select::COLUMN)
        ->columns('attribute_set_id');

$attributeSetIds = $attributeSetCollection->getConnection()->fetchAll($select);


$attributeCollection = Mage::getModel('eav/entity_group')->getCollection();

$attributeCollection->addFieldToFilter('attribute_set_id', array('in' => $attributeSetIds))
        ->addFieldToFilter('attribute_group_name', array('eq' => 'Features'));

$attributeSetIds = $attributeCollection->getAllIds();

var_dump($attributeSetIds); // Here the are

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.