How to add a customer custom-attribute in the customer address edit form?












19















I added a customer custom attribute as customer_address type and it runs correctly in the admin and in onepagecheckout as well as in shipping & billing address.



I created:
my_namespace/my_module/etc/module.xml and registration.php composer.json files in the module base directory.



my_namespace/my_module/Setup/InstallData.php



namespace NamespaceModuleSetup;

use MagentoFrameworkModuleSetupMigration;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* Customer setup factory
*
* @var CustomerSetupFactory
*/
private $customerSetupFactory;

/**
* Init
*
* @param CustomerSetupFactory $customerSetupFactory
*/
public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)
{
$this->customerSetupFactory = $customerSetupFactory;
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

$setup->startSetup();

// insert attribute
$customerSetup->addAttribute('customer_address', 'attr_code', [
'label' => 'My attribute',
'type' => 'varchar',
'input' => 'text',
'position' => 45,
'visible' => true,
'required' => false,
'system' => 0
]);

$MyAttribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'attr_code');
$MyAttribute->setData(
'used_in_forms',
['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
);
$MyAttribute->save();

$setup->endSetup();
}
}


Now I need to add attribute field in the customer add and edit address form that are related to the file magento_customer/view/frontend/templates/address/edit.phtml



I added the field but I'm not able to get and save the value of that attribute.










share|improve this question

























  • which magento version?

    – Sohel Rana
    Jul 12 '16 at 7:01











  • magento CE 2.1.0

    – Ale
    Aug 11 '16 at 9:00











  • Hi Ale, Can you please share your working code for custom customer address attribute. I also need to add same functionality.

    – Rahul
    May 13 '17 at 9:20


















19















I added a customer custom attribute as customer_address type and it runs correctly in the admin and in onepagecheckout as well as in shipping & billing address.



I created:
my_namespace/my_module/etc/module.xml and registration.php composer.json files in the module base directory.



my_namespace/my_module/Setup/InstallData.php



namespace NamespaceModuleSetup;

use MagentoFrameworkModuleSetupMigration;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* Customer setup factory
*
* @var CustomerSetupFactory
*/
private $customerSetupFactory;

/**
* Init
*
* @param CustomerSetupFactory $customerSetupFactory
*/
public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)
{
$this->customerSetupFactory = $customerSetupFactory;
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

$setup->startSetup();

// insert attribute
$customerSetup->addAttribute('customer_address', 'attr_code', [
'label' => 'My attribute',
'type' => 'varchar',
'input' => 'text',
'position' => 45,
'visible' => true,
'required' => false,
'system' => 0
]);

$MyAttribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'attr_code');
$MyAttribute->setData(
'used_in_forms',
['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
);
$MyAttribute->save();

$setup->endSetup();
}
}


Now I need to add attribute field in the customer add and edit address form that are related to the file magento_customer/view/frontend/templates/address/edit.phtml



I added the field but I'm not able to get and save the value of that attribute.










share|improve this question

























  • which magento version?

    – Sohel Rana
    Jul 12 '16 at 7:01











  • magento CE 2.1.0

    – Ale
    Aug 11 '16 at 9:00











  • Hi Ale, Can you please share your working code for custom customer address attribute. I also need to add same functionality.

    – Rahul
    May 13 '17 at 9:20
















19












19








19


4






I added a customer custom attribute as customer_address type and it runs correctly in the admin and in onepagecheckout as well as in shipping & billing address.



I created:
my_namespace/my_module/etc/module.xml and registration.php composer.json files in the module base directory.



my_namespace/my_module/Setup/InstallData.php



namespace NamespaceModuleSetup;

use MagentoFrameworkModuleSetupMigration;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* Customer setup factory
*
* @var CustomerSetupFactory
*/
private $customerSetupFactory;

/**
* Init
*
* @param CustomerSetupFactory $customerSetupFactory
*/
public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)
{
$this->customerSetupFactory = $customerSetupFactory;
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

$setup->startSetup();

// insert attribute
$customerSetup->addAttribute('customer_address', 'attr_code', [
'label' => 'My attribute',
'type' => 'varchar',
'input' => 'text',
'position' => 45,
'visible' => true,
'required' => false,
'system' => 0
]);

$MyAttribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'attr_code');
$MyAttribute->setData(
'used_in_forms',
['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
);
$MyAttribute->save();

$setup->endSetup();
}
}


