1

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

enter link description here

asked Jan 19, 2015 at 20:58

2 Answers 2

1

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
);
answered Jan 19, 2015 at 22:50
2
  • 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/XJ5Qth Commented Jan 20, 2015 at 11:58
  • Hehe, you got it ;) Commented Jan 20, 2015 at 12:11
0

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.

answered Jan 19, 2015 at 23:55

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.