0

just one simple but head-scratching question.

I create a attribute, set it to Drop-Down behavior (in Admin-Store, to be seen as a Drop-Down Attribute) it is creating quiet smooth, but didn't set the attribute_set.

In short:

is-state: my attribute --> not linked to a attribute set

to-state: my attribute --> linked to default attribute set

2
  • Is that question on programming ? Commented Dec 19, 2011 at 15:36
  • Yeah, i forget to say that it should been done under php (via Magento-API). I create an attribute via php but it isn't set to some attribute_set automatically and it would be great if someone knows what exactly needed to "set" it to the default attributset Commented Dec 19, 2011 at 15:55

1 Answer 1

4

Administration Way:

It is natural that a newly created attribute is not assigned to an attribute set (including the Default attribute set) automatically. You need to do it manually.

In the Admin, under Catalog > Attributes > Manage Attribute Sets.

source

Programming Way:

Try this code:

$installer = Mage::getModel('eav/entity_setup');
$installer->addAttributeToSet($entityTypeId, $setId, $groupId, $attributeId, $sortOrder);

The specifications for function addAttributeToSet:

  • mixed $entityTypeId
  • mixed $setId
  • mixed $groupId
  • mixed $attributeId
  • int $sortOrder=null
  • @return Mage_Eav_Model_Entity_Setup

The arguments ending with 'Id' don't actually have to be ids according to the codes. Set and group names can be transalated to ids automatically. However for the attribute, you should use code (usually written in small letters, ex. 'firstname') rather than names (ex. 'First Name').

For example, you want to add a product attribute called 'popularity' to the 'Default' attribute set under 'General' group, just write like this:

$installer = Mage::getModel('eav/entity_setup');
$installer->addAttributeToSet('catalog_product', 'Default', 'General', 'popularity');

Unfortunately I don't have an installation to test the code for the moment, hopefully it should work :)

Sign up to request clarification or add additional context in comments.

8 Comments

thanks for the answer, i've already found something about it via Backend. I forget to say that it should been done under php (via Magento-API) I create an attribute via php but it isn't set to some attribute_set automatically and it would be great if someone knows what exactly needed to "set" it to the default attributset
i accept the answer, cause it helped me searching for the right terms, finding help to my question. Is there any chance to select the default attribute_set programmatically? just got the attribute_Set id and the Name of DefaultAttributeSet. Just need to tell the API that my attribute should be inside of this set. Thanks in Advantage
Thank you vicch, will try it now, i'll give response if this helps
I've got another question especially to the GroupID: does GroupId mean the Group a customer is set to or the Product? Edit: found it here --> stackoverflow.com/questions/3090527/…
No, the Group here means the attribute group. One attribute set contains several attribute groups, and each attribute group contains several attributes. When you click on an attribute set under Manage Attribute Sets, the Groups are listed in the middle column.
|

Your Answer

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.