I have the following code to create a custom customer attribute.
<?php
namespace Vendor\MyModule\Setup\Patch\Data;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Customer\Setup\Patch\Data\UpdateIdentifierCustomerAttributesVisibility;
class AddCustomerAccountCode implements DataPatchInterface
{
private $moduleDataSetup;
private $customerSetupFactory;
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
CustomerSetupFactory $customerSetupFactory
) {
$this->moduleDataSetup = $moduleDataSetup;
$this->customerSetupFactory = $customerSetupFactory;
}
public function apply()
{
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerSetup->addAttribute(Customer::ENTITY, 'customer_account_code', [
'type' => 'varchar',
'label' => 'Account Code',
'input' => 'text',
'sort_order' => 100,
'position' => 100,
'required' => false,
'visible' => true,
'system' => false
]);
}
/**
* {@inheritdoc}
*/
public static function getDependencies()
{
return [
UpdateIdentifierCustomerAttributesVisibility::class,
];
}
public function getAliases()
{
return [];
}
}
The custom attribute is added to the admin form however when I populate the field and save the customer, the data is not saved.
Please could someone point out where I have gone wrong