如何在magento中为产品属性添加新字段


How to add new field to product attributes in magento?

我想在订购时向制造商发送电子邮件。为此,我想在制造商产品属性中添加制造商的电子邮件地址?如何做到这一点?

我假设您在问如何在代码中实现它?无论如何,只需使用安装脚本(遍布网络的教程)构建一个小模块,并使设置脚本看起来像这样:

$installer = $this;
$installer->startSetup();
// check if the attribute exists
if (Mage::getModel('catalog/resource_eav_attribute')->loadByCode('catalog_product','calculated_sold')->getId() !== NULL) {
    $installer->removeAttribute('catalog_product', 'calculated_sold');
}
// not anymore, that's for sure!
//   Note! For product attributes the XML set class needs to be "Mage_Catalog_Model_Resource_Setup"
//   instead of "Mage_Customer_Model_Entity_Setup" as you would usually go with.
$installer->addAttribute('catalog_product','calculated_sold', array (
    'type'                       => 'decimal',
    'label'                      => 'Calculated sold',
    'input'                      => 'price',          // for filtering to work only certain input types allowed
    'global'                     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'searchable'                 => true,
    'filterable'                 => true,
    'visible'                    => false,
    'required'                   => false,
    'visible_in_advanced_search' => true,
    'used_in_product_listing'    => true,
    'used_for_sort_by'           => true,
    'apply_to'                   => 'configurable',  // yeah!
));
$installer->endSetup();

这个例子添加了一个属性来跟踪售出的商品数量,但它会让你知道如何根据自己的需求进行更改。