Now I need to add attribute field in the customer add and edit address form that are related to the file magento_customer/view/frontend/templates/address/edit.phtml



I added the field but I'm not able to get and save the value of that attribute.










share|improve this question
















I added a customer custom attribute as customer_address type and it runs correctly in the admin and in onepagecheckout as well as in shipping & billing address.



I created:
my_namespace/my_module/etc/module.xml and registration.php composer.json files in the module base directory.



my_namespace/my_module/Setup/InstallData.php



namespace NamespaceModuleSetup;

use MagentoFrameworkModuleSetupMigration;
use MagentoFrameworkSetupInstallDataInterface;
use MagentoFrameworkSetupModuleContextInterface;
use MagentoFrameworkSetupModuleDataSetupInterface;

/**
* @codeCoverageIgnore
*/
class InstallData implements InstallDataInterface
{
/**
* Customer setup factory
*
* @var CustomerSetupFactory
*/
private $customerSetupFactory;

/**
* Init
*
* @param CustomerSetupFactory $customerSetupFactory
*/
public function __construct(MagentoCustomerSetupCustomerSetupFactory $customerSetupFactory)
{
$this->customerSetupFactory = $customerSetupFactory;
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);

$setup->startSetup();

// insert attribute
$customerSetup->addAttribute('customer_address', 'attr_code', [
'label' => 'My attribute',
'type' => 'varchar',
'input' => 'text',
'position' => 45,
'visible' => true,
'required' => false,
'system' => 0
]);

$MyAttribute = $customerSetup->getEavConfig()->getAttribute('customer_address', 'attr_code');
$MyAttribute->setData(
'used_in_forms',
['adminhtml_customer_address', 'customer_address_edit', 'customer_register_address']
);
$MyAttribute->save();

$setup->endSetup();
}
}


Now I need to add attribute field in the customer add and edit address form that are related to the file magento_customer/view/frontend/templates/address/edit.phtml



I added the field but I'm not able to get and save the value of that attribute.







magento2 attributes custom-attributes customer-address






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago









Rafael Corrêa Gomes

4,43223063




4,43223063










asked Jul 11 '16 at 13:52









AleAle

106116




106116













  • which magento version?

    – Sohel Rana
    Jul 12 '16 at 7:01











  • magento CE 2.1.0

    – Ale
    Aug 11 '16 at 9:00











  • Hi Ale, Can you please share your working code for custom customer address attribute. I also need to add same functionality.

    – Rahul
    May 13 '17 at 9:20





















  • which magento version?

    – Sohel Rana
    Jul 12 '16 at 7:01











  • magento CE 2.1.0

    – Ale
    Aug 11 '16 at 9:00











  • Hi Ale, Can you please share your working code for custom customer address attribute. I also need to add same functionality.

    – Rahul
    May 13 '17 at 9:20



















which magento version?

– Sohel Rana
Jul 12 '16 at 7:01





which magento version?

– Sohel Rana
Jul 12 '16 at 7:01













magento CE 2.1.0

– Ale
Aug 11 '16 at 9:00





magento CE 2.1.0

– Ale
Aug 11 '16 at 9:00













Hi Ale, Can you please share your working code for custom customer address attribute. I also need to add same functionality.

– Rahul
May 13 '17 at 9:20







Hi Ale, Can you please share your working code for custom customer address attribute. I also need to add same functionality.

– Rahul
May 13 '17 at 9:20












2 Answers
2






active

oldest

votes


















7














Custom customer attributes will never just 'appear' on the frontend like they do in the backend. The code that displays them on the frontend is located in a custom phtml file.



Magento EE has this functionality built in. I'm not suggesting you NEED to spend that money, I'm just saying it has it. If you want to go ahead and attempt to add custom attributes, it's somewhat complex.



First of all, you must do all of this in a module or it just isn't going to work right, and it's going to be hard to debug/upgrade later.



