I'm trying to add a custom text field to the edit account information page on frontend customer dashboard, so i tried to create a module like this in
VendorName\ModuleName\Setup\InstallData.php
namespace VendorName\ModuleName\Setup;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* EAV setup factory
*
* @var EavSetupFactory
*/
private $eavSetupFactory;
/**
* Init
*
* @param EavSetupFactory $eavSetupFactory
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
if (version_compare($context->getVersion(), '1.0.0') < 0){
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSetup = $objectManager->create('Wetag\InvoiceEmail\Setup\CustomerSetup');
$customerSetup->installAttributes($customerSetup);
}
}
And in
VendorName\ModuleName\Setup\CustomerSetup.php
<?php
namespace VendorName\ModuleName\Setup;
use Magento\Eav\Model\Config;
use Magento\Eav\Model\Entity\Setup\Context;
use Magento\Eav\Setup\EavSetup;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory;
class CustomerSetup extends EavSetup {
protected $eavConfig;
public function __construct(
ModuleDataSetupInterface $setup,
Context $context,
CacheInterface $cache,
CollectionFactory $attrGroupCollectionFactory,
Config $eavConfig
) {
$this -> eavConfig = $eavConfig;
parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);
}
public function installAttributes($customerSetup) {
$this -> installCustomerAttributes($customerSetup);
$this -> installCustomerAddressAttributes($customerSetup);
}
public function installCustomerAttributes($customerSetup) {
$customerSetup -> addAttribute(\Magento\Customer\Model\Customer::ENTITY,
'invoice_email',
[
'label' => 'invoice email',
'system' => 0,
'position' => 100,
'sort_order' =>100,
'visible' => true,
'note' => '',
'type' => 'varchar',
'input' => 'text',
]
);
$customerSetup -> getEavConfig() -> getAttribute('customer', 'invoice_email')->setData('is_user_defined',1)->setData('is_required',0)->setData('default_value','')->setData('used_in_forms', ['customer_account_edit']) -> save();
}
public function installCustomerAddressAttributes($customerSetup) {
}
public function getEavConfig() {
return $this -> eavConfig;
}
}
The attribute is added on backend but not on frontend, I saw a post saying to override Magento template, so how to do it, if some one give me the steps to follow to display the field on customer account edit page on front.