在Magento中复制属性

时间:2010-11-26 15:28:27

标签: attributes magento magento-1.4

Magento v1.4以编程方式复制(产品)属性的正确方法是什么?我对Magento很新,并尝试了解一些事情:)

到目前为止,我已经提出了以下内容,

$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();

但属性似乎作为两个主要表eav_attributecatalog_eav_attribute之间的关系存在。当我执行代码时,只创建catalog_eav_attribute的条目,导致eav_attribute的外键错误(其中新记录尚不存在)。希望有人可以提供帮助。

2 个答案:

答案 0 :(得分:1)

以下是有关创建属性的典型方法的一些资源。

Advanced ORM - Part 7
Installing custom attributes with your module

答案 1 :(得分:0)

上次评论中的链接无效,但我认为需要:

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