0

这是我用来添加新产品属性并将前端设置设置为yes的代码:

<?php

$installer = Mage::getResourceModel('catalog/setup','catalog_setup');
$installer->startSetup();

$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, $specCode, array(
        'group' => $profileGroupName,
        'sort_order' => 1,
        'type' => 'varchar',
        'backend' => '',
        'frontend' => '',
        'label' => $specLabel,
        'note' => $specNote,
        'input' => 'text',
        'class' => '',
        'source' => '',
        'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'required' => true,
        'user_defined' => true,
        'default' => '',
        'unique' => false,
        'used_for_promo_rules' => true,
        'searchable'        => true,
        'filterable'        => true,
        'comparable'        => true,
        'visible'      => true,
        'visible_on_front'   => true,
        'visible_in_advanced_search'   => true,
        'is_configurable'   => false
    ));
...

几乎所有的前端设置都设置为 true,但在后端安装它们后,我可以看到此设置设置为 no。

问候,

4

1 回答 1

0

固定的。在下面工作的代码。只需在这两个类 Mage_Eav_Model_Entity_Setup、Mage_Catalog_Model_Resource_Setup 中保留此方法 _prepareValues 的 $attr 数组键名即可。第二类继承自第一类,因此如果您想添加前端设置,您的安装程序需要是第二类的对象。

$installer = new Mage_Catalog_Model_Resource_Setup();
$installer->startSetup();

$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, $tradeCode, array(
        'group' => $profileGroupName,
        'sort_order' => 1,
        'type' => 'varchar',
        'input' => 'text',
        'label' => $tradeLabel,
        'note' => $tradeNote,
        'required' => 1,
        'unique' => 0,
        'user_defined' => 1,
        'default' => '',
        # Additional attribute data - forntend
        'frontend_input_renderer' => '',
        'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'visible' => 1,
        'searchable' => 1,
        'filterable' => 1,
        'comparable' => 1,
        'visible_on_front' => 1,
        'wysiwyg_enabled' => 0,
        'is_html_allowed_on_front' => 0,
        'visible_in_advanced_search' => 1,
        'filterable_in_search' => 1,
        'used_in_product_listing' => 1,
        'used_for_sort_by' => 1,
        'apply_to' => '',
        'position' => '',
        'is_configurable' => 0,
        'used_for_promo_rules' => 0,
    ));
...
于 2014-01-24T13:44:49.290 回答