Question

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.

Was it helpful?

Solution

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

Advanced ORM - Part 7
Installing custom attributes with your module

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top