1

How can we get address id based get address details! I got all address details getting based on customer id but i need to get address details based on address id?How can i achieve this

0

1 Answer 1

1

You can get the formatted address using the address id with the below code:

public function __construct(
    \Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
    \Magento\Customer\Model\Address\Config $addressConfig,
    \Magento\Customer\Model\Address\Mapper $addressMapper,
) {
    $this->addressRepository = $addressRepository;
    $this->_addressConfig = $addressConfig;
    $this->addressMapper = $addressMapper;
}

public function getFormattedAddress($addressId)
{
    try {
        $addressObject = $this->addressRepository->getById($addressId);
        /** @var \Magento\Customer\Block\Address\Renderer\RendererInterface $renderer */
        $renderer = $this->_addressConfig->getFormatByCode('html')->getRenderer();
        return $renderer->renderArray($this->addressMapper->toFlatArray($addressObject));
    } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
        return null;
    }
}
1
  • Hi Thanks for your reply! i need to REST API
    – Lavaraju
    Commented Nov 14, 2018 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.