Magento 1.8:添加新产品属性非前端参数设置为是

时间:2014-01-24 12:33:31

标签: magento magento-1.8

这是我用来添加新产品属性并将前端设置设置为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。

此致

1 个答案:

答案 0 :(得分: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,
    ));
...