我在 Magento 中为产品创建了一个自定义 Yes/No 属性,在升级文件中使用此代码:
$model = Mage::getModel('catalog/resource_eav_attribute');
$attributeData = array(
'attribute_code' => 'custom_attribute',
'frontend_label' => 'My custom attribute',
'is_global' => '1',
'frontend_input' => 'boolean',
'backend_type' => 'int',
'default_value' => null,
'is_unique' => '0',
'is_required' => '0',
'is_configurable' => '1',
'is_searchable' => '1',
'is_visible_in_advanced_search' => '1',
'is_comparable' => '1',
'is_used_for_price_rules' => '0',
'is_wysiwyg_enabled' => '1',
'is_html_allowed_on_front' => '1',
'is_visible_on_front' => '1',
'used_in_product_listing' => '1',
'used_for_sort_by' => '1',
'is_filterable_in_search' => 1,
'is_filterable' => 1,
'source_model' => null,
'option' => array(),
'apply_to' => 'simple,configurable,bundle,grouped',
'is_user_defined' => true,
'global' => true,
);
$model->addData($attributeData);
$model->setEntityTypeId(
Mage::getModel('eav/entity')->setType(Mage_Catalog_Model_Product::ENTITY)->getTypeId()
);
$model->save();
该代码有效。但是我希望在创建新产品或尝试编辑产品时默认选择是选项。现在,只有 No 首先显示。我尝试将 defult_value 更改为 true 或 1,但它不起作用。