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;








2















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?










share|improve this question




























    2















    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?










    share|improve this question
























      2












      2








      2








      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?










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 24 at 6:57









      Shoaib MunirShoaib Munir

      3,22451764




      3,22451764




















          1 Answer
          1






          active

          oldest

          votes


















          1














          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);






          share|improve this answer

























          • $this->action is the object of MagentoCatalogModelResourceModelProductAction?

            – 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











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









          1














          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);






          share|improve this answer

























          • $this->action is the object of MagentoCatalogModelResourceModelProductAction?

            – 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















          1














          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);






          share|improve this answer

























          • $this->action is the object of MagentoCatalogModelResourceModelProductAction?

            – 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













          1












          1








          1







          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);






          share|improve this answer















          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);







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 24 at 7:09

























          answered May 24 at 7:03









          Rk RathodRk Rathod

          2,198214




          2,198214












          • $this->action is the object of MagentoCatalogModelResourceModelProductAction?

            – 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











          • 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

















          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%2f275952%2fmagento-2-all-products-attributes-updated-after-update-from-collection%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

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

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

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