Skip to main content
added 141 characters in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144

I followed below link to update address using address id

Update customer address using address id in magento 2

I am getting this error upon executing this code

protected $addressRepository;

public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
 ) {
$this->addressRepository = $addressRepository;
}

public function changeAddress($addressId)
{
  $AddressId = 381993;

if(isset($AddressId) && $AddressId !=''){
            try{
                $address = $this->addressRepository->getById($AddressId);
                $address->setFirstname('test');
                $address->setLastname('test');
                $address->setCountryId('GB');
                $address->setRegion()->setData(array('region' => 'test'));
                $address->setPostcode('t9 1rd');
                $address->setCity('test');
                $this->addressRepository->save($address);
             }catch(\Exception $e){
               print_r($e->getMessage());
             }
            
            }
   }

I am getting this error upon using this code

  "message": "Invalid value of \"1\" provided for the regionId field.",

I tried

   $address->setRegion(); also same error again

What is the mistake in above code? Please anyone help me.

I followed below link to update address using address id

Update customer address using address id in magento 2

I am getting this error upon executing this code

protected $addressRepository;

public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
 ) {
$this->addressRepository = $addressRepository;
}

public function changeAddress($addressId)
{
  $AddressId = 381993;

if(isset($AddressId) && $AddressId !=''){
            try{
                $address = $this->addressRepository->getById($AddressId);
                $address->setFirstname('test');
                $address->setLastname('test');
                $address->setCountryId('GB');
                $address->setPostcode('t9 1rd');
                $address->setCity('test');
                $this->addressRepository->save($address);
             }catch(\Exception $e){
               print_r($e->getMessage());
             }
            
            }
   }

I am getting this error upon using this code

  "message": "Invalid value of \"1\" provided for the regionId field.",

I followed below link to update address using address id

Update customer address using address id in magento 2

I am getting this error upon executing this code

protected $addressRepository;

public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
 ) {
$this->addressRepository = $addressRepository;
}

public function changeAddress($addressId)
{
  $AddressId = 381993;

if(isset($AddressId) && $AddressId !=''){
            try{
                $address = $this->addressRepository->getById($AddressId);
                $address->setFirstname('test');
                $address->setLastname('test');
                $address->setCountryId('GB');
                $address->setRegion()->setData(array('region' => 'test'));
                $address->setPostcode('t9 1rd');
                $address->setCity('test');
                $this->addressRepository->save($address);
             }catch(\Exception $e){
               print_r($e->getMessage());
             }
            
            }
   }

I am getting this error upon using this code

  "message": "Invalid value of \"1\" provided for the regionId field.",

I tried

   $address->setRegion(); also same error again

What is the mistake in above code? Please anyone help me.

added 1 character in body
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144

I followed below link to update address using address id

Update customer address using address id in magento 2

I am getting this error upon executing this code

protected $addressRepository;

public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
 ) {
$this->addressRepository = $addressRepository;
}

public function changeAddress($addressId)
{
  $AddressId = 381993;

if(isset($AddressId) && $AddressId !=''){
            try{
                $address = $this->addressRepository->getById($AddressId);
                $address->setFirstname('test'test');
                $address->setLastname('test');
                $address->setCountryId('GB');
                $address->setPostcode('t9 1rd');
                $address->setCity($City'test');
                $this->addressRepository->save($address);
             }catch(\Exception $e){
               print_r($e->getMessage(););
             }
            
            }
   }

I am getting this error upon using this code

  "message": "Invalid value of \"1\" provided for the regionId field.",

I followed below link to update address using address id

Update customer address using address id in magento 2

I am getting this error upon executing this code

protected $addressRepository;

public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
 ) {
$this->addressRepository = $addressRepository;
}

public function changeAddress($addressId)
{
  $AddressId = 381993;

if(isset($AddressId) && $AddressId !=''){
            try{
                $address = $this->addressRepository->getById($AddressId);
                $address->setFirstname('test);
                $address->setLastname('test');
                $address->setCountryId('GB');
                $address->setPostcode('t9 1rd');
                $address->setCity($City);
                $this->addressRepository->save($address);
             }catch(\Exception $e){
               print_r($e->getMessage(););
             }
            
            }
   }

I am getting this error upon using this code

  "message": "Invalid value of \"1\" provided for the regionId field.",

I followed below link to update address using address id

Update customer address using address id in magento 2

I am getting this error upon executing this code

protected $addressRepository;

public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
 ) {
$this->addressRepository = $addressRepository;
}

public function changeAddress($addressId)
{
  $AddressId = 381993;

if(isset($AddressId) && $AddressId !=''){
            try{
                $address = $this->addressRepository->getById($AddressId);
                $address->setFirstname('test');
                $address->setLastname('test');
                $address->setCountryId('GB');
                $address->setPostcode('t9 1rd');
                $address->setCity('test');
                $this->addressRepository->save($address);
             }catch(\Exception $e){
               print_r($e->getMessage());
             }
            
            }
   }

I am getting this error upon using this code

  "message": "Invalid value of \"1\" provided for the regionId field.",
Source Link
Jafar Pinjar
  • 2k
  • 7
  • 70
  • 144

region Id error on updating address using address Id in magneto2

I followed below link to update address using address id

Update customer address using address id in magento 2

I am getting this error upon executing this code

protected $addressRepository;

public function __construct(
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository
 ) {
$this->addressRepository = $addressRepository;
}

public function changeAddress($addressId)
{
  $AddressId = 381993;

if(isset($AddressId) && $AddressId !=''){
            try{
                $address = $this->addressRepository->getById($AddressId);
                $address->setFirstname('test);
                $address->setLastname('test');
                $address->setCountryId('GB');
                $address->setPostcode('t9 1rd');
                $address->setCity($City);
                $this->addressRepository->save($address);
             }catch(\Exception $e){
               print_r($e->getMessage(););
             }
            
            }
   }

I am getting this error upon using this code

  "message": "Invalid value of \"1\" provided for the regionId field.",