Magento Recommended way to add comment to orderBest practice to add a layout handle for my custom...

Advice for a new journal editor

Describing what the world looks like in UV and IR

If I delete my router's history can my ISP still provide it to my parents?

How do you funnel food off a cutting board?

What would the chemical name be for C13H8Cl3NO

Can a long polymer chain interact with itself via van der Waals forces?

Why did the villain in the first Men in Black movie care about Earth's Cockroaches?

Early credit roll before the end of the film

What is the wife of a henpecked husband called?

Nested word series [humans only]

Can a hotel cancel a confirmed reservation?

Bash Script Function Return True-False

Does theoretical physics suggest that gravity is the exchange of gravitons or deformation/bending of spacetime?

How does Leonard in "Memento" remember reading and writing?

Why is working on the same position for more than 15 years not a red flag?

Why is Agricola named as such?

How can my powered armor quickly replace its ceramic plates?

A title for a history book

Why was Lupin comfortable with saying Voldemort's name?

What are career options for big-picture thinkers with no experience?

Eww, those bytes are gross

Why zero tolerance on nudity in space?

Intern applicant asking for compensation equivalent to that of permanent employee

What is the most fuel efficient way out of the Solar System?



Magento Recommended way to add comment to order


Best practice to add a layout handle for my custom module?Recommended way to Install Magento 2 on shared hosting, Composer or archivesMagento 2: How to programatically check if an order exists without using try-catch?List of filters for sales order APIWhen Should We Use a Repository and Factory in Magento 2?Return order details in REST API Magento-2Magento 1.9 API Performance - Retrieving All Sales Order InfoMagento 2 REST API - Add Order CommentMagento2: searching for orders through REST is too slow.Magento 2.3 - Preserving Success message for show













0















I am looking for the Magento recommended best practice for adding a comment to an order. I can easily accomplish this using things such as $order->addCommentToStatusHistory($message)->save() and similar actions. However I know that using a direct save action is not recommended on models and you should instead us managers/repositories.



I have also found that there is a MagentoSalesApiOrderStatusHistoryRepositoryInterface now which provides the save function. So what I'm trying to figure out is how to approach this properly. This is my best guess.



private $orderStatusHistoryRepository;

public function __construct(
MagentoSalesApiOrderStatusHistoryRepositoryInterface $orderStatusHistoryRepository
) {
$this->orderStatusHistoryRepository = $orderStatusHistoryRepository;
}

public function myFunction(MagentoSalesApiDataOrderInterface $order)
{
//... additional logic here
$history = $order->addCommentToStatusHistory($message);
$this->orderStatusHistoryRepository->save($history);
}


What I'm not certain about is if this is the proper approach AND should I also be saving the order using OrderRepositoryInterface, or if that is unnecessary.



I have looked through a lot of questions and answers around this as well as looking through some tutorials and documentation. However all of these provide conflicting information and most of them recommend ways that I know are not Magento best practice.



If there is documentation out there that would answer my question and I have overlooked it please point me in the right direction.



This is for Magento 2.3.0.









share



























    0















    I am looking for the Magento recommended best practice for adding a comment to an order. I can easily accomplish this using things such as $order->addCommentToStatusHistory($message)->save() and similar actions. However I know that using a direct save action is not recommended on models and you should instead us managers/repositories.



    I have also found that there is a MagentoSalesApiOrderStatusHistoryRepositoryInterface now which provides the save function. So what I'm trying to figure out is how to approach this properly. This is my best guess.



    private $orderStatusHistoryRepository;

    public function __construct(
    MagentoSalesApiOrderStatusHistoryRepositoryInterface $orderStatusHistoryRepository
    ) {
    $this->orderStatusHistoryRepository = $orderStatusHistoryRepository;
    }

    public function myFunction(MagentoSalesApiDataOrderInterface $order)
    {
    //... additional logic here
    $history = $order->addCommentToStatusHistory($message);
    $this->orderStatusHistoryRepository->save($history);
    }


    What I'm not certain about is if this is the proper approach AND should I also be saving the order using OrderRepositoryInterface, or if that is unnecessary.



    I have looked through a lot of questions and answers around this as well as looking through some tutorials and documentation. However all of these provide conflicting information and most of them recommend ways that I know are not Magento best practice.



    If there is documentation out there that would answer my question and I have overlooked it please point me in the right direction.



    This is for Magento 2.3.0.









    share

























      0












      0








      0








      I am looking for the Magento recommended best practice for adding a comment to an order. I can easily accomplish this using things such as $order->addCommentToStatusHistory($message)->save() and similar actions. However I know that using a direct save action is not recommended on models and you should instead us managers/repositories.



      I have also found that there is a MagentoSalesApiOrderStatusHistoryRepositoryInterface now which provides the save function. So what I'm trying to figure out is how to approach this properly. This is my best guess.



      private $orderStatusHistoryRepository;

      public function __construct(
      MagentoSalesApiOrderStatusHistoryRepositoryInterface $orderStatusHistoryRepository
      ) {
      $this->orderStatusHistoryRepository = $orderStatusHistoryRepository;
      }

      public function myFunction(MagentoSalesApiDataOrderInterface $order)
      {
      //... additional logic here
      $history = $order->addCommentToStatusHistory($message);
      $this->orderStatusHistoryRepository->save($history);
      }


      What I'm not certain about is if this is the proper approach AND should I also be saving the order using OrderRepositoryInterface, or if that is unnecessary.



      I have looked through a lot of questions and answers around this as well as looking through some tutorials and documentation. However all of these provide conflicting information and most of them recommend ways that I know are not Magento best practice.



      If there is documentation out there that would answer my question and I have overlooked it please point me in the right direction.



      This is for Magento 2.3.0.









      share














      I am looking for the Magento recommended best practice for adding a comment to an order. I can easily accomplish this using things such as $order->addCommentToStatusHistory($message)->save() and similar actions. However I know that using a direct save action is not recommended on models and you should instead us managers/repositories.



      I have also found that there is a MagentoSalesApiOrderStatusHistoryRepositoryInterface now which provides the save function. So what I'm trying to figure out is how to approach this properly. This is my best guess.



      private $orderStatusHistoryRepository;

      public function __construct(
      MagentoSalesApiOrderStatusHistoryRepositoryInterface $orderStatusHistoryRepository
      ) {
      $this->orderStatusHistoryRepository = $orderStatusHistoryRepository;
      }

      public function myFunction(MagentoSalesApiDataOrderInterface $order)
      {
      //... additional logic here
      $history = $order->addCommentToStatusHistory($message);
      $this->orderStatusHistoryRepository->save($history);
      }


      What I'm not certain about is if this is the proper approach AND should I also be saving the order using OrderRepositoryInterface, or if that is unnecessary.



      I have looked through a lot of questions and answers around this as well as looking through some tutorials and documentation. However all of these provide conflicting information and most of them recommend ways that I know are not Magento best practice.



      If there is documentation out there that would answer my question and I have overlooked it please point me in the right direction.



      This is for Magento 2.3.0.







      magento2 sales-order magento2.3 best-practice order-comment





      share












      share










      share



      share










      asked 8 mins ago









      rain2orain2o

      1816




      1816






















          0






          active

          oldest

          votes











          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%2f263878%2fmagento-recommended-way-to-add-comment-to-order%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f263878%2fmagento-recommended-way-to-add-comment-to-order%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

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          夢乃愛華...