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
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
add a comment |
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
add a comment |
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
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
magento2 custom-attributes
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
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
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.
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
add a comment |
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.
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 thisupdateAttribute($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
add a comment |
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);
add a comment |
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);
New contributor
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
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 thisupdateAttribute($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
add a comment |
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.
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 thisupdateAttribute($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
add a comment |
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.
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.
answered May 2 '18 at 8:16
Amit Bera♦Amit 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 thisupdateAttribute($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
add a comment |
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 thisupdateAttribute($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
add a comment |
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);
add a comment |
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);
add a comment |
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);
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);
answered May 3 '18 at 6:12
DivyeshDivyesh
835321
835321
add a comment |
add a comment |
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);
New contributor
add a comment |
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);
New contributor
add a comment |
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);
New contributor
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);
New contributor
New contributor
answered 5 mins ago
mohithmohith
1
1
New contributor
New contributor
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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