I added one attribute using this code but when I try to add another attribute then it is not working
why?
<?php
namespace Icore\Module\Setup;
use Magento\Customer\Model\Customer;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements \Magento\Framework\Setup\InstallDataInterface
{
private $eavSetupFactory;
private $eavConfig;
private $attributeResource;
public function __construct(
\Magento\Eav\Setup\EavSetupFactory $eavSetupFactory,
\Magento\Eav\Model\Config $eavConfig,
\Magento\Customer\Model\ResourceModel\Attribute $attributeResource
) {
$this->eavSetupFactory = $eavSetupFactory;
$this->eavConfig = $eavConfig;
$this->attributeResource = $attributeResource;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->removeAttribute(Customer::ENTITY, "skype");
$attributeSetId = $eavSetup->getDefaultAttributeSetId(Customer::ENTITY);
$attributeGroupId = $eavSetup->getDefaultAttributeGroupId(Customer::ENTITY);
$eavSetup->addAttribute(Customer::ENTITY, 'skype', [
// Attribute parameters
'type' => 'varchar',
'label' => 'Skype Account',
'input' => 'text',
'required' => false,
'visible' => true,
'user_defined' => true,
'sort_order' => 990,
'position' => 990,
'system' => 0,
]);
$attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'skype');
$attribute->setData('attribute_set_id', $attributeSetId);
$attribute->setData('attribute_group_id', $attributeGroupId);
$eavSetup->removeAttribute(Customer::ENTITY, "bussiness");
$attributeSetId = $eavSetup->getDefaultAttributeSetId(Customer::ENTITY);
$attributeGroupId = $eavSetup->getDefaultAttributeGroupId(Customer::ENTITY);
$eavSetup->addAttribute(Customer::ENTITY, 'bussiness', [
// Attribute parameters
'type' => 'varchar',
'label' => 'Check',
'input' => 'text',
'required' => false,
'visible' => true,
'user_defined' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
]);
$attribute = $this->eavConfig->getAttribute(Customer::ENTITY, 'bussiness');
$attribute->setData('attribute_set_id', $attributeSetId);
$attribute->setData('attribute_group_id', $attributeGroupId);
/*
//You can use this attribute in the following forms
adminhtml_checkout
adminhtml_customer
adminhtml_customer_address
customer_account_create
customer_account_edit
customer_address_edit
customer_register_address
*/
$attribute->setData('used_in_forms', [
'adminhtml_customer',
'customer_account_create',
'customer_account_edit'
]);
$this->attributeResource->save($attribute);
}
}
?>
also added addtional.phtml but not showing in registration form Magento 2 (Only showing "skype account")
<div class="field skype required">
<label class="label" for="skype">
<span><?= $block->escapeHtml(__('Skype Account')) ?></span>
</label>
<div class="control">
<input type="text" name="skype" id="skype" value="" title="<?= $block->escapeHtmlAttr(__('Skype Account')) ?>" class="input-text" data-validate="{required:false}">
</div>
</div>
<div class="field skype required">
<label class="label" for="skype2">
<span><?= $block->escapeHtml(__('Check')) ?></span>
</label>
<div class="control">
<input type="text" name="skype2" id="skype2" value="" title="<?= $block->escapeHtmlAttr(__('Check')) ?>" class="input-text" data-validate="{required:false}">
</div>
</div>
<div class="field tcagreecreateaccount required">
<div class="control">
<input type="checkbox" id="tcagreecreateaccount" name="tcagreecreateaccount" data-validate="{required:true}" class="input-checkbox checkbox required" value="1">
<label for="tcagreecreateaccount" class="label">
<?= __('Custom T&C') ?>
</label>
</div>
</div>
Any Idea? Please help!