0

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 ?

Marius
199k55 gold badges431 silver badges837 bronze badges
asked Sep 23, 2015 at 12:04

1 Answer 1

0

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.

answered Sep 23, 2015 at 12:09
3
  • 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. Commented 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. Commented Sep 23, 2015 at 13:24
  • Sure, no problem, I am also trying to find this. Thanks for your help. Commented Sep 24, 2015 at 4:20

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.