How to update product eav attribute in magento 2Magento 2 - How to do get the product attribute code and value associated with product using product id?Magento 2 : How to get attribute group id using attribute set id ?Magento 2 API - Update Product Custom Attribute to Blank/NullMagento 2: Display Custom attribute value under the product name on category pageMagento 2 How to get “custom_atribute” Value in product page when atribute color drop down changes?Magento 2 : Detect change of attribute set on admin product edit page in jsMagento 2: Custom product attribute is missing from products bulk updateHow to fetch product attribute value in phtml file in Magento 2?How to show product custom attribute to invoice email in magento2.2.0?Magento 2 : Product price should be change on custom option select in custom module

If the only attacker is removed from combat, is a creature still counted as having attacked this turn?

Do you waste sorcery points if you try to apply metamagic to a spell from a scroll but fail to cast it?

Using streams for a null-safe conversion from an array to list

Grepping string, but include all non-blank lines following each grep match

Why is the principal energy of an electron lower for excited electrons in a higher energy state?

How many people need to be born every 8 years to sustain population?

Why didn't Voldemort know what Grindelwald looked like?

What should be the ideal length of sentences in a blog post for ease of reading?

Review your own paper in Mathematics

How to leave product feedback on macOS?

If Captain Marvel (MCU) were to have a child with a human male, would the child be human or Kree?

Integral Notations in Quantum Mechanics

When and why was runway 07/25 at Kai Tak removed?

What is the meaning of "You've never met a graph you didn't like?"

Why do Radio Buttons not fill the entire outer circle?

Given this phrasing in the lease, when should I pay my rent?

"Oh no!" in Latin

How much do grades matter for a future academia position?

Make a Bowl of Alphabet Soup

How were servants to the Kaiser of Imperial Germany treated and where may I find more information on them

Can I say "fingers" when referring to toes?

Can I cause damage to electrical appliances by unplugging them when they are turned on?

Difference between shutdown options

I'm just a whisper. Who am I?



How to update product eav attribute in magento 2


Magento 2 - How to do get the product attribute code and value associated with product using product id?Magento 2 : How to get attribute group id using attribute set id ?Magento 2 API - Update Product Custom Attribute to Blank/NullMagento 2: Display Custom attribute value under the product name on category pageMagento 2 How to get “custom_atribute” Value in product page when atribute color drop down changes?Magento 2 : Detect change of attribute set on admin product edit page in jsMagento 2: Custom product attribute is missing from products bulk updateHow to fetch product attribute value in phtml file in Magento 2?How to show product custom attribute to invoice email in magento2.2.0?Magento 2 : Product price should be change on custom option select in custom module













2















I want to update product custom attribute when custom module is upgraded. Attribute code is product_brand and i want to set it's is_used_for_promo_rules to 1. Any help appreciated.










