Should MagentoEavModelAttributeRepository save 'used_in_forms' attribute value? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Set date value to an attribute in a custom modelMagento2 add custom address attributeModel Override issue in magento 2Magento 2.1.5 How to create Module which can use Eav functionalities (addAttribute in my case)I have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down listUpdate Product programmatically - Invalid method MagentoEavModelEntityAttribute::isScopeGlobalMagento 2 How to upgrade existing custom customer address attribute?Magento2 REST API get all customers detailsmagento 2.2 trying to save multi select value in database

How does TikZ render an arc?

French equivalents of おしゃれは足元から (Every good outfit starts with the shoes)

Flight departed from the gate 5 min before scheduled departure time. Refund options

What did Turing mean when saying that "machines cannot give rise to surprises" is due to a fallacy?

Why not use the yoke to control yaw, as well as pitch and roll?

Where did Ptolemy compare the Earth to the distance of fixed stars?

What does 丫 mean? 丫是什么意思?

When does a function NOT have an antiderivative?

Can gravitational waves pass through a black hole?

An isoperimetric-type inequality inside a cube

Weaponising the Grasp-at-a-Distance spell

Pointing to problems without suggesting solutions

Is a copyright notice with a non-existent name be invalid?

Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?

Does the Rock Gnome trait Artificer's Lore apply when you aren't proficient in History?

Short story about astronauts fertilizing soil with their own bodies

Problem with display of presentation

First paper to introduce the "principal-agent problem"

Why did Bronn offer to be Tyrion Lannister's champion in trial by combat?

.bashrc alias for a command with fixed second parameter

Did John Wesley plagiarize Matthew Henry...?

Fit odd number of triplets in a measure?

Getting representations of the Lie group out of representations of its Lie algebra

Twin's vs. Twins'



Should MagentoEavModelAttributeRepository save 'used_in_forms' attribute value?



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Set date value to an attribute in a custom modelMagento2 add custom address attributeModel Override issue in magento 2Magento 2.1.5 How to create Module which can use Eav functionalities (addAttribute in my case)I have created an extension to show Customer Company Name in Order grid. But when creating new order, order is not showing in order gridMagento offline custom Payment method with drop down listUpdate Product programmatically - Invalid method MagentoEavModelEntityAttribute::isScopeGlobalMagento 2 How to upgrade existing custom customer address attribute?Magento2 REST API get all customers detailsmagento 2.2 trying to save multi select value in database



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I add EAV attribute to a customer address.
I can use MagentoCustomerModelResourceModelAttribute $attributeResource to save the attribute.



According to Magento DevDocs https://devdocs.magento.com/guides/v2.3/extension-dev-guide/attributes.html



/** @var MagentoEavApiDataAttributeInterface $attribute */
$attribute->setData('used_in_forms', ['adminhtml_customer']);
$attributeResource->save($attribute);


It works.



I'm trying to use MagentoEavModelAttributeRepository to save the attribute.



