gpt4 book ai didi

magento - 如何根据 magento 产品表单中选择的国家/地区添加州下拉菜单

转载 作者:行者123 更新时间:2023-12-02 10:25:07 26 4
gpt4 key购买 nike

您好,我想根据在管理中的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com