I'm having trouble with getting customer address Id as it returns a null value.
This is what I have tried:
$checkout = $this->_sessionCheckout->getQuote();
if ($checkout) {
$shippingAddress = $checkout->getShippingAddress();
if ($shippingAddress) {
$addressId = $shippingAddress->getCustomerAddressId();
$this->_logger->log(100, print_r('address Id: ' . $addressId , true)); //Returns null
/** @var \Magento\Customer\Api\Data\AddressInterface $address */
$address = $this->_addressRepository->getById($addressId);
$address->setCity($city_name);
$this->_addressRepository->save($address);
}
I just need to get customer address Id in order to update the city. I don't know why it returns a null value.
Edited Details:
The below image shows the saved shipping addresses:
What I want to know is How to know the customer address id of each of those shipping addresses. So I can modify any details I want.