Magento Forum

system.xml dynamical creation? 
 
arthurio
Jr. Member
 
Total Posts:  10
Joined:  2012-10-11
 

Hello all. For example, I have this system.xml file:

<config>
    <
sections>
        <
shippingrestr translate=\"label\" module=\"shipmentandpayment\">
            <
label>Shipping restrictions</label>
            <
tab>customer</tab>
            <
frontend_type>text</frontend_type>
            <
sort_order>1000</sort_order>
            <
show_in_default>1</show_in_default>
            <
show_in_website>1</show_in_website>
            <
show_in_store>1</show_in_store>
            <
groups>
                <
shippingrestr_group translate=\"label\" module=\"shipmentandpayment\">
                    <
label>Customer groups</label>
                    <
frontend_type>text</frontend_type>
                    <
sort_order>1000</sort_order>
                    <
show_in_default>1</show_in_default>
                    <
show_in_website>1</show_in_website>
                    <
show_in_store>1</show_in_store>
                    <
expanded>1</expanded>
                    <
fields>
                        <
customer_groups>
                            <
label>Customer groups</label>
                            <
frontend_type>multiselect</frontend_type>
                            <
source_model>shipmentandpayment/customergroups</source_model>
                            <
sort_order>1</sort_order>
                            <
show_in_default>1</show_in_default>
                            <
show_in_website>1</show_in_website>
                            <
show_in_store>1</show_in_store>
                        </
customer_groups>
                        <
shipping_methods>
                            <
label>Shipping methods</label>
                            <
frontend_type>multiselect</frontend_type>
                            <
source_model>shipmentandpayment/shippingmethods</source_model>
                            <
sort_order>1</sort_order>
                            <
show_in_default>1</show_in_default>
                            <
show_in_website>1</show_in_website>
                            <
show_in_store>1</show_in_store>
                        </
shipping_methods>
                        <
customer_groups2>
                            <
label>Customer groups</label>
                            <
frontend_type>multiselect</frontend_type>
                            <
source_model>shipmentandpayment/customergroups</source_model>
                            <
sort_order>1</sort_order>
                            <
show_in_default>1</show_in_default>
                            <
show_in_website>1</show_in_website>
                            <
show_in_store>1</show_in_store>
                        </
customer_groups2>
                    </
fields>
                </
shippingrestr_group>
            </
groups>
        </
shippingrestr>
    </
sections>
</
config>
This adds new section under system->configuration->Customers with name \"Shipping restrictions\” with group \"Customer groups\” in which it makes 3 fields. With source model i filled them.

But, i need to create fields dynamically depending on one or another condition. ( For example, create as many multiselect fields, as there are enabled shipping methods )

Is there any way I can do that? My guess is that it\’s done with Blocks, but i\’m not sure. Maybe there are some tutorials? I couldn\’t find any in google.

Any help will be appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
arthurio
Jr. Member
 
Total Posts:  10
Joined:  2012-10-11
 
arabgento - 11 February 2013 03:52 AM

<depends/>

<depends/> allows you specify that your configuration field should only be displayed when another confgiruation field in the same group has a specific value.

For example, the Paypal Express System Configuration has the following select defined.

<specificcountry translate="label">
<label>Countries Payment Applicable From</label>
<frontend_type>multiselect</frontend_type>
<sort_order>110</sort_order>
<source_model>adminhtml/system_config_source_country</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
<depends><allowspecific>1</allowspecific></depends>
</specificcountry>

You’ll notice the

<depends><allowspecific>1</allowspecific></depends>

This is telling the system that if the <allowspecific> field (defined with the following)

<allowspecific translate="label">
<label>Payment Applicable From</label>
<frontend_type>select</frontend_type>
<sort_order>100</sort_order> <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</allowspecific>

has a value of “1”, then the <specificcountry> field should be displayed. This happens instantly via some behind the scenes Javascript.

While it appears to work with any fields that send out on onchange event, the core Magento system only uses this function where the parent field is a select. If you’re paranoid about forward compatibility, I’d apply the same restriction to your own System Configuration fields, as it’s hard to tell where the core Magento team may take this feature in the future.



link of tut http://alanstorm.com/magento_system_configuration_in_depth_tutorial

I dont think this will work in my situation, because as I understood from this tutorial, ill have to make so many multiselects as there are shipping methods and then point this <depends> to every multiselect for every method.

Maybe this will be clearer - I need to make multiselects with customer groups and <label> for multiselect should be shipping methods title. So, for every enabled shipping method there should be multiselect field with customer groups, where <label> will be shipping method. With enabled shipping method i mean methods, which are enabled in system->configuration->sales->shipping methods

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top