Magento : System/Config Add Custom Value in MultiSelect

此生再无相见时 提交于 2019-12-05 00:11:37

问题


i have created one simple Module. i have created system.xml. there is one field Multiselect i want to add custom Value in multiselect field.

is it possible to add custom Value in multiselect field ?

 <Data translate="label">
 <label>Select Socail Media</label>
 <comment>Select Social Media To fdisplay ion Front Side</comment>
 <front_end_type>multiselect</front_end_type>
 <source_model>adminhtml/system_config_source_country</source_model>
 <sort_order>3</sort_order>
 <show_in_default>1</show_in_default>
 <show_in_website>1</show_in_website>
 <show_in_store>1</show_in_store>
 </Data>    

in Multiselect Options i want to add my Custom Option like: Data1, Data2 , Data3 etc..

how can i do that? is it possible?


回答1:


yes you can create like this way add below code to system.xml

<fields>
    <view_style translate="label">
        <label>Display Settings</label>
        <frontend_type>multiselect</frontend_type>
        <source_model>yourmodule/system_config_source_view</source_model>
        <sort_order>40</sort_order>
        <show_in_default>1</show_in_default>
    </view_style>
</fields>

create one file for multiselect option in your module in this path

your_namespace/yourmodel/Model/System/Config/Source/View.php

Add below code in your View.php

class YourNamespace_YourModule_Model_System_Config_Source_View 
{
    /**
     * Options getter
     *
     * @return array
     */
    public function toOptionArray()
    {
        return array(
            array('value' => 0, 'label' => Mage::helper('adminhtml')->__('Data1')),
            array('value' => 1, 'label' => Mage::helper('adminhtml')->__('Data2')),
            array('value' => 2, 'label' => Mage::helper('adminhtml')->__('Data3')),
        );
    }

    /**
     * Get options in "key-value" format
     *
     * @return array
     */
    public function toArray()
    {
        return array(
            0 => Mage::helper('adminhtml')->__('Data1'),
            1 => Mage::helper('adminhtml')->__('Data2'),
            3 => Mage::helper('adminhtml')->__('Data3'),
        );
    }
}

Also for more detail use this link

hope this will sure help you.



来源:https://stackoverflow.com/questions/18650487/magento-system-config-add-custom-value-in-multiselect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!