Reputation: 389
I created an attribute like so...
$installer = $this;
$installer->startSetup();
/* $installer Services_Issue_Model_Mysql4_Setup */
$installer->addAttribute('catalog_product', 'alice_id', array(
'backend' => '',
'frontend' => '',
'type' => 'text',
'visible' => true,
'label' => 'Alice Id',
'note' => 'Alice Id.',
'input' => 'text',
'unique' => true,
'source' => '',
'global' => true,
'visible' => true,
'required' => true,
'user_defined' => true,
'default' => '',
'visible_on_front' => true,
'apply_to' => 'simple,configurable,default',
'group' => 'Special Attributes',
'used_in_product_listing' => true,
'frontend_class' => '',
'class' => '',
'is_html_allowed_on_front' => true,
'searchable' => true
));
$installer->endSetup();
Now I need to move it to another group within the product information page. So I've tried this without any success.
$installer = $this;
$installer->startSetup();
/* $installer Services_Issue_Model_Mysql4_Setup */
$installer->updateAttribute('catalog_product', 'alice_id', 'note', 'Product SKU for Alice.com third-party cart & checkout.');
/* - move between groups not possible with updateAttribute - */
$installer->updateAttribute('catalog_product', 'alice_id', 'group', 'Additional Attributes');
$installer->endSetup();
Can anyone tell me how I can accomplish this?
Upvotes: 2
Views: 3528
Reputation: 48
If you know the name/code of your group, you can get it's group ID directly using getAttributeGroupID(). This example updates the group of attribute_code to be "Group Name" within the default attribute set.
// $installer->startSetup()
// ...
$eavSetup = new Mage_Eav_Model_Entity_Setup('core_setup');
$iDefaultAttrSetID = $eavSetup->getDefaultAttributeSetId('catalog_product');
$iAttributeID = $eavSetup->getAttributeId('catalog_product', 'attribute_code');
$iGroupID = $eavSetup->getAttributeGroupId('catalog_product', $iDefaultAttrSetID, 'Group Name');
$eavSetup->addAttributeToGroup('catalog_product', $iDefaultAttrSetID, $iGroupID, $iAttributeID);
Upvotes: 1
Reputation: 130
You can use the addAttributeToGroup($entityType, $attributeSetId, $attributeGroupId, $attributeId, $sortOrder)
method in Mage_Eav_Model_Entity_Setup
to move an attribute to a different group. First, you'll need to get the set ID and group ID.
// ... start setup
// get default set id
$setId = $installer->getDefaultAttributeSetId('catalog_product');
// get group id by name "Additional Attributes"
$attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_group_collection');
foreach ($attributeSetCollection->getData() as $attributeGroupIndex) {
foreach ($attributeGroupIndex as $key => $value) {
if ($key === "attribute_group_name" and $value === "Additional Attributes") {
$groupId = $attributeGroupIndex["attribute_group_id"];
break 2;
}
}
}
// move attribute 'alice_id' to group 'Additional Attributes'
if (isset($setId) and isset($groupId)) {
$installer->addAttributeToGroup('catalog_product', $setId, $groupId, 'alice_id', 1000);
}
// ... end setup
Upvotes: 4