获取Magento 2中的配送地址county
嗨,我有一个自定义模块。我想进入航运国获取Magento 2中的配送地址county,magento,magento2,Magento,Magento2,嗨,我有一个自定义模块。我想进入航运国 public function execute(\Magento\Framework\Event\Observer $observer) { 请让我知道我怎样才能得到这个 我看过这个邮政编码,但我不确定他的工作与否 $postCode = $this->_checkoutSession->getQuote()-getShippingAddress()->getPostcode(); 我需要在公共功能中执行配送地址国家名称。
public function execute(\Magento\Framework\Event\Observer $observer)
{
请让我知道我怎样才能得到这个
我看过这个邮政编码,但我不确定他的工作与否
$postCode = $this->_checkoutSession->getQuote()-getShippingAddress()->getPostcode();
我需要在公共功能中执行配送地址国家名称。请提供帮助。声明一个公共变量并初始化该变量,如下所示,然后您就可以在execute方法中使用它了
class Example {
public $_checkOutSession;
public function __construct(\Magento\Customer\Model\Session $checkOUtSession)
{
$this->_checkOutSession = $checkOutSession;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$postCode = $this->_checkoutSession->getQuote()->getShippingAddress()->getPostcode();
}
}
这取决于你想要哪个观察者。你能提供一个更具体的场景吗 其中签出会话当前有一个报价。您可以使用Reggie提供的上述解决方案 否则,您需要初始化报价单/订单才能获得它