问题描述
网站1(美国)正常工作,网站2(澳大利亚)无效,两者的配置相同。
如果客户尝试通过卡付款,出现以下错误,
Fatal error: Uncaught Error: Call to a member function getId() on null in /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.PHP:1524 Stack trace:
#0 /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.PHP(1493): Magento\Paypal\Model\Api\Nvp->_applyStreetAndRegionWorkarounds(Object(Magento\Framework\DataObject))
#1 /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.PHP(849): Magento\Paypal\Model\Api\Nvp->_exportAddresses(Array)
#2 /var/www/html/test/app/code/Magento/Paypal/Model/Express/Checkout.PHP(621): Magento\Paypal\Model\Api\Nvp->callGetExpressCheckoutDetails()
#3/var/www/html/test/app/code/Magento/Paypal/Controller/Express/AbstractExpress/ReturnAction.PHP(32): Magento\Paypal\Model\Express\Checkout->returnFromPaypal('*********')
#4/var/www/html/test/generated/code/Magento/Paypal/Controller/Express/ReturnAction/Interceptor.PHP(24): Magento\Paypal\Controller\Express\AbstractExpress\ReturnAction->execute()
#5 /var/www/html/test/lib/internal/Magento/Framework/App/Action/Ac in /var/www/html/test/app/code/Magento/Paypal/Model/Api/Nvp.PHP on line 1524
代码:
protected function _applyStreetAndRegionWorkarounds(DataObject $address)
{
// merge street addresses into 1
if ($address->getData('street2') !== null) {
$address->setStreet(implode("\n",[$address->getData('street'),$address->getData('street2')]));
$address->unsetData('street2');
}
// attempt to fetch region_id from directory
if ($address->getCountryId() && $address->getRegion()) {
$regions = $this->_countryFactory->create()->loadByCode(
$address->getCountryId()
)->getRegionCollection()->addRegionCodeOrNameFilter(
$address->getRegion()
)->setPageSize(
1
);
$regionItems = $regions->getItems();
$region = array_shift($regionItems);
$address->setRegionId($region->getId());
$address->setExportedKeys(array_merge($address->getExportedKeys(),['region_id']));
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)