You have to do these things:




  • Create the attribute (you've done this if it shows up in admin)

  • override the frontend layout for referenceContainer form.additional.info

  • add a template phtml file to show the additional attribute(s)

  • add a block PHP file to load the new attributes and create the HTML

  • other things like learn how to automate the process and load multiples instead of hard coding it to load just the name of the one you created.


You can load your custom attributes in the Block PHP. Then just add your layout to the customer_account_create.xml like this:



<?xml version="1.0"?>

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="customer_form_template_handle"/>
<body>
<referenceContainer name="form.additional.info">
<block class="CompanyCustomformattributesBlockFormCustomer" template="Company_Customformattributes::customattributes.phtml" name="customer_form_user_attributes" cacheable="false">
<action method="setFormCode">
<argument name="code" xsi:type="string">customer_account_edit</argument>
</action>
<action method="setEntityModelClass">
<argument name="code" xsi:type="string">MagentoCustomerModelCustomer</argument>
</action>
</block>
</referenceContainer>
</body>
</page>


This is the magic sauce to get your block PHP to load, to get your phtml to load, and to get it into the correct page.



This isn't a full answer honestly, there is a lot more to it, but you get the basic idea.






share|improve this answer


























  • can you please complete your answer? what you have entered in block and template file?

    – chirag
    Feb 10 '17 at 5:20











  • setEntityModelClass action can automatically save our attribute or we need to write code for saving attribute also?

    – siddhesh
    Jul 19 '17 at 15:59



















1














Cannot answer your question, because there is not enough code provided, but have a little advice. Did you check this tutorial Adding customer attirbute tutorial ?



Since Magento 2.1 there is a change and methods ->save() are deprecated.
You should start using Repositories instead.
For example for customer EAV you should use



MagentoEavModelAttributeRepository



In your case, second part of script should be changed to



/** MagentoEavModelAttributeRepository $attributeRepository */
$attributeRepository->save($MyAttribute);





share|improve this answer

























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f125194%2fhow-to-add-a-customer-custom-attribute-in-the-customer-address-edit-form%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    7














    Custom customer attributes will never just 'appear' on the frontend like they do in the backend. The code that displays them on the frontend is located in a custom phtml file.



    Magento EE has this functionality built in. I'm not suggesting you NEED to spend that money, I'm just saying it has it. If you want to go ahead and attempt to add custom attributes, it's somewhat complex.



    First of all, you must do all of this in a module or it just isn't going to work right, and it's going to be hard to debug/upgrade later.



    You have to do these things:




    • Create the attribute (you've done this if it shows up in admin)

    • override the frontend layout for referenceContainer form.additional.info

    • add a template phtml file to show the additional attribute(s)

    • add a block PHP file to load the new attributes and create the HTML

    • other things like learn how to automate the process and load multiples instead of hard coding it to load just the name of the one you created.


    You can load your custom attributes in the Block PHP. Then just add your layout to the customer_account_create.xml like this:



    <?xml version="1.0"?>

    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="customer_form_template_handle"/>
    <body>
    <referenceContainer name="form.additional.info">
    <block class="CompanyCustomformattributesBlockFormCustomer" template="Company_Customformattributes::customattributes.phtml" name="customer_form_user_attributes" cacheable="false">
    <action method="setFormCode">
    <argument name="code" xsi:type="string">customer_account_edit</argument>
    </action>
    <action method="setEntityModelClass">
    <argument name="code" xsi:type="string">MagentoCustomerModelCustomer</argument>
    </action>
    </block>
    </referenceContainer>
    </body>
    </page>


    This is the magic sauce to get your block PHP to load, to get your phtml to load, and to get it into the correct page.



    This isn't a full answer honestly, there is a lot more to it, but you get the basic idea.






    share|improve this answer


























    • can you please complete your answer? what you have entered in block and template file?

      – chirag
      Feb 10 '17 at 5:20











    • setEntityModelClass action can automatically save our attribute or we need to write code for saving attribute also?

      – siddhesh
      Jul 19 '17 at 15:59
















    7














    Custom customer attributes will never just 'appear' on the frontend like they do in the backend. The code that displays them on the frontend is located in a custom phtml file.



    Magento EE has this functionality built in. I'm not suggesting you NEED to spend that money, I'm just saying it has it. If you want to go ahead and attempt to add custom attributes, it's somewhat complex.



    First of all, you must do all of this in a module or it just isn't going to work right, and it's going to be hard to debug/upgrade later.



    You have to do these things:




    • Create the attribute (you've done this if it shows up in admin)

    • override the frontend layout for referenceContainer form.additional.info

    • add a template phtml file to show the additional attribute(s)

    • add a block PHP file to load the new attributes and create the HTML

    • other things like learn how to automate the process and load multiples instead of hard coding it to load just the name of the one you created.


    You can load your custom attributes in the Block PHP. Then just add your layout to the customer_account_create.xml like this:



    <?xml version="1.0"?>

    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="customer_form_template_handle"/>
    <body>
    <referenceContainer name="form.additional.info">
    <block class="CompanyCustomformattributesBlockFormCustomer" template="Company_Customformattributes::customattributes.phtml" name="customer_form_user_attributes" cacheable="false">
    <action method="setFormCode">
    <argument name="code" xsi:type="string">customer_account_edit</argument>
    </action>
    <action method="setEntityModelClass">
    <argument name="code" xsi:type="string">MagentoCustomerModelCustomer</argument>
    </action>
    </block>
    </referenceContainer>
    </body>
    </page>


    This is the magic sauce to get your block PHP to load, to get your phtml to load, and to get it into the correct page.



    This isn't a full answer honestly, there is a lot more to it, but you get the basic idea.






    share|improve this answer


























    • can you please complete your answer? what you have entered in block and template file?

      – chirag
      Feb 10 '17 at 5:20











    • setEntityModelClass action can automatically save our attribute or we need to write code for saving attribute also?

      – siddhesh
      Jul 19 '17 at 15:59














    7












    7








    7







    Custom customer attributes will never just 'appear' on the frontend like they do in the backend. The code that displays them on the frontend is located in a custom phtml file.



    Magento EE has this functionality built in. I'm not suggesting you NEED to spend that money, I'm just saying it has it. If you want to go ahead and attempt to add custom attributes, it's somewhat complex.



    First of all, you must do all of this in a module or it just isn't going to work right, and it's going to be hard to debug/upgrade later.



    You have to do these things:




    • Create the attribute (you've done this if it shows up in admin)

    • override the frontend layout for referenceContainer form.additional.info

    • add a template phtml file to show the additional attribute(s)

    • add a block PHP file to load the new attributes and create the HTML

    • other things like learn how to automate the process and load multiples instead of hard coding it to load just the name of the one you created.


    You can load your custom attributes in the Block PHP. Then just add your layout to the customer_account_create.xml like this:



    <?xml version="1.0"?>

    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="customer_form_template_handle"/>
    <body>
    <referenceContainer name="form.additional.info">
    <block class="CompanyCustomformattributesBlockFormCustomer" template="Company_Customformattributes::customattributes.phtml" name="customer_form_user_attributes" cacheable="false">
    <action method="setFormCode">
    <argument name="code" xsi:type="string">customer_account_edit</argument>
    </action>
    <action method="setEntityModelClass">
    <argument name="code" xsi:type="string">MagentoCustomerModelCustomer</argument>
    </action>
    </block>
    </referenceContainer>
    </body>
    </page>


    This is the magic sauce to get your block PHP to load, to get your phtml to load, and to get it into the correct page.



    This isn't a full answer honestly, there is a lot more to it, but you get the basic idea.






    share|improve this answer















    Custom customer attributes will never just 'appear' on the frontend like they do in the backend. The code that displays them on the frontend is located in a custom phtml file.



    Magento EE has this functionality built in. I'm not suggesting you NEED to spend that money, I'm just saying it has it. If you want to go ahead and attempt to add custom attributes, it's somewhat complex.



    First of all, you must do all of this in a module or it just isn't going to work right, and it's going to be hard to debug/upgrade later.



    You have to do these things:




    • Create the attribute (you've done this if it shows up in admin)

    • override the frontend layout for referenceContainer form.additional.info

    • add a template phtml file to show the additional attribute(s)

    • add a block PHP file to load the new attributes and create the HTML

    • other things like learn how to automate the process and load multiples instead of hard coding it to load just the name of the one you created.


    You can load your custom attributes in the Block PHP. Then just add your layout to the customer_account_create.xml like this:



    <?xml version="1.0"?>

    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <update handle="customer_form_template_handle"/>
    <body>
    <referenceContainer name="form.additional.info">
    <block class="CompanyCustomformattributesBlockFormCustomer" template="Company_Customformattributes::customattributes.phtml" name="customer_form_user_attributes" cacheable="false">
    <action method="setFormCode">
    <argument name="code" xsi:type="string">customer_account_edit</argument>
    </action>
    <action method="setEntityModelClass">
    <argument name="code" xsi:type="string">MagentoCustomerModelCustomer</argument>
    </action>
    </block>
    </referenceContainer>
    </body>
    </page>


    This is the magic sauce to get your block PHP to load, to get your phtml to load, and to get it into the correct page.



    This isn't a full answer honestly, there is a lot more to it, but you get the basic idea.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 hours ago









    Rafael Corrêa Gomes

    4,43223063




    4,43223063










    answered Jul 12 '16 at 12:41









    CarCompCarComp

    8301026




    8301026













    • can you please complete your answer? what you have entered in block and template file?

      – chirag
      Feb 10 '17 at 5:20











    • setEntityModelClass action can automatically save our attribute or we need to write code for saving attribute also?

      – siddhesh
      Jul 19 '17 at 15:59



















    • can you please complete your answer? what you have entered in block and template file?

      – chirag
      Feb 10 '17 at 5:20











    • setEntityModelClass action can automatically save our attribute or we need to write code for saving attribute also?

      – siddhesh
      Jul 19 '17 at 15:59

















    can you please complete your answer? what you have entered in block and template file?

    – chirag
    Feb 10 '17 at 5:20





    can you please complete your answer? what you have entered in block and template file?

    – chirag
    Feb 10 '17 at 5:20













    setEntityModelClass action can automatically save our attribute or we need to write code for saving attribute also?

    – siddhesh
    Jul 19 '17 at 15:59





    setEntityModelClass action can automatically save our attribute or we need to write code for saving attribute also?

    – siddhesh
    Jul 19 '17 at 15:59













    1














    Cannot answer your question, because there is not enough code provided, but have a little advice. Did you check this tutorial Adding customer attirbute tutorial ?



    Since Magento 2.1 there is a change and methods ->save() are deprecated.
    You should start using Repositories instead.
    For example for customer EAV you should use



    MagentoEavModelAttributeRepository



    In your case, second part of script should be changed to



    /** MagentoEavModelAttributeRepository $attributeRepository */
    $attributeRepository->save($MyAttribute);





    share|improve this answer






























      1














      Cannot answer your question, because there is not enough code provided, but have a little advice. Did you check this tutorial Adding customer attirbute tutorial ?



      Since Magento 2.1 there is a change and methods ->save() are deprecated.
      You should start using Repositories instead.
      For example for customer EAV you should use



      MagentoEavModelAttributeRepository



      In your case, second part of script should be changed to



      /** MagentoEavModelAttributeRepository $attributeRepository */
      $attributeRepository->save($MyAttribute);





      share|improve this answer




























        1












        1








        1







        Cannot answer your question, because there is not enough code provided, but have a little advice. Did you check this tutorial Adding customer attirbute tutorial ?



        Since Magento 2.1 there is a change and methods ->save() are deprecated.
        You should start using Repositories instead.
        For example for customer EAV you should use



        MagentoEavModelAttributeRepository



        In your case, second part of script should be changed to



        /** MagentoEavModelAttributeRepository $attributeRepository */
        $attributeRepository->save($MyAttribute);





        share|improve this answer















        Cannot answer your question, because there is not enough code provided, but have a little advice. Did you check this tutorial Adding customer attirbute tutorial ?



        Since Magento 2.1 there is a change and methods ->save() are deprecated.
        You should start using Repositories instead.
        For example for customer EAV you should use



        MagentoEavModelAttributeRepository



        In your case, second part of script should be changed to



        /** MagentoEavModelAttributeRepository $attributeRepository */
        $attributeRepository->save($MyAttribute);






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jul 12 '16 at 11:30









        Rushvi

        2,4291830




        2,4291830










        answered Jul 12 '16 at 11:08









        pietrpietr

        594




        594






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f125194%2fhow-to-add-a-customer-custom-attribute-in-the-customer-address-edit-form%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Magento 2 controller redirect on button click in phtml file

            Polycentropodidae