Magento 2 - All products attributes updated after update from collectionAdd all flat-attributes to product collection?Get collection of products of all storesMagento Collection Loading PrematurelyHow to change dynamic attributes when simple product is selectedMagento 2.1.6 Product Grid page count and record count issue when programmatically adding filter using different methodsMagento 2.1 Create a filter in the product grid by new attributeProduct import successfully done no errors but no products imported in Magento 2Media image attribute bugged in frontendGet collection of recently updated productsGet products collection in cronjob
Why don't I have ground wiring on any of my outlets?
How did the Zip Chip and RocketChip accelerators work for the Apple II?
What is a simple, physical situation where complex numbers emerge naturally?
What should I do about a religious player who refuses to accept the existence of multiple gods in D&D?
If a massive object like Jupiter flew past the Earth how close would it need to come to pull people off of the surface?
Is there an evolutionary advantage to having two heads?
Can you use a concentration spell while using Mantle of Majesty?
What if you don't bring your credit card or debit for incidentals?
Scala list with same adjacent values
Is there a rule that prohibits us from using 2 possessives in a row?
How to detach yourself from a character you're going to kill?
How can a single Member of the House block a Congressional bill?
Orientable with respect to complex cobordism?
Did airlines fly their aircraft slower in response to oil prices in the 1970s?
Why use water tanks from a retired Space Shuttle?
How crucial is a waifu game storyline?
Looking after a wayward brother in mother's will
Could a guilty Boris Johnson be used to cancel Brexit?
When was the word "ambigu" first used with the sense of "meal with all items served at the same time"?
If Sweden was to magically float away, at what altitude would it be visible from the southern hemisphere?
Is a hash a zero-knowledge proof?
Applicants clearly not having the skills they advertise
Strange math syntax in old basic listing
Make a formula to get the highest score
Magento 2 - All products attributes updated after update from collection
Add all flat-attributes to product collection?Get collection of products of all storesMagento Collection Loading PrematurelyHow to change dynamic attributes when simple product is selectedMagento 2.1.6 Product Grid page count and record count issue when programmatically adding filter using different methodsMagento 2.1 Create a filter in the product grid by new attributeProduct import successfully done no errors but no products imported in Magento 2Media image attribute bugged in frontendGet collection of recently updated productsGet products collection in cronjob
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have got collection in $collecction
from MagentoCatalogModelResourceModelProductCollectionFactory
with some certain conditions
I am updating a custom attribute viewed_count
in foreach
loop like this:
foreach($collection as $k=>$_product)
echo $_product->getSku()." ";
$viewCount = $this->getViewedCount($_product->getId());
$_product->getResource()->saveAttribute($_product, "viewed_count");
$_product->setViewedCount($viewCount);
$_product->save();
After this it is successfully updating product viewed count in viewed_count
attribute.
But the issue is: After this code is executed, all other attributes got updated and set to some default values. Can anyone tell me what am I doing wrong?
magento2 collection products magento-2.2.5 attribute-value
add a comment |
I have got collection in $collecction
from MagentoCatalogModelResourceModelProductCollectionFactory
with some certain conditions
I am updating a custom attribute viewed_count
in foreach
loop like this:
foreach($collection as $k=>$_product)
echo $_product->getSku()." ";
$viewCount = $this->getViewedCount($_product->getId());
$_product->getResource()->saveAttribute($_product, "viewed_count");
$_product->setViewedCount($viewCount);
$_product->save();
After this it is successfully updating product viewed count in viewed_count
attribute.
But the issue is: After this code is executed, all other attributes got updated and set to some default values. Can anyone tell me what am I doing wrong?
magento2 collection products magento-2.2.5 attribute-value
add a comment |
I have got collection in $collecction
from MagentoCatalogModelResourceModelProductCollectionFactory
with some certain conditions
I am updating a custom attribute viewed_count
in foreach
loop like this:
foreach($collection as $k=>$_product)
echo $_product->getSku()." ";
$viewCount = $this->getViewedCount($_product->getId());
$_product->getResource()->saveAttribute($_product, "viewed_count");
$_product->setViewedCount($viewCount);
$_product->save();
After this it is successfully updating product viewed count in viewed_count
attribute.
But the issue is: After this code is executed, all other attributes got updated and set to some default values. Can anyone tell me what am I doing wrong?
magento2 collection products magento-2.2.5 attribute-value
I have got collection in $collecction
from MagentoCatalogModelResourceModelProductCollectionFactory
with some certain conditions
I am updating a custom attribute viewed_count
in foreach
loop like this:
foreach($collection as $k=>$_product)
echo $_product->getSku()." ";
$viewCount = $this->getViewedCount($_product->getId());
$_product->getResource()->saveAttribute($_product, "viewed_count");
$_product->setViewedCount($viewCount);
$_product->save();
After this it is successfully updating product viewed count in viewed_count
attribute.
But the issue is: After this code is executed, all other attributes got updated and set to some default values. Can anyone tell me what am I doing wrong?
magento2 collection products magento-2.2.5 attribute-value
magento2 collection products magento-2.2.5 attribute-value
asked May 24 at 6:57
Shoaib MunirShoaib Munir
3,22451764
3,22451764
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Reference Link
updateAttributes
of class MagentoCatalogModelResourceModelProductAction
. Method can update multiple products and attribute values, but if you want to update just one product with one attribute value you can do it like this:
$this->action->updateAttributes([$product->getId()], ['attribute_code' => $newValue], $storeId);
$this->action
is the object ofMagentoCatalogModelResourceModelProductAction
?
– Shoaib Munir
May 24 at 7:05
yes bro.........
– Rk Rathod
May 24 at 7:08
Thanks Rk Rathod I will try this. Will let you know when it resolved :)
– Shoaib Munir
May 24 at 7:12
ok buddy....... :)
– Rk Rathod
May 24 at 7:13
It worked perfectly. Thanks :)
– Shoaib Munir
May 24 at 10:42
|
show 1 more 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%2f275952%2fmagento-2-all-products-attributes-updated-after-update-from-collection%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Reference Link
updateAttributes
of class MagentoCatalogModelResourceModelProductAction
. Method can update multiple products and attribute values, but if you want to update just one product with one attribute value you can do it like this:
$this->action->updateAttributes([$product->getId()], ['attribute_code' => $newValue], $storeId);
$this->action
is the object ofMagentoCatalogModelResourceModelProductAction
?
– Shoaib Munir
May 24 at 7:05
yes bro.........
– Rk Rathod
May 24 at 7:08
Thanks Rk Rathod I will try this. Will let you know when it resolved :)
– Shoaib Munir
May 24 at 7:12
ok buddy....... :)
– Rk Rathod
May 24 at 7:13
It worked perfectly. Thanks :)
– Shoaib Munir
May 24 at 10:42
|
show 1 more comment
Reference Link
updateAttributes
of class MagentoCatalogModelResourceModelProductAction
. Method can update multiple products and attribute values, but if you want to update just one product with one attribute value you can do it like this:
$this->action->updateAttributes([$product->getId()], ['attribute_code' => $newValue], $storeId);
$this->action
is the object ofMagentoCatalogModelResourceModelProductAction
?
– Shoaib Munir
May 24 at 7:05
yes bro.........
– Rk Rathod
May 24 at 7:08
Thanks Rk Rathod I will try this. Will let you know when it resolved :)
– Shoaib Munir
May 24 at 7:12
ok buddy....... :)
– Rk Rathod
May 24 at 7:13
It worked perfectly. Thanks :)
– Shoaib Munir
May 24 at 10:42
|
show 1 more comment
Reference Link
updateAttributes
of class MagentoCatalogModelResourceModelProductAction
. Method can update multiple products and attribute values, but if you want to update just one product with one attribute value you can do it like this:
$this->action->updateAttributes([$product->getId()], ['attribute_code' => $newValue], $storeId);
Reference Link
updateAttributes
of class MagentoCatalogModelResourceModelProductAction
. Method can update multiple products and attribute values, but if you want to update just one product with one attribute value you can do it like this:
$this->action->updateAttributes([$product->getId()], ['attribute_code' => $newValue], $storeId);
edited May 24 at 7:09
answered May 24 at 7:03
Rk RathodRk Rathod
2,198214
2,198214
$this->action
is the object ofMagentoCatalogModelResourceModelProductAction
?
– Shoaib Munir
May 24 at 7:05
yes bro.........
– Rk Rathod
May 24 at 7:08
Thanks Rk Rathod I will try this. Will let you know when it resolved :)
– Shoaib Munir
May 24 at 7:12
ok buddy....... :)
– Rk Rathod
May 24 at 7:13
It worked perfectly. Thanks :)
– Shoaib Munir
May 24 at 10:42
|
show 1 more comment
$this->action
is the object ofMagentoCatalogModelResourceModelProductAction
?
– Shoaib Munir
May 24 at 7:05
yes bro.........
– Rk Rathod
May 24 at 7:08
Thanks Rk Rathod I will try this. Will let you know when it resolved :)
– Shoaib Munir
May 24 at 7:12
ok buddy....... :)
– Rk Rathod
May 24 at 7:13
It worked perfectly. Thanks :)
– Shoaib Munir
May 24 at 10:42
$this->action
is the object of MagentoCatalogModelResourceModelProductAction
?– Shoaib Munir
May 24 at 7:05
$this->action
is the object of MagentoCatalogModelResourceModelProductAction
?– Shoaib Munir
May 24 at 7:05
yes bro.........
– Rk Rathod
May 24 at 7:08
yes bro.........
– Rk Rathod
May 24 at 7:08
Thanks Rk Rathod I will try this. Will let you know when it resolved :)
– Shoaib Munir
May 24 at 7:12
Thanks Rk Rathod I will try this. Will let you know when it resolved :)
– Shoaib Munir
May 24 at 7:12
ok buddy....... :)
– Rk Rathod
May 24 at 7:13
ok buddy....... :)
– Rk Rathod
May 24 at 7:13
It worked perfectly. Thanks :)
– Shoaib Munir
May 24 at 10:42
It worked perfectly. Thanks :)
– Shoaib Munir
May 24 at 10:42
|
show 1 more 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%2f275952%2fmagento-2-all-products-attributes-updated-after-update-from-collection%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