作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您好,我想根据在管理中的 magento 产品中选择的国家/地区显示状态下拉菜单,任何人都可以告诉我如何执行此操作。我已经用 google 搜索了它,但没有成功。
最佳答案
Sunel。请检查以下解决方案,它可能会对您有所帮助。
打开 Yournamespace/Modulename/Block/Adminhtml/Modulename/Edit/Tab/Form.php
中的表单,然后添加以下字段
$country = $fieldset->addField('country', 'select', array(
'name' => 'country',
'label' => 'Country',
'values' => Mage::getModel('adminhtml/system_config_source_country') ->toOptionArray(),
'onchange' => 'getstate(this)',
));
$fieldset->addField('state', 'select', array(
'name' => 'state',
'label' => 'State',
'values' => Mage::getModel('modulename/modulename')->getstate('AU'),
));
/*
* Add Ajax to the Country select box html output
*/
$country->setAfterElementHtml("<script type=\"text/javascript\">
function getstate(selectElement){
var reloadurl = '". $this->getUrl('modulename/adminhtml_modulename/state') . "country/' + selectElement.value;
new Ajax.Request(reloadurl, {
method: 'get',
onLoading: function (stateform) {
$('state').update('Searching...');
},
onComplete: function(stateform) {
$('state').update(stateform.responseText);
}
});
}
</script>");
现在在 modulenamecontroller.php 文件中创建状态操作,如下所示
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>";
}
}
echo $state;
}
谢谢。
关于magento - 如何根据 magento 产品表单中选择的国家/地区添加州下拉菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18030117/
我是一名优秀的程序员,十分优秀!