2016-05-18 4 views
3

これは私のMagento 2を使用した最初のプロジェクトです。ログインした顧客のデフォルト請求/発送先住所を私のフロントエンドカスタムモジュール。ログインした顧客のデフォルトの請求先/配送先住所を取得Magento 2.0

これまでのところ、私はこれがあります。

//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); 

をしかし、エラーは言う: Call to undefined method Magento\Customer\Model\AddressFactory::load()

私は近いですが、私は次に何をすべきか分からないと思います。前もって感謝します。

答えて

5

顧客のログインの請求先住所を取得するための正しい方法は次のとおりです。

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

それは働きました!ありがとう! :D – Ian

+2

オブジェクトマネージャを直接使用するのは良い習慣ではありません。 さらに、使用するアドレスの適切なリポジトリにする必要があります。 –

+2

代わりに「間違った」方法を指摘してから、実際にどのように実装されるべきかの提案を書いてください。 – LefterisL

関連する問題