Programmaticaly add attributes to attribute group

Posted Almost 2 years ago. Visible to the public.
/**
 * Add attributes to attibute_group 'CAUTION!!! System Config'.
 */
if ($attrs) {
    $resource = Mage::getResourceSingleton('eav/entity_attribute');
    foreach ($customerGroupIds as $groupCode => $groupId) {
        /** @var Scx_ExtendedCustomer_Model_Attribute_Set $set */
        $set = Mage::getModel('extendedcustomer/attribute_set');
        $set->load($groupId, 'apply_to');
        if (!$set->getId()) {
            continue;
        }
        $agId = Mage::getResourceModel('eav/entity_attribute_group_collection')
            ->addFieldToFilter('attribute_group_name', 'CAUTION!!! System Config')
            ->addFieldToFilter('attribute_set_id', $set->getId())
            ->getFirstItem()
            ->getId();
        if (!$agId) {
            $agId = Mage::getModel('eav/entity_attribute_group')
                ->setAttributeGroupName('CAUTION!!! System Config')
                ->setAttributeSetId($set->getId())
                ->save()
                ->getId();
        }
        foreach ($attrs as $attr) {
            $attr->setAttributeSetId($set->getId())
                ->setAttributeGroupId($agId);
            $resource->saveInSetIncluding($attr);
        }
    }
}

kiatng
Last edit
Almost 2 years ago
kiatng
Posted by kiatng to OpenMage (2022-08-10 10:16)