Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取Magento 2中的配送地址county_Magento_Magento2 - Fatal编程技术网

获取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提供的上述解决方案

否则,您需要初始化报价单/订单才能获得它