【问题标题】:Magento : attribute select optionsMagento:属性选择选项
【发布时间】:2014-03-20 11:16:31
【问题描述】:

对于允许自定义价格,只有是/否,但我也想添加“使用配置”选项,如应用地图选择我该怎么做?

这是属性:

$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:

                    <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>

谢谢你的提前

【问题讨论】:

    标签: magento


    【解决方案1】:

    在您的属性配置中,您将源模型设置为eav/entity_attribute_source_boolean。该类包含以下填充选项数据的方法:

     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扩展它。

    编辑:

    您可以将Mage_Catalog_Model_Product_Attribute_Source_Boolean 作为您的来源。它包含选项:

    • 是的
    • 没有
    • 使用配置

    所以来源应该设置为:catalog/product_attribute_source_boolean

    【讨论】:

    • 你看到在产品价格中应用地图它使用是-否-使用配置什么类?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-20
    • 1970-01-01
    • 2014-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多