Lucas Moeskops
Lucas Moeskops

Reputation: 5443

Duplicating attribute in Magento

What would be the proper way in Magento v1.4 to programmatically duplicate a (product) attribute? I'm fairly new to Magento and trying some things out to get to know it :)

I've so far come up with the following,

$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($id_of_attribute_to_copy);
$data = $attribute->getData();
$data['attribute_id'] = '';
$data['attribute_code'] = 'new_attribute_name';
$attribute->setData($data);
$attribute->save();

but attributes seem to exist as a relation between two main tables, eav_attribute and catalog_eav_attribute. When I execute the code, only an entry for catalog_eav_attribute is created resulting in a Foreign Key error for eav_attribute (in which a new record doesn't yet exist). Hope someone can help.

Upvotes: 1

Views: 2649

Answers (2)

Maksim Gerasimenko
Maksim Gerasimenko

Reputation: 53

Not works links from last comment but i think need:

$mainEavAttribute = [logic..]
$eavSetup->addAttribute(Product::ENTITY,'new_attribute',$mainEavAttribute);

Upvotes: 0

clockworkgeek
clockworkgeek

Reputation: 37700

Here are some resources on the typical way of creating attributes.

Advanced ORM - Part 7
Installing custom attributes with your module

Upvotes: 1

Related Questions