How to create dropdown/select box in magento system.xml for payment/shipping configuration
-
looks like self promotion and it is anyway a duplicate questionClaudiu Creanga– Claudiu Creanga2016年04月26日 13:53:46 +00:00Commented Apr 26, 2016 at 13:53
-
Too generic, please be more specific.Phoenix128_RiccardoT– Phoenix128_RiccardoT2016年04月26日 19:00:37 +00:00Commented Apr 26, 2016 at 19:00
-
Please check below i also put the answer of my question.Jaydip Kansagra– Jaydip Kansagra2016年04月28日 07:07:10 +00:00Commented Apr 28, 2016 at 7:07
1 Answer 1
Create drop down in system.xml and show custom values in it, rather than using default magento classes only
Directory : app/code/local/Companyname/Modulename/config/system.xml
In system.xml
<config>
<sections>
<payment>
<groups>
<Modulename translate="label" module="Modulename">
<label>Payment Module</label>
<sort_order>670</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<fields>
<paymentmethod translate="label comment">
<label>Payment method</label>
<comment>Omni Payment method.</comment>
<frontend_type>select</frontend_type>
<source_model>Modulename/Modelname</source_model>
<sort_order>30</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>0</show_in_website>
<show_in_store>0</show_in_store>
</paymentmethod>
</fields>
</Modulename>
</groups>
</payment>
</sections>
</config>
If you want to create your custom source_Model, you need to do the following steps: Create a Pmethod.php in app/code/local/Companyname/Modulename/Model/Pmethod.php Companyname_Modulename is our module name. You need to create a function name toOptionArray() as mention below, the value and label can be anything you want to be display in dropdown
In Pmethod.php
class Companyname_Modulename_Model_Pmethod
{
public function toOptionArray()
{
return array(
array(
'value' => 'key1',
'label' => 'Label 1',
),
array(
'value' => 'key2',
'label' => 'label 2',
)
);
}
}
-
How to show selected value in backend dropdown? Because after saving it's not showing selected value in dropdpwn.Kaushal Suthar– Kaushal Suthar2017年06月23日 06:45:34 +00:00Commented Jun 23, 2017 at 6:45
-
You need to check <source_model>Modulename/Modelname</source_model> with same value as ModelJaydip Kansagra– Jaydip Kansagra2017年06月24日 09:17:03 +00:00Commented Jun 24, 2017 at 9:17
-
Yes that's correct in mine, Values are fetched properly but after saving it's not showing selected value in dropdown.Kaushal Suthar– Kaushal Suthar2017年06月25日 20:24:15 +00:00Commented Jun 25, 2017 at 20:24
Explore related questions
See similar questions with these tags.