要在您的自定义模块配置中加入允许的国家/地区字段,请执行以下操作:
将以下内容添加到模块的system.xml中
<sallowspecific translate="label">
<label>Ship to Applicable Countries</label>
<frontend_type>select</frontend_type>
<sort_order>90</sort_order>
<frontend_class>shipping-applicable-country</frontend_class>
<source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</sallowspecific>
<specificcountry translate="label">
<label>Ship to Specific Countries</label>
<frontend_type>multiselect</frontend_type>
<sort_order>91</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>
<can_be_empty>1</can_be_empty>
</specificcountry>
<fields>
您的自定义部分中的标签下。
要将其添加到管理员表单中:
在app / code / local / Yourmodulename / Block / Adminhtml / Yourmodulename / Edit / Tab / Form.php中
$countryList = Mage::getModel('directory/country')->getResourceCollection()->loadByStore()->toOptionArray(true);
$fieldset->addField('allowed_countries', 'multiselect', array( /* "allowed_countries" is the column name in your custom table to store these values */
'name' => 'countries[]',
'label' => Mage::helper('yourmodulename')->__('Allowed Countries'),
'title' => Mage::helper('yourmodulename')->__('Allowed Countries'),
'required' => true, /* only if it is required */
'values' => $countryList,
));
注意:
- 您必须编写逻辑以将multiselect值保存在saveAction()中的数据库中
将其显示在管理网格中:
请参阅此链接。