Magento 2 - How to add admin username in order comments on admin actionMagento add Custom order statusHow to create invioce for cancel order?how to get order shipment comments in MG2 using DI ( dependecency injection)How to add comments on order after checkoutHow to get last order status history comment and order status Magento 2Order : To add comments programmatically for an order in admin panel in magento 2how to cancel processed order?Magento 2 order information: How to add links dynamically?Send Email to customers automaticallyadd username to order comment history

"Marked down as someone wanting to sell shares." What does that mean?

Why is "la Gestapo" feminine?

Weird lines in Microsoft Word

Someone scrambled my calling sign- who am I?

What kind of footwear is suitable for walking in micro gravity environment?

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

Is there any common country to visit for uk and schengen visa?

Imaginary part of expression too difficult to calculate

Error in master's thesis, I do not know what to do

Isn't the word "experience" wrongly used in this context?

Exposing a company lying about themselves in a tightly knit industry: Is my career at risk on the long run?

Should a narrator ever describe things based on a characters view instead of fact?

What are the differences between tunneling and regulare encapsulation?

What is the tangent at a sharp point on a curve?

Symbolism of 18 Journeyers

Jem'Hadar, something strange about their life expectancy

Can other pieces capture a threatening piece and prevent a checkmate?

Why doesn't the chatan sign the ketubah?

Print a physical multiplication table

Unfrosted light bulb

Is xar preinstalled on macOS?

What will the Frenchman say?

Why are there no stars visible in cislunar space?

Do people actually use the word "kaputt" in conversation?



Magento 2 - How to add admin username in order comments on admin action


Magento add Custom order statusHow to create invioce for cancel order?how to get order shipment comments in MG2 using DI ( dependecency injection)How to add comments on order after checkoutHow to get last order status history comment and order status Magento 2Order : To add comments programmatically for an order in admin panel in magento 2how to cancel processed order?Magento 2 order information: How to add links dynamically?Send Email to customers automaticallyadd username to order comment history













3















I need to add admin username in order comment history whenever I create



  • invoice

  • shipment

  • and On Cancel order.









