I'm trying to add a new Custom attribute to the Magento customer model, and I think that I've set everything up correctly from what I've been able to scour off of this website & google, but I'm just not having any luck with it.
Essentially, the project is about overloading some of the functionality for the Magento Customer module, we want to execute some custom code in & around the Customer saving, loading and authentication functionality.
I'm building all of my interceptors into a custom module which I've successfully vendored into my Dev instance.
This module has an InstallData.php script which does successfully create my Custom Attribute:
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory, Config $eavConfig)
{
$this->eavSetupFactory = $eavSetupFactory;
$this->eavConfig = $eavConfig;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
Customer::ENTITY,
'MSISDN',
[
'type' => 'varchar',
'label' => 'MSISDN',
'input' => 'text',
'required' => true,
'visible' => true,
'user_defined' => true,
'position' => 999,
'system' => 0
]
);
$msisdnAttribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'MSISDN');
$msisdnAttribute->setData(
'used_in_forms',
['adminhtml_customer']
);
$msisdnAttribute->save();
}
Once I've run composer update & php bin/magento setup:upgrade, I can confirm that the custom attribute has been created in the database.
However, when I try to register a new customer using the REST API, following request:
{
"customer": {
"group_id": 1,
"default_billing": "",
"default_shipping": "",
"created_at": "2019-02-05 12:12:12",
"updated_at": "2019-02-05 12:12:12",
"created_in": "dev_store",
"dob": "1981-03-01",
"email": "[email protected]",
"firstname": "User",
"lastname": "Name",
"middlename": "X",
"prefix": "B",
"suffix": "A",
"gender": 1,
"store_id": 1,
"taxvat": "string",
"website_id": 1,
"custom_attributes": [
{
"attribute_code": "MSISDN",
"value": "121314151617"
}
]
},
"password": "TestPassword1234"
}
I get the Error response:
{"message":"\"MSISDN\" is a required value."}
Ultimately, I want to be able to intercept this value before the Customer data model gets saved so that I can execute custom validations & a few other tasks.
Please let me know if I can provide any other info.
Thanks in advance for the help.