I have a magento site in which there are simple products having language videos attributes.
Currently there are two language video sections being maintained, each section containing six different videos & their thumbs.
Now I want to add three more sections of same number of video attributes, resulting into 18 attributes to be newly created.
So my question is, how can I clone all those attributes(video attributes which are textfields & thumb attributes which are WYSIWYG editors) by script, without doing the tedious task of manually creating each attribute ?
1 Answer 1
I haven't tested this, but I think it should work.
$attributeIdToClone = 'attribute_id_to_clone';
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeIdToClone);
if ($attribute->getId()) {
$attribute->setAttributeCode('new_attribute_code_here');
$attribute->setLabel('New label here');
$attribute->setId(null);
$attribute->save();
}
if you need to clone multiple times, just use this in a for
(foreach
/ while
) loop.
please backup your db before trying this.
-
Tks Marius, the code does insert the attribute, but it somehow fails to set it's label in admin, so can you update your answer for that, also please include the line for assigning the attribute to particular attribute set by Id.H.D.– H.D.2015年09月23日 12:40:57 +00:00Commented Sep 23, 2015 at 12:40
-
@H.D. I have no idea why it does not set the label. As I said, I didn't test the code. Also I don't know how you can assign the attribute to a group. I will test it and come back if I get a better result.Marius– Marius2015年09月23日 13:24:34 +00:00Commented Sep 23, 2015 at 13:24
-
Sure, no problem, I am also trying to find this. Thanks for your help.H.D.– H.D.2015年09月24日 04:20:00 +00:00Commented Sep 24, 2015 at 4:20
Explore related questions
See similar questions with these tags.