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
方法