1

I have added new custom attributes in my custom module via InstallData.php with following install function content:

/** @var \Magento\Customer\Setup\CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

$attributesInfo = [
    'company_info' => [
        'label' => 'Company Info',
        'type' => 'static',
        'input' => 'textarea',
        'position' => 65,
        'visible' => true,
        'system' => false,
        'user_defined' => false,
        'required' => false,
        'validate_rules' => 'a:1:{s:15:"max_text_length";i:500;}'
    ],
    'telephone_secondary' => [
        'label' => 'Secondary Phone Number',
        'type' => 'static',
        'input' => 'text',
        'position' => 125,
        'visible' => true,
        'system' => false,
        'user_defined' => false,
        'required' => false,
    ]
];

$columns = [
    'company_info' => [
        'type' => Table::TYPE_TEXT,
        'nullable' => true,
        'default' => null,
        'comment' => 'Company Info',
    ],
    'telephone_secondary' => [
        'type' => Table::TYPE_TEXT,
        'nullable' => true,
        'default' => null,
        'length' => 255,
        'comment' => 'Secondary Phone Number',
    ]
];

$tableNames = [
    'customer_address_entity',
    'quote_address',
    'sales_order_address'
];

foreach ($attributesInfo as $attributeCode => $attributeParams) {
    $customerSetup->addAttribute('customer_address', $attributeCode, $attributeParams);
    $customerSetup->getEavConfig()->getAttribute('customer_address', $attributeCode)
        ->setData('attribute_set_id', AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS)
        ->setData('used_in_forms', [
            'customer_address_edit',
            'customer_register_address',
            'adminhtml_customer_address'
        ])
        ->save();
}

$connection = $setup->getConnection();
foreach ($tableNames as $tableName) {
    foreach ($columns as $name => $definition) {
        $connection->addColumn($tableName, $name, $definition);
    }
}

Then I went to checkout and my attributes showed there correctly. But when I went to billing step, values of my custom attributes were not saved into database. Am I doing something wrong?

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.