share|improve this question




























    2















    I want to update product custom attribute when custom module is upgraded. Attribute code is product_brand and i want to set it's is_used_for_promo_rules to 1. Any help appreciated.










    share|improve this question


























      2












      2








      2








      I want to update product custom attribute when custom module is upgraded. Attribute code is product_brand and i want to set it's is_used_for_promo_rules to 1. Any help appreciated.










      share|improve this question
















      I want to update product custom attribute when custom module is upgraded. Attribute code is product_brand and i want to set it's is_used_for_promo_rules to 1. Any help appreciated.







      magento2 custom-attributes






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 2 '18 at 8:10









      Amit Bera

      59.3k1675177




      59.3k1675177










      asked May 2 '18 at 7:51









      Nitin PawarNitin Pawar

      79911438




      79911438




















          4 Answers
          4






          active

          oldest

          votes


















          2














          I used following code



          <?php

          namespace CustomModuleSetup;
          use MagentoFrameworkSetupUpgradeDataInterface;
          use MagentoFrameworkSetupModuleDataSetupInterface;
          use MagentoFrameworkSetupModuleContextInterface;
          use MagentoEavSetupEavSetup;

          class UpgradeData implements UpgradeDataInterface

          public function __construct(
          EavSetup $eavSetupFactory
          )

          $this->eavSetupFactory = $eavSetupFactory;


          public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
          $setup->startSetup();
          $this->eavSetupFactory->updateAttribute(4,135,'is_used_for_promo_rules',1,null);
          $setup->endSetup();





          in updateAttribute 4 is entity type id and 135 is attributer id.






          share|improve this answer























          • is your solution worked?

            – Amit Bera
            May 2 '18 at 12:54











          • @AmitBera yes it worked, upgraded module version and run setup:upgrade.

            – Nitin Pawar
            May 2 '18 at 13:45











          • excellent.Where the issue ? Only parameters of update function ?

            – Amit Bera
            May 2 '18 at 13:46


















          1














          For this ,you have to create UpgradeData script at your custom module.



          On this upgradedata script you need to inject MagentoEavSetupEavSetup class and this class has function updateAttribute() which can update is_used_for_promo_rules field value to 1.






          share|improve this answer























          • It will not work, I did try this a weeks ago. If you have another solution You are Most Welcome.

            – Vivek
            May 2 '18 at 8:18












          • can u please share your code which have tried

            – Amit Bera
            May 2 '18 at 8:21











          • codeshare.io/5gNdlR Check here

            – Vivek
            May 2 '18 at 8:38











          • Hi i found this updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) function and called in upgradeData script like $this->eavSetupFactory->updateAttribute(4,135,array('is_used_for_promo_rules' => 1),null,null); this code but it is not working.

            – Nitin Pawar
            May 2 '18 at 9:48



















          0














          It’s pretty easy when you have the eavSetup in your setup module. It’s only necessary to execute:



          $eavSetup->updateAttribute(Product::ENTITY, $attributeCode, $attributeField, $value);


          For example, if I want to change the ‘position’ field value of the ‘price’ product attribute:



          $eavSetup->updateAttribute('catalog_product', 'price', 'position', 100);





          share|improve this answer






























            0














            Follow these steps to update the products attributes



            use MagentoCatalogModelResourceModelProductAction;

            your class{

            protected $_updateAction;

            public function __construct(

            Action $action

            )


            $this->_updateAction = $action;



            public yourfunction()

            $this->_updateAction->updateAttributes($productId,
            ['is_used_for_promo_rules'=>1],0);







            share|improve this answer










            New contributor




            mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.



















              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%2f224412%2fhow-to-update-product-eav-attribute-in-magento-2%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              2














              I used following code



              <?php

              namespace CustomModuleSetup;
              use MagentoFrameworkSetupUpgradeDataInterface;
              use MagentoFrameworkSetupModuleDataSetupInterface;
              use MagentoFrameworkSetupModuleContextInterface;
              use MagentoEavSetupEavSetup;

              class UpgradeData implements UpgradeDataInterface

              public function __construct(
              EavSetup $eavSetupFactory
              )

              $this->eavSetupFactory = $eavSetupFactory;


              public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
              $setup->startSetup();
              $this->eavSetupFactory->updateAttribute(4,135,'is_used_for_promo_rules',1,null);
              $setup->endSetup();





              in updateAttribute 4 is entity type id and 135 is attributer id.






              share|improve this answer























              • is your solution worked?

                – Amit Bera
                May 2 '18 at 12:54











              • @AmitBera yes it worked, upgraded module version and run setup:upgrade.

                – Nitin Pawar
                May 2 '18 at 13:45











              • excellent.Where the issue ? Only parameters of update function ?

                – Amit Bera
                May 2 '18 at 13:46















              2














              I used following code



              <?php

              namespace CustomModuleSetup;
              use MagentoFrameworkSetupUpgradeDataInterface;
              use MagentoFrameworkSetupModuleDataSetupInterface;
              use MagentoFrameworkSetupModuleContextInterface;
              use MagentoEavSetupEavSetup;

              class UpgradeData implements UpgradeDataInterface

              public function __construct(
              EavSetup $eavSetupFactory
              )

              $this->eavSetupFactory = $eavSetupFactory;


              public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
              $setup->startSetup();
              $this->eavSetupFactory->updateAttribute(4,135,'is_used_for_promo_rules',1,null);
              $setup->endSetup();





              in updateAttribute 4 is entity type id and 135 is attributer id.






              share|improve this answer























              • is your solution worked?

                – Amit Bera
                May 2 '18 at 12:54











              • @AmitBera yes it worked, upgraded module version and run setup:upgrade.

                – Nitin Pawar
                May 2 '18 at 13:45











              • excellent.Where the issue ? Only parameters of update function ?

                – Amit Bera
                May 2 '18 at 13:46













              2












              2








              2







              I used following code



              <?php

              namespace CustomModuleSetup;
              use MagentoFrameworkSetupUpgradeDataInterface;
              use MagentoFrameworkSetupModuleDataSetupInterface;
              use MagentoFrameworkSetupModuleContextInterface;
              use MagentoEavSetupEavSetup;

              class UpgradeData implements UpgradeDataInterface

              public function __construct(
              EavSetup $eavSetupFactory
              )

              $this->eavSetupFactory = $eavSetupFactory;


              public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
              $setup->startSetup();
              $this->eavSetupFactory->updateAttribute(4,135,'is_used_for_promo_rules',1,null);
              $setup->endSetup();





              in updateAttribute 4 is entity type id and 135 is attributer id.






              share|improve this answer













              I used following code



              <?php

              namespace CustomModuleSetup;
              use MagentoFrameworkSetupUpgradeDataInterface;
              use MagentoFrameworkSetupModuleDataSetupInterface;
              use MagentoFrameworkSetupModuleContextInterface;
              use MagentoEavSetupEavSetup;

              class UpgradeData implements UpgradeDataInterface

              public function __construct(
              EavSetup $eavSetupFactory
              )

              $this->eavSetupFactory = $eavSetupFactory;


              public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
              $setup->startSetup();
              $this->eavSetupFactory->updateAttribute(4,135,'is_used_for_promo_rules',1,null);
              $setup->endSetup();





              in updateAttribute 4 is entity type id and 135 is attributer id.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 2 '18 at 11:43









              Nitin PawarNitin Pawar

              79911438




              79911438












              • is your solution worked?

                – Amit Bera
                May 2 '18 at 12:54











              • @AmitBera yes it worked, upgraded module version and run setup:upgrade.

                – Nitin Pawar
                May 2 '18 at 13:45











              • excellent.Where the issue ? Only parameters of update function ?

                – Amit Bera
                May 2 '18 at 13:46

















              • is your solution worked?

                – Amit Bera
                May 2 '18 at 12:54











              • @AmitBera yes it worked, upgraded module version and run setup:upgrade.

                – Nitin Pawar
                May 2 '18 at 13:45











              • excellent.Where the issue ? Only parameters of update function ?

                – Amit Bera
                May 2 '18 at 13:46
















              is your solution worked?

              – Amit Bera
              May 2 '18 at 12:54





              is your solution worked?

              – Amit Bera
              May 2 '18 at 12:54













              @AmitBera yes it worked, upgraded module version and run setup:upgrade.

              – Nitin Pawar
              May 2 '18 at 13:45





              @AmitBera yes it worked, upgraded module version and run setup:upgrade.

              – Nitin Pawar
              May 2 '18 at 13:45













              excellent.Where the issue ? Only parameters of update function ?

              – Amit Bera
              May 2 '18 at 13:46





              excellent.Where the issue ? Only parameters of update function ?

              – Amit Bera
              May 2 '18 at 13:46













              1














              For this ,you have to create UpgradeData script at your custom module.



              On this upgradedata script you need to inject MagentoEavSetupEavSetup class and this class has function updateAttribute() which can update is_used_for_promo_rules field value to 1.






              share|improve this answer























              • It will not work, I did try this a weeks ago. If you have another solution You are Most Welcome.

                – Vivek
                May 2 '18 at 8:18












              • can u please share your code which have tried

                – Amit Bera
                May 2 '18 at 8:21











              • codeshare.io/5gNdlR Check here

                – Vivek
                May 2 '18 at 8:38











              • Hi i found this updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) function and called in upgradeData script like $this->eavSetupFactory->updateAttribute(4,135,array('is_used_for_promo_rules' => 1),null,null); this code but it is not working.

                – Nitin Pawar
                May 2 '18 at 9:48
















              1














              For this ,you have to create UpgradeData script at your custom module.



              On this upgradedata script you need to inject MagentoEavSetupEavSetup class and this class has function updateAttribute() which can update is_used_for_promo_rules field value to 1.






              share|improve this answer























              • It will not work, I did try this a weeks ago. If you have another solution You are Most Welcome.

                – Vivek
                May 2 '18 at 8:18












              • can u please share your code which have tried

                – Amit Bera
                May 2 '18 at 8:21











              • codeshare.io/5gNdlR Check here

                – Vivek
                May 2 '18 at 8:38











              • Hi i found this updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) function and called in upgradeData script like $this->eavSetupFactory->updateAttribute(4,135,array('is_used_for_promo_rules' => 1),null,null); this code but it is not working.

                – Nitin Pawar
                May 2 '18 at 9:48














              1












              1








              1







              For this ,you have to create UpgradeData script at your custom module.



              On this upgradedata script you need to inject MagentoEavSetupEavSetup class and this class has function updateAttribute() which can update is_used_for_promo_rules field value to 1.






              share|improve this answer













              For this ,you have to create UpgradeData script at your custom module.



              On this upgradedata script you need to inject MagentoEavSetupEavSetup class and this class has function updateAttribute() which can update is_used_for_promo_rules field value to 1.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered May 2 '18 at 8:16









              Amit BeraAmit Bera

              59.3k1675177




              59.3k1675177












              • It will not work, I did try this a weeks ago. If you have another solution You are Most Welcome.

                – Vivek
                May 2 '18 at 8:18












              • can u please share your code which have tried

                – Amit Bera
                May 2 '18 at 8:21











              • codeshare.io/5gNdlR Check here

                – Vivek
                May 2 '18 at 8:38











              • Hi i found this updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) function and called in upgradeData script like $this->eavSetupFactory->updateAttribute(4,135,array('is_used_for_promo_rules' => 1),null,null); this code but it is not working.

                – Nitin Pawar
                May 2 '18 at 9:48


















              • It will not work, I did try this a weeks ago. If you have another solution You are Most Welcome.

                – Vivek
                May 2 '18 at 8:18












              • can u please share your code which have tried

                – Amit Bera
                May 2 '18 at 8:21











              • codeshare.io/5gNdlR Check here

                – Vivek
                May 2 '18 at 8:38











              • Hi i found this updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) function and called in upgradeData script like $this->eavSetupFactory->updateAttribute(4,135,array('is_used_for_promo_rules' => 1),null,null); this code but it is not working.

                – Nitin Pawar
                May 2 '18 at 9:48

















              It will not work, I did try this a weeks ago. If you have another solution You are Most Welcome.

              – Vivek
              May 2 '18 at 8:18






              It will not work, I did try this a weeks ago. If you have another solution You are Most Welcome.

              – Vivek
              May 2 '18 at 8:18














              can u please share your code which have tried

              – Amit Bera
              May 2 '18 at 8:21





              can u please share your code which have tried

              – Amit Bera
              May 2 '18 at 8:21













              codeshare.io/5gNdlR Check here

              – Vivek
              May 2 '18 at 8:38





              codeshare.io/5gNdlR Check here

              – Vivek
              May 2 '18 at 8:38













              Hi i found this updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) function and called in upgradeData script like $this->eavSetupFactory->updateAttribute(4,135,array('is_used_for_promo_rules' => 1),null,null); this code but it is not working.

              – Nitin Pawar
              May 2 '18 at 9:48






              Hi i found this updateAttribute($entityTypeId, $id, $field, $value = null, $sortOrder = null) function and called in upgradeData script like $this->eavSetupFactory->updateAttribute(4,135,array('is_used_for_promo_rules' => 1),null,null); this code but it is not working.

              – Nitin Pawar
              May 2 '18 at 9:48












              0














              It’s pretty easy when you have the eavSetup in your setup module. It’s only necessary to execute:



              $eavSetup->updateAttribute(Product::ENTITY, $attributeCode, $attributeField, $value);


              For example, if I want to change the ‘position’ field value of the ‘price’ product attribute:



              $eavSetup->updateAttribute('catalog_product', 'price', 'position', 100);





              share|improve this answer



























                0














                It’s pretty easy when you have the eavSetup in your setup module. It’s only necessary to execute:



                $eavSetup->updateAttribute(Product::ENTITY, $attributeCode, $attributeField, $value);


                For example, if I want to change the ‘position’ field value of the ‘price’ product attribute:



                $eavSetup->updateAttribute('catalog_product', 'price', 'position', 100);





                share|improve this answer

























                  0












                  0








                  0







                  It’s pretty easy when you have the eavSetup in your setup module. It’s only necessary to execute:



                  $eavSetup->updateAttribute(Product::ENTITY, $attributeCode, $attributeField, $value);


                  For example, if I want to change the ‘position’ field value of the ‘price’ product attribute:



                  $eavSetup->updateAttribute('catalog_product', 'price', 'position', 100);





                  share|improve this answer













                  It’s pretty easy when you have the eavSetup in your setup module. It’s only necessary to execute:



                  $eavSetup->updateAttribute(Product::ENTITY, $attributeCode, $attributeField, $value);


                  For example, if I want to change the ‘position’ field value of the ‘price’ product attribute:



                  $eavSetup->updateAttribute('catalog_product', 'price', 'position', 100);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered May 3 '18 at 6:12









                  DivyeshDivyesh

                  835321




                  835321





















                      0














                      Follow these steps to update the products attributes



                      use MagentoCatalogModelResourceModelProductAction;

                      your class{

                      protected $_updateAction;

                      public function __construct(

                      Action $action

                      )


                      $this->_updateAction = $action;



                      public yourfunction()

                      $this->_updateAction->updateAttributes($productId,
                      ['is_used_for_promo_rules'=>1],0);







                      share|improve this answer










                      New contributor




                      mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.
























                        0














                        Follow these steps to update the products attributes



                        use MagentoCatalogModelResourceModelProductAction;

                        your class{

                        protected $_updateAction;

                        public function __construct(

                        Action $action

                        )


                        $this->_updateAction = $action;



                        public yourfunction()

                        $this->_updateAction->updateAttributes($productId,
                        ['is_used_for_promo_rules'=>1],0);







                        share|improve this answer










                        New contributor




                        mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.






















                          0












                          0








                          0







                          Follow these steps to update the products attributes



                          use MagentoCatalogModelResourceModelProductAction;

                          your class{

                          protected $_updateAction;

                          public function __construct(

                          Action $action

                          )


                          $this->_updateAction = $action;



                          public yourfunction()

                          $this->_updateAction->updateAttributes($productId,
                          ['is_used_for_promo_rules'=>1],0);







                          share|improve this answer










                          New contributor




                          mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.










                          Follow these steps to update the products attributes



                          use MagentoCatalogModelResourceModelProductAction;

                          your class{

                          protected $_updateAction;

                          public function __construct(

                          Action $action

                          )


                          $this->_updateAction = $action;



                          public yourfunction()

                          $this->_updateAction->updateAttributes($productId,
                          ['is_used_for_promo_rules'=>1],0);








                          share|improve this answer










                          New contributor




                          mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer








                          edited yesterday









                          magefms

                          1,9171425




                          1,9171425






                          New contributor




                          mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered yesterday









                          mohithmohith

                          1




                          1




                          New contributor




                          mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          mohith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.



























                              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%2f224412%2fhow-to-update-product-eav-attribute-in-magento-2%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

                              Sum ergo cogito? 1 nng

                              419 nièngy_Soadمي 19bal1.5o_g

                              Queiggey Chernihivv 9NnOo i Zw X QqKk LpB