Can anybody tell me how I can add multiple attributes in 1 install file of a custom module? In this case I also want to add them to the tab attributes but it doesn't work.
Just a beginner so I hope somebody can help me
2 Answers 2
Method getAttributeId accepts two parameters:
public function getAttributeId($entityTypeId, $id)
{
if (!is_numeric($id)) {
$id = $this->getAttribute($entityTypeId, $id, 'attribute_id');
}
if (!is_numeric($id)) {
return false;
}
return $id;
}
And in your code you have three:
$attributeId = $installer->getAttributeId(
'catalog_product',
'test1'
'test2'
);
You just have to repeat getAttributeId and addAttributeToSet for each attribute.
EDIT:
$attributeId = $installer->getAttributeId(
'catalog_product',
'affiliate_link2'
);
$installer->addAttributeToSet(
'catalog_product',
$defaultSetId,
$groupId,
$attributeId
);
$attributeId = $installer->getAttributeId(
'catalog_product',
'affiliate_link3'
);
$installer->addAttributeToSet(
'catalog_product',
$defaultSetId,
$groupId,
$attributeId
);
-
Thanks for the details, I am trying it but doesn't work yet. Not sure what to do with the addAttributeToSet. In this code only the affiliate_link3 is added to the new tab Affiliate ideone.com/XJ5QthSander van Zuidam– Sander van Zuidam2015年01月20日 11:58:52 +00:00Commented Jan 20, 2015 at 11:58
-
Hehe, you got it ;)Lord Skeletor– Lord Skeletor2015年01月20日 12:11:39 +00:00Commented Jan 20, 2015 at 12:11
The actual syntax error is because you have a missing comma between your parameters. e.g:
$attributeId = $installer->getAttributeId(
'catalog_product',
'test1'
'test2'
)
should be
$attributeId = $installer->getAttributeId(
'catalog_product',
'test1',
'test2'
)
but as Reindex 'Em All has said, this function only accepts 2 paramaters so it should be
$attributeId = $installer->getAttributeId(
'catalog_product',
'test1'
)
You can only get an attributeId for one product at a time.