I've created a new customer address attribute called 'landline' (required). I've used the code generated by https://mage2gen.com/ which seems 'correct' to me:
- Attribute is correctly created and displayed
- I can save the attribute from the backoffice
However, if I try to create a new address programmatically and set a value for this new attribute, I get the following error:
"Landline" is a required value.
If I create the attribute but it's not required, then the address is generated, but the landline field is empty.
This is the code I use for address generation:
$address = $this->customerAddressFactory->create();
$address->setCustomerId($customerId)
->setFirstname($addressData['firstname'])
->setLastname($addressData['lastname'])
->setCountryId($addressData['country_id'])
->setRegionId($addressData['region_id'])
->setPostcode($addressData['postcode'])
->setCity($addressData['city'])
->setTelephone($addressData['fax'])
->setData('landline', $addressData['telephone'])
->setStreet($addressData['street_array']);
$this->customerAddressRepository->save($address);
As you can see, I'm using 'setData' for landline attribute. If I use: setLandline, the following error is thrown:
Call to undefined method Magento\Customer\Model\Data\Address::setLandline()
How can I save this attribute programmatically? What am I doing wrong? I'm using Magento 2.4.1