【发布时间】:2014-03-29 17:18:53
【问题描述】:
我有一个客户的请求,他们想在 Magento 中添加额外的国家。 例如,除了“United Kingdom”,我们还添加了“Wales”、“Scotland”、“England”。
我遵循了来自:http://www.magentoworks.net/how-to-add-new-country-in-magento 的指南 并在管理面板中设置新的国家发货。 这很好并且有效,但是指南提到需要在数据库中使用唯一的国家代码。
出现的问题是该网站使用的支付网关只接受默认的 Magento 网关,并且由于向网站添加国家/地区是装饰性的,我认为最好的想法是在结帐时,一旦收货地址选择然后我可以检查任何新的国家代码,然后将它们设置为“英国”国家代码。
我在尝试使其正常工作时遇到问题。通过查看 shipping.phtml,选择的国家被称为:
<label for="shipping:country_id" class="required"><em>*</em><?php echo $this->__('Country') ?></label>
<div class="input-box">
<?php echo $this->getCountryHtmlSelect('shipping') ?>
</div>
我已经追踪到了函数:
public function getCountryHtmlSelect($type)
其中:
Mage/Checkout/Block/Onepage/Abstract.php
从这里我尝试覆盖和自定义函数,以便如果国家代码是自定义代码之一,那么它将设置为我希望可以工作的“GB”:
public function getCountryHtmlSelect($type)
{
$countryId = $this->getAddress()->getCountryId();
if($countryId == 'ZD' || $countryId == 'ZB' || $countryId == 'ZC'):
$newCountryId = "GB";
else:
$newCountryId = $countryId;
endif;
if (is_null($countryId)) {
$countryId = Mage::helper('core')->getDefaultCountry();
}
$select = $this->getLayout()->createBlock('core/html_select')
->setName($type.'[country_id]')
->setId($type.':country_id')
->setTitle(Mage::helper('checkout')->__('Country'))
->setClass('validate-select')
->setValue($newCountryId)
->setOptions($this->getCountryOptions());
if ($type === 'shipping') {
$select->setExtraParams('onchange="if(window.shipping)shipping.setSameAsBilling(false);"');
}
return $select->getHtml();
}
但是,当我结帐并到达支付网关时,我遇到了故障(因为它仍在发送自定义国家代码。
当用户刚刚完成结帐的“送货”步骤时,在单页结帐中更改送货国家代码的最佳方法是什么?
非常感谢任何帮助。谢谢你。
【问题讨论】:
-
getCountryHtmlSelect以前端形式打印国家/地区列表。
标签: magento magento-1.7 checkout