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

Air travel with refrigerated insulin

Make a Bowl of Alphabet Soup

Unfrosted light bulb

Should a narrator ever describe things based on a character's view instead of facts?

Reasons for having MCU pin-states default to pull-up/down out of reset

If the Dominion rule using their Jem'Hadar troops, why is their life expectancy so low?

Checking @@ROWCOUNT failing

Does capillary rise violate hydrostatic paradox?

Do native speakers use "ultima" and "proxima" frequently in spoken English?

Why is implicit conversion not ambiguous for non-primitive types?

How do you justify more code being written by following clean code practices?

Sort with assumptions

How do I prevent inappropriate ads from appearing in my game?

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

Why does the frost depth increase when the surface temperature warms up?

Should I warn a new PhD Student?

PTIJ: Which Dr. Seuss books should one obtain?

Travelling in US for more than 90 days

Index matching algorithm without hash-based data structures?

Walter Rudin's mathematical analysis: theorem 2.43. Why proof can't work under the perfect set is uncountable.

What properties make a magic weapon befit a Rogue more than a DEX-based Fighter?

Mortal danger in mid-grade literature

Is there a distance limit for minecart tracks?

Is divisi notation needed for brass or woodwind in an orchestra?



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.3k1575177




      59.3k1575177










      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 this 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








            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.3k1575177




              59.3k1575177












              • 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 this 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








                      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 this 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








                        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 this 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








                          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 this 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








                          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


                          share






                          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 5 mins ago









                          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

                              Nidaros erkebispedøme

                              Birsay

                              Where did Arya get these scars? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Favourite questions and answers from the 1st quarter of 2019Why did Arya refuse to end it?Has the pronunciation of Arya Stark's name changed?Has Arya forgiven people?Why did Arya Stark lose her vision?Why can Arya still use the faces?Has the Narrow Sea become narrower?Does Arya Stark know how to make poisons outside of the House of Black and White?Why did Nymeria leave Arya?Why did Arya not kill the Lannister soldiers she encountered in the Riverlands?What is the current canonical age of Sansa, Bran and Arya Stark?