share|improve this question




























    3















    I need to add admin username in order comment history whenever I create



    • invoice

    • shipment

    • and On Cancel order.









    share|improve this question


























      3












      3








      3








      I need to add admin username in order comment history whenever I create



      • invoice

      • shipment

      • and On Cancel order.









      share|improve this question
















      I need to add admin username in order comment history whenever I create



      • invoice

      • shipment

      • and On Cancel order.






      magento2 sales-order magento2.3 admin-panel






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 13 hours ago









      Muhammad Hasham

      2,5581731




      2,5581731










      asked Feb 13 at 12:02







      user76063



























          1 Answer
          1






          active

          oldest

          votes


















          3














          I recently did this work through observers



          You have to add these event in your module event file VendorYourmodulenameetcevents.xml



          For Invoice



          <event name="sales_order_invoice_register">
          <observer name="vendor_yourmodulename_observer_addcommentonaction" instance="VendorYourmodulenameObserverAddcommentonaction" />
          </event>


          For Cancel



          <event name="order_cancel_after">
          <observer name="vendor_yourmodulename_observer_addcommentoncancelaction" instance="VendorYourmodulenameObserverAddcommentoncancelaction" />
          </event>


          For Shipment



          <event name="sales_order_shipment_save_after">
          <observer name="vendor_yourmodulename_observer_addcommentonshipmentaction" instance="VendorYourmodulenameObserverAddcommentonshipmentaction" />
          </event>



          Observer files




          For Invoice Add file in your module VendorYourmodulenameObserverAddcommentonaction.php



          <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Invoice generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Cancel Add file in your module VendorYourmodulenameObserverAddcommentoncancelaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentoncancelaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Order canceled"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Shipment Add file in your module VendorYourmodulenameObserverAddcommentonshipmentaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonshipmentaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $shipment = $observer->getEvent()->getShipment();
          $order = $shipment->getOrder();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Shipment generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;







          share|improve this answer























          • Thanks Brother. It worked :)

            – user76063
            Feb 13 at 12:43










          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%2f261607%2fmagento-2-how-to-add-admin-username-in-order-comments-on-admin-action%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









          3














          I recently did this work through observers



          You have to add these event in your module event file VendorYourmodulenameetcevents.xml



          For Invoice



          <event name="sales_order_invoice_register">
          <observer name="vendor_yourmodulename_observer_addcommentonaction" instance="VendorYourmodulenameObserverAddcommentonaction" />
          </event>


          For Cancel



          <event name="order_cancel_after">
          <observer name="vendor_yourmodulename_observer_addcommentoncancelaction" instance="VendorYourmodulenameObserverAddcommentoncancelaction" />
          </event>


          For Shipment



          <event name="sales_order_shipment_save_after">
          <observer name="vendor_yourmodulename_observer_addcommentonshipmentaction" instance="VendorYourmodulenameObserverAddcommentonshipmentaction" />
          </event>



          Observer files




          For Invoice Add file in your module VendorYourmodulenameObserverAddcommentonaction.php



          <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Invoice generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Cancel Add file in your module VendorYourmodulenameObserverAddcommentoncancelaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentoncancelaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Order canceled"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Shipment Add file in your module VendorYourmodulenameObserverAddcommentonshipmentaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonshipmentaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $shipment = $observer->getEvent()->getShipment();
          $order = $shipment->getOrder();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Shipment generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;







          share|improve this answer























          • Thanks Brother. It worked :)

            – user76063
            Feb 13 at 12:43















          3














          I recently did this work through observers



          You have to add these event in your module event file VendorYourmodulenameetcevents.xml



          For Invoice



          <event name="sales_order_invoice_register">
          <observer name="vendor_yourmodulename_observer_addcommentonaction" instance="VendorYourmodulenameObserverAddcommentonaction" />
          </event>


          For Cancel



          <event name="order_cancel_after">
          <observer name="vendor_yourmodulename_observer_addcommentoncancelaction" instance="VendorYourmodulenameObserverAddcommentoncancelaction" />
          </event>


          For Shipment



          <event name="sales_order_shipment_save_after">
          <observer name="vendor_yourmodulename_observer_addcommentonshipmentaction" instance="VendorYourmodulenameObserverAddcommentonshipmentaction" />
          </event>



          Observer files




          For Invoice Add file in your module VendorYourmodulenameObserverAddcommentonaction.php



          <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Invoice generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Cancel Add file in your module VendorYourmodulenameObserverAddcommentoncancelaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentoncancelaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Order canceled"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Shipment Add file in your module VendorYourmodulenameObserverAddcommentonshipmentaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonshipmentaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $shipment = $observer->getEvent()->getShipment();
          $order = $shipment->getOrder();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Shipment generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;







          share|improve this answer























          • Thanks Brother. It worked :)

            – user76063
            Feb 13 at 12:43













          3












          3








          3







          I recently did this work through observers



          You have to add these event in your module event file VendorYourmodulenameetcevents.xml



          For Invoice



          <event name="sales_order_invoice_register">
          <observer name="vendor_yourmodulename_observer_addcommentonaction" instance="VendorYourmodulenameObserverAddcommentonaction" />
          </event>


          For Cancel



          <event name="order_cancel_after">
          <observer name="vendor_yourmodulename_observer_addcommentoncancelaction" instance="VendorYourmodulenameObserverAddcommentoncancelaction" />
          </event>


          For Shipment



          <event name="sales_order_shipment_save_after">
          <observer name="vendor_yourmodulename_observer_addcommentonshipmentaction" instance="VendorYourmodulenameObserverAddcommentonshipmentaction" />
          </event>



          Observer files




          For Invoice Add file in your module VendorYourmodulenameObserverAddcommentonaction.php



          <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Invoice generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Cancel Add file in your module VendorYourmodulenameObserverAddcommentoncancelaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentoncancelaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Order canceled"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Shipment Add file in your module VendorYourmodulenameObserverAddcommentonshipmentaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonshipmentaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $shipment = $observer->getEvent()->getShipment();
          $order = $shipment->getOrder();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Shipment generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;







          share|improve this answer













          I recently did this work through observers



          You have to add these event in your module event file VendorYourmodulenameetcevents.xml



          For Invoice



          <event name="sales_order_invoice_register">
          <observer name="vendor_yourmodulename_observer_addcommentonaction" instance="VendorYourmodulenameObserverAddcommentonaction" />
          </event>


          For Cancel



          <event name="order_cancel_after">
          <observer name="vendor_yourmodulename_observer_addcommentoncancelaction" instance="VendorYourmodulenameObserverAddcommentoncancelaction" />
          </event>


          For Shipment



          <event name="sales_order_shipment_save_after">
          <observer name="vendor_yourmodulename_observer_addcommentonshipmentaction" instance="VendorYourmodulenameObserverAddcommentonshipmentaction" />
          </event>



          Observer files




          For Invoice Add file in your module VendorYourmodulenameObserverAddcommentonaction.php



          <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Invoice generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Cancel Add file in your module VendorYourmodulenameObserverAddcommentoncancelaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentoncancelaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $order= $observer->getData('order');
          //$order->doSomething();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Order canceled"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;




          For Shipment Add file in your module VendorYourmodulenameObserverAddcommentonshipmentaction.php



           <?php
          namespace VendorYourmodulenameObserver;

          class Addcommentonshipmentaction implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)


          $shipment = $observer->getEvent()->getShipment();
          $order = $shipment->getOrder();
          $authsession = MagentoFrameworkAppObjectManager::getInstance()->create(MagentoBackendModelAuthSession::class);
          $username = $authsession->getUser()->getUsername();


          $notify = false;
          $visible = false;
          $history = $order->addStatusHistoryComment("Shipment generated"." (".$username.")", $order->getStatus());
          $history->setIsVisibleOnFront($visible);
          $history->setIsCustomerNotified($notify);
          $history->save();

          return $this;








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 13 at 12:20









          Muhammad HashamMuhammad Hasham

          2,5581731




          2,5581731












          • Thanks Brother. It worked :)

            – user76063
            Feb 13 at 12:43

















          • Thanks Brother. It worked :)

            – user76063
            Feb 13 at 12:43
















          Thanks Brother. It worked :)

          – user76063
          Feb 13 at 12:43





          Thanks Brother. It worked :)

          – user76063
          Feb 13 at 12:43

















          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%2f261607%2fmagento-2-how-to-add-admin-username-in-order-comments-on-admin-action%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

          Sum ergo cogito? 1 nng

          三茅街道4182Guuntc Dn precexpngmageondP