【问题标题】:magento: add attibute to product, but not show up when editing the productmagento:为产品添加属性,但在编辑产品时不显示
【发布时间】:2011-11-30 20:50:12
【问题描述】:

根据 bens 的评论和回答我更新了我的脚本,cmets 表示更改

{Magento 1.4.0.1} 目前我有一个安装程序脚本:

$installer = $this;
$installer->startSetup();

//commented out to use factory method
//$setup = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
$setup = Mage::getResourceModel('catalog/setup','core_setup');    

if(!$setup->getAttribute('catalog_product','attribute_code')){
    $newFields = array(
        'attribute_code' => array(
            'type'              => 'text',
            'label'             => 'Attribute Label',
            //added visible option
            'visible'           => false,
        ),
    );

    $entities = array(
        'catalog_product',
    );

    foreach($newFields as $attributeName => $attributeDefs) {
        foreach ($entities as $entity) {
            $setup->addAttribute($entity, $attributeName, array(
                'type'                          => $attributeDefs['type'],
                'label'                         => $attributeDefs['label'],
                //added visible option
                'visible'                       => $attributeDefs['visible'],
                'class'                         => '',
                'required'                      => false,
            ));
        }
    }
}

$installer->endSetup();

效果很好!除了在编辑产品时属性显示在常规属性组中并且我根本不希望它显示(它是一个秘密的忍者属性)之外,我做错了什么吗?或者我应该做些什么来让 Magento 不知道它不应该出现?

【问题讨论】:

  • 您的代码应该使用工厂方法,即 $setup = Mage::getResourceModel('catalog/setup','default_setup');
  • 注意到...现在关于我的问题? .......

标签: magento attributes magento-1.4 product


【解决方案1】:

使用addAttribute(),您可以设置'visibleindex tofalse. UsingupdateAttribute()`,您应该执行以下操作:

$setup->updateAttribute('catalog_product','attr_code','is_visible',false);

如果我错了,请告诉我。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-26
  • 1970-01-01
  • 1970-01-01
  • 2015-01-07
相关资源
最近更新 更多