php - 获取登录客户 Magento 2.0 的默认账单/送货地址

标签 php magento frontend magento2

这是我使用 Magento 2 的第一个项目。我很难让登录客户的默认账单/送货地址显示在我的自定义模块的前端。

到目前为止我有这个:

//this gets the billing id which is an integer. I'm thinking it must be loaded to get the whole data of the address
$billingId =  $customerSession->getCustomer()->getDefaultBilling();

//just found this in the internet and thought it might be the same as loading an order, but it doesn't work
$address = $objectManager->create('\Magento\Customer\Model\AddressFactory')->load($billingId);

但是错误说: 调用未定义的方法 Magento\Customer\Model\AddressFactory::load()

我想我已经接近了,但我不知道下一步该做什么。提前致谢。

最佳答案

获取已登录客户的账单地址的正确方法是:

$billingID =  $customerSession->getCustomer()->getDefaultBilling();
$address = $objectManager->create('Magento\Customer\Model\Address')->load($billingID);
echo "<pre>";print_r($address->getData());exit;

关于php - 获取登录客户 Magento 2.0 的默认账单/送货地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37290152/

相关文章:

php - 如何在开源(Github + Heroku)应用程序中保护 Google API Key

php - 如何使用PHP查找两个日期之间的时差

php - Magento 自定义支付方式

html - 仅使用CSS将图片制作成圆形 View

css - 页面滚动?也许 z-index?

php - MySQL查询结果中某项的顺序

php - 在 Laravel 4 中返回 Input::except() 多个输入

html - devicePixelRatio 和 dppx 有什么不同?

magento - magento 变量中的下划线

css - 如何管理超过 10,000 行的 magento CSS 文件?