Magento: get a list of regions for a country in the admin delivery module

Currently, in my /etc/system.xml file, I can use this to pull out a complete list of regions that are stored in Magento and display them as a multi-segment. This works great, but I would only prefer to push regions for one country, for example. counties of Great Britain or states of the USA:

                    <counties translate="label">
                        <label>Counties</label>
                        <frontend_type>multiselect</frontend_type>
                        <sort_order>10</sort_order>
                        <source_model>adminhtml/system_config_source_allregion</source_model>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </counties>

The reason for this is that I added a lot of regions / states / districts to the system, and now it is not a very user-friendly selection field.

UPDATE:

After you did not immediately answer the solutions below, I again considered this problem after a while to assemble my own solution based on the answers received.

//​​ ​​/Mage/Adminhtml/Model/System/Config/Source/Allregion.php app/code/core/Mage/Adminhtml/Model/System/Config/Source/Ukregion.php

Mage_Adminhtml_Model_System_Config_Source_Ukregion.

:

        $regionsCollection = Mage::getResourceModel('directory/region_collection')->load();

:

        $regionsCollection = Mage::getResourceModel('directory/region_collection')->addCountryFilter('GB')->load();

( , " " ).

, system.xml:

                    <counties translate="label">
                        <label>Counties</label>
                        <frontend_type>multiselect</frontend_type>
                        <sort_order>10</sort_order>
                        <source_model>adminhtml/system_config_source_ukregion</source_model>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>
                    </counties>

"" "GB" - GB NI, " ". "" , .

+3
2

"" > "" > " ", , .

app/code/core/Mage/Shipping/etc/system.xml. :

<country_id translate="label">
    <label>Country</label>
    <frontend_type>select</frontend_type>
    <frontend_class>countries</frontend_class>
    <source_model>adminhtml/system_config_source_country</source_model>
    <sort_order>10</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>0</show_in_store>
</country_id>
<region_id translate="label">
    <label>Region/State</label>
    <frontend_type>text</frontend_type>
    <sort_order>20</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>0</show_in_store>
</region_id>

:

  • countries country_id.
  • region_id.
  • .

javascript . countries ID (). , AJAX.

, /, .

+4

source_model "where" - . , , source_model .

toOptionArray(). :

public function toOptionArray()
    {
        return array(
            array( 'value' => VALUE,
                'label' => LABEL ) ),

            array( 'value' => VALUE2,
                'label' => LABEL2 )
        );
    }

, .

+1

All Articles