Magento:如何从所选/输入的配送地址获取countryID
我试图隐藏shipping_method.phtml中的一些文本/代码,这取决于所选或输入的配送地址所在的国家是否在法国 我找到的唯一代码是Magento:如何从所选/输入的配送地址获取countryID,magento,checkout,shipping,street-address,country,Magento,Checkout,Shipping,Street Address,Country,我试图隐藏shipping_method.phtml中的一些文本/代码,这取决于所选或输入的配送地址所在的国家是否在法国 我找到的唯一代码是 Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getCountryId() 但所有这些都是返回地址簿中我默认地址的countryID。 因此,当地址已经在通讯簿中时,代码就起作用,但如果客户决定将其发送到新地址,代码就不起作用
Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->getCountryId()
但所有这些都是返回地址簿中我默认地址的countryID。
因此,当地址已经在通讯簿中时,代码就起作用,但如果客户决定将其发送到新地址,代码就不起作用
因此,我需要一种方法来访问php/javascript中选择/输入的CountryID(应该存储在会话的某个地方,因为它显示在进度侧栏中)
请注意,我在magento CE 1.7.0.2中使用的是标准的onepage签出。问题是,当页面加载时会执行此代码,基本上,shipping methods块只是隐藏,直到您进入该步骤。这意味着
$this->getQuote()->getShippingAddress()->getCountry()
l
Ajax加载的唯一内容是可用的传送方法,因此我通过连接到
app/design/base/default/template/checkout/onepage/shipping_method/available.phtml
并添加以下javascript代码
<?php //Show extra shipping options only if the shipping address is outside of FRANCE ?>
<script type="text/javascript">
var countryID = '<?= Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData('country_id') ?>';
jQuery('#ownTransport')[countryID == 'FR' ? 'hide' : 'show']();
</script>
是
//
希望这能帮到别人 如果在magento中使用onepage签出,请使用此代码
Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()
->getCountryId();
您还可以使用:-
$countryId =Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData('country_id');
您可以尝试使用此代码
$this->getQuote()->getShippingAddress()->getCountry()
以获取国家id尝试修改的页面是什么?结账什么步骤?在本例中,$this->getQuote()->getShippingAddress()->getCountry()应该可以工作。这给了我与前面相同的结果。您获得的是默认发货地址的countryID,而不是所选地址(如果您有多个保存的发货地址)或所输入地址的countryID(如果您选择输入新地址)。奇怪。对我来说,它是有效的。尝试Mage::getSingleton('checkout/session')
而不是$this
。只是想把它扔出去。。。我不知道你想在这里实现什么,但值得注意的是,如果你想修改运费或任何基于国家的东西,WebShopApps的用户拥有一系列成熟的配送模块,可以满足你的任何需求。这正是我要搜索的。。我想检查装运国是德国还是与开票国相等。。谢谢。。你为我节省了很多时间:)
Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()
->getCountryId();
$countryId =Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getData('country_id');