根据bens评论和回答,我更新了我的脚本,评论表明了更改
{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();
效果非常好!除了在编辑产品时在General属性组中显示的属性,我不想让它显示(它是一个秘密的忍者属性)是否有一些我做错了?或许我应该采取一些措施让Magento知道它不应该出现?
答案 0 :(得分:0)
使用addAttribute()
您可以设置'visible index to
false . Using
updateAttribute()`您应该执行以下操作:
$setup->updateAttribute('catalog_product','attr_code','is_visible',false);
如果我错了,请告诉我。