You can get the customer address data by Address id using AddressRepositoryInterface interface.
Magento\Customer\Api\AddressRepositoryInterface contains the getById($addressId) function with pass first argument as address id to fetch specific customer address data.
<?php
namespace Rbj\Model\Address;
use Exception;
use Magento\Customer\Api\AddressRepositoryInterface;
class CustomerAddressById
{
/**
* @var AddressRepositoryInterface
*/
private $addressRepository;
public function __construct(
AddressRepositoryInterface $addressRepository
) {
$this->addressRepository = $addressRepository;
}
/**
* @param $addressId
*
* @return \Magento\Customer\Api\Data\AddressInterface
*/
public function getAddressData($addressId)
{
try {
$addressData = $this->addressRepository->getById($addressId);
} catch (Exception $exception) {
throw new Exception($exception->getMessage());
);
return $addressData;
}
}
You can get the address data by above function with passing address id as first arguments.
$addressId = 10;
$address = $this->getAddressData($addressId);
echo $address->getId();
echo $address->getCustomerId();
