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

          Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

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

          Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form