The repository contains a method



 public function save(MagentoEavApiDataAttributeInterface $attribute)
{
try
/** @var MagentoEavModelResourceModelEntityAttribute */
$this->eavResource->save($attribute);
catch (Exception $e)
...



and I see the attribute in eav_attribute database table but there are no records in the table customer_form_attribute.



Maybe someone can explain why?



Code example:



use MagentoCustomerApiAddressMetadataInterface;
use MagentoEavApiAttributeRepositoryInterface;
use MagentoEavModelConfig as EavConfig;
use MagentoEavSetupEavSetupFactory;
use MagentoFrameworkSetupModuleDataSetupInterface;
use MagentoFrameworkSetupPatchDataPatchInterface;

....
/**
* @param ModuleDataSetupInterface $moduleDataSetup
* @param EavSetupFactory $eavSetupFactory
* @param EavConfig $eavConfig
* @param AttributeRepositoryInterface $attributeRepository
*/
public function __construct(
ModuleDataSetupInterface $moduleDataSetup,
EavSetupFactory $eavSetupFactory,
EavConfig $eavConfig,
AttributeRepositoryInterface $attributeRepository
)
$this->eavSetupFactory = $eavSetupFactory;
$this->moduleDataSetup = $moduleDataSetup;
$this->eavConfig = $eavConfig;
$this->attributeRepository = $attributeRepository;


/**
* @inheritdoc
*/
public function apply()

/** @var MagentoEavSetupEavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

$attributeCode = 'test_attribute';

$entityTypeId = AddressMetadataInterface::ENTITY_TYPE_ADDRESS;
$setId = AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS;
$eavSetup->addAttribute($entityTypeId, $attributeCode, [
'type' => 'int',
'input' => 'boolean',
'label' => 'Test attribute',
'required' => 0,
'user_defined' => 1,
'default' => 0,
'system' => 0,
'position' => 60,
]);

$eavSetup->addAttributeToSet($entityTypeId, $setId, null, $attributeCode);

$attribute = $this->eavConfig->getAttribute($entityTypeId, $attributeCode);
$attribute->setData('used_in_forms', [
'adminhtml_customer_address',
'customer_address_edit',
'customer_register_address'
]);

// works. deprecated, I remember
// $attribute->getResource()->save($attribute);

// the attribute is saved, but the information on the forms in which the attribute is added is not saved
$this->attributeRepository->save($attribute);










share|improve this question




























    0















    I add EAV attribute to a customer address.
    I can use MagentoCustomerModelResourceModelAttribute $attributeResource to save the attribute.



    According to Magento DevDocs https://devdocs.magento.com/guides/v2.3/extension-dev-guide/attributes.html



    /** @var MagentoEavApiDataAttributeInterface $attribute */
    $attribute->setData('used_in_forms', ['adminhtml_customer']);
    $attributeResource->save($attribute);


    It works.



    I'm trying to use MagentoEavModelAttributeRepository to save the attribute.



    The repository contains a method



     public function save(MagentoEavApiDataAttributeInterface $attribute)
    {
    try
    /** @var MagentoEavModelResourceModelEntityAttribute */
    $this->eavResource->save($attribute);
    catch (Exception $e)
    ...



    and I see the attribute in eav_attribute database table but there are no records in the table customer_form_attribute.



    Maybe someone can explain why?



    Code example:



    use MagentoCustomerApiAddressMetadataInterface;
    use MagentoEavApiAttributeRepositoryInterface;
    use MagentoEavModelConfig as EavConfig;
    use MagentoEavSetupEavSetupFactory;
    use MagentoFrameworkSetupModuleDataSetupInterface;
    use MagentoFrameworkSetupPatchDataPatchInterface;

    ....
    /**
    * @param ModuleDataSetupInterface $moduleDataSetup
    * @param EavSetupFactory $eavSetupFactory
    * @param EavConfig $eavConfig
    * @param AttributeRepositoryInterface $attributeRepository
    */
    public function __construct(
    ModuleDataSetupInterface $moduleDataSetup,
    EavSetupFactory $eavSetupFactory,
    EavConfig $eavConfig,
    AttributeRepositoryInterface $attributeRepository
    )
    $this->eavSetupFactory = $eavSetupFactory;
    $this->moduleDataSetup = $moduleDataSetup;
    $this->eavConfig = $eavConfig;
    $this->attributeRepository = $attributeRepository;


    /**
    * @inheritdoc
    */
    public function apply()

    /** @var MagentoEavSetupEavSetup $eavSetup */
    $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

    $attributeCode = 'test_attribute';

    $entityTypeId = AddressMetadataInterface::ENTITY_TYPE_ADDRESS;
    $setId = AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS;
    $eavSetup->addAttribute($entityTypeId, $attributeCode, [
    'type' => 'int',
    'input' => 'boolean',
    'label' => 'Test attribute',
    'required' => 0,
    'user_defined' => 1,
    'default' => 0,
    'system' => 0,
    'position' => 60,
    ]);

    $eavSetup->addAttributeToSet($entityTypeId, $setId, null, $attributeCode);

    $attribute = $this->eavConfig->getAttribute($entityTypeId, $attributeCode);
    $attribute->setData('used_in_forms', [
    'adminhtml_customer_address',
    'customer_address_edit',
    'customer_register_address'
    ]);

    // works. deprecated, I remember
    // $attribute->getResource()->save($attribute);

    // the attribute is saved, but the information on the forms in which the attribute is added is not saved
    $this->attributeRepository->save($attribute);










    share|improve this question
























      0












      0








      0








      I add EAV attribute to a customer address.
      I can use MagentoCustomerModelResourceModelAttribute $attributeResource to save the attribute.



      According to Magento DevDocs https://devdocs.magento.com/guides/v2.3/extension-dev-guide/attributes.html



      /** @var MagentoEavApiDataAttributeInterface $attribute */
      $attribute->setData('used_in_forms', ['adminhtml_customer']);
      $attributeResource->save($attribute);


      It works.



      I'm trying to use MagentoEavModelAttributeRepository to save the attribute.



      The repository contains a method



       public function save(MagentoEavApiDataAttributeInterface $attribute)
      {
      try
      /** @var MagentoEavModelResourceModelEntityAttribute */
      $this->eavResource->save($attribute);
      catch (Exception $e)
      ...



      and I see the attribute in eav_attribute database table but there are no records in the table customer_form_attribute.



      Maybe someone can explain why?



      Code example:



      use MagentoCustomerApiAddressMetadataInterface;
      use MagentoEavApiAttributeRepositoryInterface;
      use MagentoEavModelConfig as EavConfig;
      use MagentoEavSetupEavSetupFactory;
      use MagentoFrameworkSetupModuleDataSetupInterface;
      use MagentoFrameworkSetupPatchDataPatchInterface;

      ....
      /**
      * @param ModuleDataSetupInterface $moduleDataSetup
      * @param EavSetupFactory $eavSetupFactory
      * @param EavConfig $eavConfig
      * @param AttributeRepositoryInterface $attributeRepository
      */
      public function __construct(
      ModuleDataSetupInterface $moduleDataSetup,
      EavSetupFactory $eavSetupFactory,
      EavConfig $eavConfig,
      AttributeRepositoryInterface $attributeRepository
      )
      $this->eavSetupFactory = $eavSetupFactory;
      $this->moduleDataSetup = $moduleDataSetup;
      $this->eavConfig = $eavConfig;
      $this->attributeRepository = $attributeRepository;


      /**
      * @inheritdoc
      */
      public function apply()

      /** @var MagentoEavSetupEavSetup $eavSetup */
      $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

      $attributeCode = 'test_attribute';

      $entityTypeId = AddressMetadataInterface::ENTITY_TYPE_ADDRESS;
      $setId = AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS;
      $eavSetup->addAttribute($entityTypeId, $attributeCode, [
      'type' => 'int',
      'input' => 'boolean',
      'label' => 'Test attribute',
      'required' => 0,
      'user_defined' => 1,
      'default' => 0,
      'system' => 0,
      'position' => 60,
      ]);

      $eavSetup->addAttributeToSet($entityTypeId, $setId, null, $attributeCode);

      $attribute = $this->eavConfig->getAttribute($entityTypeId, $attributeCode);
      $attribute->setData('used_in_forms', [
      'adminhtml_customer_address',
      'customer_address_edit',
      'customer_register_address'
      ]);

      // works. deprecated, I remember
      // $attribute->getResource()->save($attribute);

      // the attribute is saved, but the information on the forms in which the attribute is added is not saved
      $this->attributeRepository->save($attribute);










      share|improve this question














      I add EAV attribute to a customer address.
      I can use MagentoCustomerModelResourceModelAttribute $attributeResource to save the attribute.



      According to Magento DevDocs https://devdocs.magento.com/guides/v2.3/extension-dev-guide/attributes.html



      /** @var MagentoEavApiDataAttributeInterface $attribute */
      $attribute->setData('used_in_forms', ['adminhtml_customer']);
      $attributeResource->save($attribute);


      It works.



      I'm trying to use MagentoEavModelAttributeRepository to save the attribute.



      The repository contains a method



       public function save(MagentoEavApiDataAttributeInterface $attribute)
      {
      try
      /** @var MagentoEavModelResourceModelEntityAttribute */
      $this->eavResource->save($attribute);
      catch (Exception $e)
      ...



      and I see the attribute in eav_attribute database table but there are no records in the table customer_form_attribute.



      Maybe someone can explain why?



      Code example:



      use MagentoCustomerApiAddressMetadataInterface;
      use MagentoEavApiAttributeRepositoryInterface;
      use MagentoEavModelConfig as EavConfig;
      use MagentoEavSetupEavSetupFactory;
      use MagentoFrameworkSetupModuleDataSetupInterface;
      use MagentoFrameworkSetupPatchDataPatchInterface;

      ....
      /**
      * @param ModuleDataSetupInterface $moduleDataSetup
      * @param EavSetupFactory $eavSetupFactory
      * @param EavConfig $eavConfig
      * @param AttributeRepositoryInterface $attributeRepository
      */
      public function __construct(
      ModuleDataSetupInterface $moduleDataSetup,
      EavSetupFactory $eavSetupFactory,
      EavConfig $eavConfig,
      AttributeRepositoryInterface $attributeRepository
      )
      $this->eavSetupFactory = $eavSetupFactory;
      $this->moduleDataSetup = $moduleDataSetup;
      $this->eavConfig = $eavConfig;
      $this->attributeRepository = $attributeRepository;


      /**
      * @inheritdoc
      */
      public function apply()

      /** @var MagentoEavSetupEavSetup $eavSetup */
      $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

      $attributeCode = 'test_attribute';

      $entityTypeId = AddressMetadataInterface::ENTITY_TYPE_ADDRESS;
      $setId = AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS;
      $eavSetup->addAttribute($entityTypeId, $attributeCode, [
      'type' => 'int',
      'input' => 'boolean',
      'label' => 'Test attribute',
      'required' => 0,
      'user_defined' => 1,
      'default' => 0,
      'system' => 0,
      'position' => 60,
      ]);

      $eavSetup->addAttributeToSet($entityTypeId, $setId, null, $attributeCode);

      $attribute = $this->eavConfig->getAttribute($entityTypeId, $attributeCode);
      $attribute->setData('used_in_forms', [
      'adminhtml_customer_address',
      'customer_address_edit',
      'customer_register_address'
      ]);

      // works. deprecated, I remember
      // $attribute->getResource()->save($attribute);

      // the attribute is saved, but the information on the forms in which the attribute is added is not saved
      $this->attributeRepository->save($attribute);







      magento2 eav eav-attributes repository






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Boris RuvinskyBoris Ruvinsky

      457




      457




















          0






          active

          oldest

          votes












          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%2f270757%2fshould-magento-eav-model-attributerepository-save-used-in-forms-attribute-valu%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          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%2f270757%2fshould-magento-eav-model-attributerepository-save-used-in-forms-attribute-valu%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

          Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

          Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

          Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?