问题描述
对于允许自定义价格,只有是/否,但是我也想添加使用配置"选项,例如应用地图"选择我该怎么做?
for allow custom price there is just Yes/No but i wanna add "use config" option too like Apply Map select how can i do that ?
这是属性:
$setup->addAttribute('catalog_product', 'allow_customprice', array(
'group' => 'Prices',
'input' => 'select',
'label' => 'Allow Custom Price',
'source' => 'eav/entity_attribute_source_boolean',
'backend' => '',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 1,
'filterable' => 0,
'default' => 1,
'comparable' => 1,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));
多数民众赞成在system.xml:
thats the system.xml :
<fields>
<enablecp translate="label">
<label>Enable Custom Price</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<comment>Option for all products.</comment>
<sort_order>20</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enablecp>
<!-- END FIELD -->
<minprice translate="label">
<label>Min Price</label>
<frontend_type>text</frontend_type>
<validate>validate-number</validate>
<comment>Min price for all products.</comment>
<sort_order>60</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</minprice>
<!-- END FIELD -->
</fields>
就这样,谢谢前进
推荐答案
在属性配置中,将源模型设置为eav/entity_attribute_source_boolean
.此类包含以下填充选项数据的方法:
In your attribute configuration you set the source model to eav/entity_attribute_source_boolean
. This class contains the following method which fills the option data:
public function getAllOptions()
{
if (is_null($this->_options)) {
$this->_options = array(
array(
'label' => Mage::helper('eav')->__('Yes'),
'value' => self::VALUE_YES
),
array(
'label' => Mage::helper('eav')->__('No'),
'value' => self::VALUE_NO
),
);
}
return $this->_options;
}
当您要修改它时,请创建您自己的源类并从Mage_Eav_Model_Entity_Attribute_Source_Abstract
扩展它.
When you want to modify it create your own source class and extend it from Mage_Eav_Model_Entity_Attribute_Source_Abstract
.
您可以将Mage_Catalog_Model_Product_Attribute_Source_Boolean
作为源.它包含以下选项:
You can take Mage_Catalog_Model_Product_Attribute_Source_Boolean
as your source. It contains the options:
- 是
- 否
- 使用配置
因此,源应设置为:catalog/product_attribute_source_boolean
这篇关于Magento:属性选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!