カスタムフォームに「許可された国」フィールドを追加する方法


8

管理者がさまざまな国のゾーンを作成できるようにするカスタムモジュールを作成する必要があります。System > Configuration > General > Countries Options管理者がゾーンの国を選択できるフォームに(デフォルトのmagentoと同じように)「国を許可する」フィールドを追加する必要があります。

カスタムモジュール管理フォームに国の複数選択フィールドを追加するだけです。

誰でもこれを行う方法を手伝ってくれる?ありがとう。


尋ねるのを忘れて申し訳ありません。これをカスタム構成セクションまたは管理フォームに追加しますか?
Shathish 2013年

カスタムモジュール管理フォームにフィールドを追加する必要があります。
ジャイミンスタリヤ2013年

回答:


6

私は解決策を見つけました。
フォームに国の複数選択ドロップダウンを追加するには、Block/Adminhtml/ModuleName/Edit/Tab/Form.phpファイルに以下のコードを追加する必要があります。

$countryList = Mage::getModel('directory/country')->getResourceCollection()->loadByStore()->toOptionArray(true);
$fieldset->addField('countries', 'multiselect', array(
            'name'      => 'countries[]',
            'label'     => Mage::helper('zones')->__('Countries'),
            'title'     => Mage::helper('zones')->__('Countries'),
            'required'  => true,
            'values'    => $countryList,
        ));

6

カスタムモジュール構成の許可された国フィールドを取り込むには:

以下をモジュールの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,
));

注意:

  • データベースの複数選択値をsaveAction()に保存するロジックを作成する必要があります

これを管理グリッドに表示するには:

このリンクを参照してください


複数選択値を保存するには、 "、"を使用して投稿データを内挿するだけです(例:$ countries = implode( "、"、$ selectedCountries))。データベースに保存します。Magentoは他のすべてを行い、編集または表示ページに戻します。
ジャイミンスタリヤ2013年

3
$fieldset->addField('country', 'select', array(  
        'name' => 'country',  
        'label' => 'Country',  
        'values' => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),  
        ));
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.