【问题标题】:How to add country and state drop down in customer account inforamtion tab and display state based on country selected in magento admin如何在客户帐户信息选项卡中添加国家和州下拉菜单并根据在 magento admin 中选择的国家/地区显示状态
【发布时间】:2016-05-24 06:36:37
【问题描述】:

我想在后台管理的客户帐户信息选项卡中再显示两个下拉菜单,并首次显示所有国家和州的列表。 when select country than show all list of state based on selected country.

【问题讨论】:

    标签: tabs add state country customer


    【解决方案1】:
    Open your "app\code\core\Mage\Adminhtml\Block\Customer\Edit\TabAccount.php" file and copy file in your local code folder 
    

    在网站 id 后添加代码

    $country = $fieldset->addField('country', 'select', array(
                'name' => 'country',
                'label' => Mage::helper('customer')->__('Country'),
                'values' => Mage::getModel('adminhtml/system_config_source_country')->toOptionArray(),
                'class' => 'required-entry',`enter code here`
                'required' => true,
                'onchange' => 'getstate(this)',
            ));
    
            //Edit action pass your custom table to country id and get state
            $storeId = $this->getRequest()->getParam('id');
            $editState = $stateCollection = Mage::getModel('directory/region')->load($storeId);
            $stateCollection = Mage::getModel('directory/region')->getResourceCollection()->addCountryFilter($editState->getCountry())->load();
            $state = "";
            foreach ($stateCollection as $_state) {
                $state[] = array('value' => $_state->getCode(), 'label' => $_state->getDefaultName());
            }
            $fieldset->addField('state', 'select', array(
                'label' => Mage::helper('customer')->__('State'),
                'required' => false,
                'name' => 'state',
                'selected' => 'selected',
                'values' => $state,
            ));
    
    
            /*
             * Add Ajax to the Country select box html output
             */
            $url = Mage::getBaseUrl();
            $country->setAfterElementHtml("<script type=\"text/javascript\">
        function getstate(selectElement){
            var reloadurl = '" . $url . 'admin/customer/state/' . "country/' + selectElement.value;
            new Ajax.Request(reloadurl, {
                method: 'POST',
                onComplete: function (transport) {
                    jQuery('#_accountstate').html(transport.responseText);
                }
            });
        }
    //</script>");
    
    add function in "app\code\core\Mage\Adminhtml\controllers\CustomerController.php after extend it in your local code pool
    
    
    public function stateAction() {
            $countrycode = $this->getRequest()->getParam('country');
            $state = "<option value=''>--Please Select--</option>";
            if ($countrycode != '') {
                $statearray = Mage::getModel('directory/region')->getResourceCollection()->addCountryFilter($countrycode)->load();
                foreach ($statearray as $_state) {
                    $state .= "<option value='" . $_state->getCode() . "'>" . $_state->getDefaultName() . "</option>";
                }strong text
            }
            echo $state;
    

    标题

       i have tested it on magento 1.7
    
    clear your magento cache.
    

    很好在这里

    【讨论】:

      猜你喜欢
      • 2017-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-03
      相关资源
      最近更新 更多