I followed this article http://www.extensions.sashas.org/blog/magento-2-1-3-how-to-make-customer-attribute-update.html to add 3 attributes this is My Install.php
<?php
namespace Magenticians\CustomerAttribute\Setup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Customer\Model\Customer;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* @var CustomerSetupFactory
*/
protected $customerSetupFactory;
/**
* @var AttributeSetFactory
*/
private $attributeSetFactory;
/**
* @param CustomerSetupFactory $customerSetupFactory
* @param AttributeSetFactory $attributeSetFactory
*/
public function __construct(
CustomerSetupFactory $customerSetupFactory,
AttributeSetFactory $attributeSetFactory
) {
$this->customerSetupFactory = $customerSetupFactory;
$this->attributeSetFactory = $attributeSetFactory;
}
/**
* {@inheritdoc}
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
$customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
$attributeSetId = $customerEntity->getDefaultAttributeSetId();
/** @var $attributeSet AttributeSet */
$attributeSet = $this->attributeSetFactory->create();
$attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
$customerSetup->addAttribute(Customer::ENTITY, 'birth', [
'type' => 'static',
'label' => 'Birth',
'input' => 'date',
'required' => true,
'visible' => true,
'user_defined' => true,
'sort_order' => 1000,
'position' => 1000,
'system' => 0,
]);
$customerSetup->addAttribute(Customer::ENTITY, 'adresse', [
'type' => 'varchar',
'label' => 'Adresse',
'input' => 'text',
'required' => true,
'visible' => true,
'user_defined' => true,
'sort_order' => 1001,
'position' => 1001,
'system' => 0,
]);
$customerSetup->addAttribute(Customer::ENTITY, 'phone', [
'type' => 'varchar',
'label' => 'Phone Number',
'input' => 'text',
'required' => true,
'visible' => true,
'user_defined' => true,
'validate_rules' => '{"max_text_length":255,"min_text_length":1}',
'sort_order' => 1002,
'position' => 1002,
'system' => 0,
]);
$attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'birth')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['customer_account_create'],
]);
$secondattribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'adresse')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['customer_account_create'],
]);
$thirdattribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'phone')
->addData([
'attribute_set_id' => $attributeSetId,
'attribute_group_id' => $attributeGroupId,
'used_in_forms' => ['customer_account_create'],
]);
$attribute->save();
$secondattribute->save();
$thirdattribute->save();
}
}
I also added to register.phtml
<div class="field required">
<label for="adresse" class="label"><span><?php /* @escapeNotVerified */ echo __('Adresse') ?></span></label>
<div class="control">
<input type="text" name="adresse" id="adresse" value="<?php echo $block->escapeHtml($block->getFormData()->getAdresse()) ?>" title="
<?php /* @escapeNotVerified */ echo __('Adresse') ?>" class="input-text">
</div>
</div>
<div class="field required">
<label for="birth" class="label"><span><?php /* @escapeNotVerified */ echo __('Birth') ?></span></label>
<div class="control">
<input type="date" name="birth" id="birth" value="<?php echo $block->escapeHtml($block->getFormData()->getBirth()) ?>" title="
<?php /* @escapeNotVerified */ echo __('Birth') ?>" class="input-text">
</div>
</div>
<div class="field required">
<label for="phone" class="label"><span><?php /* @escapeNotVerified */ echo __('Phone Number') ?></span></label>
<div class="control">
<input type="phone" name="phone" id="phone" value="<?php echo $block->escapeHtml($block->getFormData()->getPhone()) ?>" title="
<?php /* @escapeNotVerified */ echo __('Phone Number') ?>" class="input-text" pattern='[\+]\d{2}[\(]\d{2}[\)]\d{4}[\-]\d{4}' >
</div>
</div>
I got this error when I tried to add new customer:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sajjada_site.customer_entity_date' doesn't exist, query was: DESCRIBE `customer_entity_date`
please help me figure out the problem and thanks in advance.