Magento2 - Exception occurs when I update customer data using customer repository
-
11-04-2021 - |
Question
Error:
Invalid value of UK provided for the countryId
field.
Error File:
vendor\\magento\\module-customer\\Model\\ResourceModel\\AddressRepository.php
Error line: 133
Code is:
$customer = $this->customerRepository->getById($customer->getId());
$cattrValue = $customer->getCustomAttribute('username');
$customer->setCustomAttribute('username', $customerData['web_username']);
$customer->setFirstname($customerData['first_name']);
$customer->setLastname($customerData['last_name']);
$this->customerRepository->save($customer, $hashedPassword);
Solution
Country ID should be GB. But as you are not upding it the address must already be in the DB. You will have to update UK to GB via direct SQL
http://gist.github.com/pitbulk/ff028a9ba472ed810e54a976d583ef88
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange