Frage

I need to fetch the value of customer address attribute just like we have product attribute

I am using Magento\Customer\Api\AddressRepositoryInterface and created the instance from it

$addressRepository = $objectManager->create("Magento\Customer\Api\AddressRepositoryInterface");
$address = $addressRepository->getById($customerId);

From $address instance, I am able to fetch the default field or attribute just like

$address->getFirstname();

The problem is, I am not able to fetch the newly created customer address attribute

For Example: My newly created customer address attribute is area but I am not able to fetch it from $address->getArea();

Any help, experience and knowledge sharing would be appreciated

War es hilfreich?

Lösung

If you have custom address attribute then you can get it's value by this:

echo $address->getCustomAttribute("area")->getValue();

This would treated as same way as customer custom attribute.

But the problem with above code is, if your attribute is dropdown, then it will return option id, not the text of option.

Hope this will resolve your issue :)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top