Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.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
Php 从签出表单magento 2获取数据_Php_Magento2 - Fatal编程技术网

Php 从签出表单magento 2获取数据

Php 从签出表单magento 2获取数据,php,magento2,Php,Magento2,我正在创建一个新的发货方法,使用邮政编码验证邮政编码是否覆盖范围,但首先我需要结帐表单中的数据,我找到了下一个代码: $shippingId = $customerSession->getCustomer()->getDefaultShipping(); $address = $objectManager->create('Magento\Customer\Model\Address')->load($shippingId); $address->getData(

我正在创建一个新的发货方法,使用邮政编码验证邮政编码是否覆盖范围,但首先我需要结帐表单中的数据,我找到了下一个代码:

$shippingId =  $customerSession->getCustomer()->getDefaultShipping();
$address = $objectManager->create('Magento\Customer\Model\Address')->load($shippingId);
$address->getData();
我使用它来获取数据,但在chrome中检查控制台时会显示下一条消息:

加载资源失败:服务器响应状态为500

代码的一部分是:

public function collectRates(RateRequest $request)
    {
        if (!$this->getConfigFlag('active')) {
            return false;
        }


        $shippingId = $customerSession->getCustomer()->getDefaultShipping();
$address = $objectManager->create('Magento\Customer\Model\Address')->load($shippingId);
$mage = $address->getData();

$file = 'postal.txt';
$print = print_r($mage, true);
file_put_contents($file, $print, FILE_APPEND | LOCK_EX);


        $shippingPrice = $this->getConfigData('price');

        $result = $this->_rateResultFactory->create();

        if ($shippingPrice !== false) {
            $method = $this->_rateMethodFactory->create();

            $method->setCarrier($this->_code);
$method->setCarrierTitle($this->getConfigData('title'));

            $method->setMethod($this->_code);
$method->setMethodTitle($this->getConfigData('name'));

            if ($request->getFreeShipping() === true || $request->getPackageQty() == $this->getFreeBoxes()) {
                $shippingPrice = '0.00';
            }

            $method->setPrice($shippingPrice);
            $method->setCost($shippingPrice);

            $result->append($method);
        }

        return $result;
    } 

如何从签出表单中正确获取数据?

若要检索邮政编码,请使用
$request->getdestposcode()
内部
CollectRates
方法

若要检索邮政编码,请使用
$request->getdestposcode()
内部
CollectRates
方法