I am adding two custom address attribute as mobile
and country_code
.
InstallData.php
as below,
<?php
namespace OcraCustomerMobileSetup;
use MagentoEavSetupEavSetup;
use MagentoEavSetupEavSetupFactory;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoEavModelConfig;
use MagentoCustomerModelCustomer;
use MagentoCustomerSetupCustomerSetupFactory;
use MagentoEavModelEntityAttributeSetFactory as AttributeSetFactory;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
private $attributeSetFactory;
private $customerSetupFactory;
public function __construct(
AttributeSetFactory $attributeSetFactory,
CustomerSetupFactory $customerSetupFactory,
EavSetupFactory $eavSetupFactory,
Config $eavConfig
)
{
$this->customerSetupFactory = $customerSetupFactory;
$this->attributeSetFactory = $attributeSetFactory;
$this->eavSetupFactory = $eavSetupFactory;
$this->eavConfig = $eavConfig;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$customerSetup = $this->customerSetupFactory->create(('setup' => $setup));
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(
MagentoCustomerModelCustomer::ENTITY,
'country_code',
(
'type' => 'varchar',
'label' => 'Country Code',
'input' => 'text',
'required' => false,
'visible' => true,
'user_defined' => true,
'position' => 1000,
'system' => 0,
)
);
$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'country_code')
->addData((
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => (
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit',
'checkout_register',
)
));
$attribute->save();
$customerSetup->addAttribute(
MagentoCustomerModelCustomer::ENTITY,
'mobile',
(
'type' => 'varchar',
'label' => 'Mobile',
'input' => 'text',
'required' => false,
'visible' => true,
'user_defined' => true,
'position' => 1001,
'system' => 0,
)
);
$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'mobile')
->addData((
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => (
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit',
'checkout_register',
)
));
$attribute->save();
$customerSetup->addAttribute(
MagentoCustomerModelCustomer::ENTITY,
'is_mobile_verified',
(
'type' => 'int',
'label' => 'Is Mobile Verified?',
'input' => 'select',
'source' => 'OcraCustomerMobileModelConfigSourceOption',
'backend' => 'MagentoEavModelEntityAttributeBackendArrayBackend',
'required' => false,
'visible' => true,
'user_defined' => true,
'position' => 1002,
'system' => 0,
'default' => 2
)
);
$attribute = $customerSetup->getEavConfig()->getAttribute('customer', 'is_mobile_verified')
->addData((
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => (
'adminhtml_customer',
'adminhtml_checkout',
'customer_account_create',
'customer_account_edit',
'checkout_register',
)
));
$attribute->save();
$customerSetup->addAttribute('customer_address', 'country_code', (
'label' => 'Country Code',
'input' => 'varchar',
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'source' => '',
'required' => false,
'position' => 90,
'visible' => true,
'system' => false,
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false,
'is_searchable_in_grid' => false,
'frontend_input' => 'hidden',
'backend' => ''
));
$attribute=$customerSetup->getEavConfig()
->getAttribute('customer_address','country_code')
->addData((
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => (
'adminhtml_customer_address',
'adminhtml_customer',
'customer_address_edit',
'customer_register_address',
'customer_address',
)
));
$attribute->save();
$customerSetup->addAttribute('customer_address', 'mobile', (
'label' => 'Mobile',
'input' => 'varchar',
'type' => MagentoFrameworkDBDdlTable::TYPE_TEXT,
'source' => '',
'required' => false,
'position' => 90,
'visible' => true,
'system' => false,
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false,
'is_searchable_in_grid' => false,
'frontend_input' => 'hidden',
'backend' => ''
));
$attribute=$customerSetup->getEavConfig()
->getAttribute('customer_address','mobile')
->addData((
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => (
'adminhtml_customer_address',
'adminhtml_customer',
'customer_address_edit',
'customer_register_address',
'customer_address',
)
));
$attribute->save();
}
}
After this, if I open New Address
from admin customer edit screen or new customer screen, address form is not loading instead error is created in debug.log
and system.log
as below,
(2021-01-13 11:55:16) main.CRITICAL: TypeError: Argument 2 passed to
MagentoFrameworkViewElementUiComponentFactory::argumentsResolver()
must be of the type array, null given, called in
D:wamp_newwwwmagento_2_4vendormagentoframeworkViewElementUiComponentFactory.php
on line 235 and defined in
D:wamp_newwwwmagento_2_4vendormagentoframeworkViewElementUiComponentFactory.php:183
Stack trace:
#0 D:wamp_newwwwmagento_2_4vendormagentoframeworkViewElementUiComponentFactory.php(235):
MagentoFrameworkViewElementUiComponentFactory->argumentsResolver(‘country_code’,
NULL)
#1 D:wamp_newwwwmagento_2_4vendormagentomodule-uiComponentFormField.php(85):
MagentoFrameworkViewElementUiComponentFactory->create(‘country_code’,
‘varchar’, Array)
#2 D:wamp_newwwwmagento_2_4vendormagentoframeworkViewLayoutGeneratorUiComponent.php(164):
Error on the screen as below,

Where is it going wrong.