Magento 2 - How to call sales_order_save_after Observer manually for testing?Unit Test for overwrite collection class in magento2sales_order_shipment_track_save_after get order IDSet custom price of product when adding to cart code not workingMagento 2: How to override newsletter Subscriber modelMagento 2: Add a product to the cart programmaticallyI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsHow to print order details for event observer sales_order_save_afterHow to alert in sales_order_save_after observer?Magento 2.2.2 error when setting order status with API

Is declining an undergraduate award which causes me discomfort appropriate?

How does a blind passenger not die, if driver becomes unconscious

Number of solutions mod p and Betti numbers

Why is it easier to balance a non-moving bike standing up than sitting down?

Understanding the reasoning of the woman who agreed with Shlomo to "cut the baby in half"

Can I enter the UK for 24 hours from a Schengen area, holding an Indian passport?

What is appropriate short form for "laboratoires" in French?

Cut the gold chain

What is the highest voltage from the power supply a Raspberry Pi 3 B can handle without getting damaged?

How can I get my left hand to sound legato when I'm leaping?

How to remove this component from PCB

Heavily limited premature compiler translates text into excecutable python code

If the Dragon's Breath spell is cast on a familiar, does it use the wizard's DC or familiar's DC?

Trainee keeps passing deadlines for independent learning

Story about hunting giant lizards for hides on privately owned planet

DBCC checkdb on tempdb

Is "Busen" just the area between the breasts?

When to remove insignificant variables?

Why are < or > required to use /dev/tcp

Why does cooking oatmeal starting with cold milk make it creamy?

What can I do with a research project that is my university’s intellectual property?

Intuition for the role of diffeomorphisms

Why does the Saturn V have standalone inter-stage rings?

Explain why a line can never intersect a plane in exactly two points.



Magento 2 - How to call sales_order_save_after Observer manually for testing?


Unit Test for overwrite collection class in magento2sales_order_shipment_track_save_after get order IDSet custom price of product when adding to cart code not workingMagento 2: How to override newsletter Subscriber modelMagento 2: Add a product to the cart programmaticallyI have created one field using product form field for my price i want save my field value at product creation time from backend magento2Magento 2.2.5: Add, Update and Delete existing products Custom OptionsHow to print order details for event observer sales_order_save_afterHow to alert in sales_order_save_after observer?Magento 2.2.2 error when setting order status with API






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















i have a working Observer on the event sales_order_save_after.
The Observer looks like this:



namespace CompanyExportOrderObserver;
use MagentoFrameworkEventObserverInterface;



class Observer implements ObserverInterface

protected $connector; public function __construct()
$objectManager = MagentoFrameworkAppObjectManager::getInstance();


public function execute(MagentoFrameworkEventObserver $observer)
$order = $observer->getEvent()->getOrder();
$orderId = $order->getId();
$customerId = $order->getCustomerId();

// do something




How am i able to call this Observer manually for testing? I don´t really want to create orders again and again. Idea is something like this:



$model = $objectManager->create('CompanyExportOrderObserverObserver');
$model->execute();


But the execute-Function expects the Observer Model, and how can i set the order id manually for testing the function?










share|improve this question






























    0















    i have a working Observer on the event sales_order_save_after.
    The Observer looks like this:



    namespace CompanyExportOrderObserver;
    use MagentoFrameworkEventObserverInterface;



    class Observer implements ObserverInterface

    protected $connector; public function __construct()
    $objectManager = MagentoFrameworkAppObjectManager::getInstance();


    public function execute(MagentoFrameworkEventObserver $observer)
    $order = $observer->getEvent()->getOrder();
    $orderId = $order->getId();
    $customerId = $order->getCustomerId();

    // do something




    How am i able to call this Observer manually for testing? I don´t really want to create orders again and again. Idea is something like this:



    $model = $objectManager->create('CompanyExportOrderObserverObserver');
    $model->execute();


    But the execute-Function expects the Observer Model, and how can i set the order id manually for testing the function?










    share|improve this question


























      0












      0








      0








      i have a working Observer on the event sales_order_save_after.
      The Observer looks like this:



      namespace CompanyExportOrderObserver;
      use MagentoFrameworkEventObserverInterface;



      class Observer implements ObserverInterface

      protected $connector; public function __construct()
      $objectManager = MagentoFrameworkAppObjectManager::getInstance();


      public function execute(MagentoFrameworkEventObserver $observer)
      $order = $observer->getEvent()->getOrder();
      $orderId = $order->getId();
      $customerId = $order->getCustomerId();

      // do something




      How am i able to call this Observer manually for testing? I don´t really want to create orders again and again. Idea is something like this:



      $model = $objectManager->create('CompanyExportOrderObserverObserver');
      $model->execute();


      But the execute-Function expects the Observer Model, and how can i set the order id manually for testing the function?










      share|improve this question
















      i have a working Observer on the event sales_order_save_after.
      The Observer looks like this:



      namespace CompanyExportOrderObserver;
      use MagentoFrameworkEventObserverInterface;



      class Observer implements ObserverInterface

      protected $connector; public function __construct()
      $objectManager = MagentoFrameworkAppObjectManager::getInstance();


      public function execute(MagentoFrameworkEventObserver $observer)
      $order = $observer->getEvent()->getOrder();
      $orderId = $order->getId();
      $customerId = $order->getCustomerId();

      // do something




      How am i able to call this Observer manually for testing? I don´t really want to create orders again and again. Idea is something like this:



      $model = $objectManager->create('CompanyExportOrderObserverObserver');
      $model->execute();


      But the execute-Function expects the Observer Model, and how can i set the order id manually for testing the function?







      magento2 event-observer sales-order sales






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 13 at 5:34









      Ahmed Zameer

      5311




      5311










      asked Jun 12 at 14:33









      LucoLuco

      61




      61




















          2 Answers
          2






          active

          oldest

          votes


















          1














          Simply create one test order and try to change status of the same order everytime. This will trigger the event sales_order_save_after



          $orderId = 1;
          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $order = $objectManager->create('MagentoSalesModelOrder') ->load($orderId);
          $orderState = "holded";
          $order->setState($orderState)->setStatus("holded");
          $order->save();





          share|improve this answer








          New contributor



          Abdul Pathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


























            0














            Try following way:



            $objectManager = MagentoFrameworkAppObjectManager::getInstance();
            /** @var MagentoSalesModelOrder $order */
            $order = $objectManager->create('MagentoSalesModelOrder')->load(1884);
            $eventManager = $objectManager->create('MagentoFrameworkEventManagerInterface');
            $eventManager->dispatch('sales_order_save_after', ['order' => $order]);





            share|improve this answer























              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%2f278138%2fmagento-2-how-to-call-sales-order-save-after-observer-manually-for-testing%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Simply create one test order and try to change status of the same order everytime. This will trigger the event sales_order_save_after



              $orderId = 1;
              $objectManager = MagentoFrameworkAppObjectManager::getInstance();
              $order = $objectManager->create('MagentoSalesModelOrder') ->load($orderId);
              $orderState = "holded";
              $order->setState($orderState)->setStatus("holded");
              $order->save();





              share|improve this answer








              New contributor



              Abdul Pathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.























                1














                Simply create one test order and try to change status of the same order everytime. This will trigger the event sales_order_save_after



                $orderId = 1;
                $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                $order = $objectManager->create('MagentoSalesModelOrder') ->load($orderId);
                $orderState = "holded";
                $order->setState($orderState)->setStatus("holded");
                $order->save();





                share|improve this answer








                New contributor



                Abdul Pathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





















                  1












                  1








                  1







                  Simply create one test order and try to change status of the same order everytime. This will trigger the event sales_order_save_after



                  $orderId = 1;
                  $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                  $order = $objectManager->create('MagentoSalesModelOrder') ->load($orderId);
                  $orderState = "holded";
                  $order->setState($orderState)->setStatus("holded");
                  $order->save();





                  share|improve this answer








                  New contributor



                  Abdul Pathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  Simply create one test order and try to change status of the same order everytime. This will trigger the event sales_order_save_after



                  $orderId = 1;
                  $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                  $order = $objectManager->create('MagentoSalesModelOrder') ->load($orderId);
                  $orderState = "holded";
                  $order->setState($orderState)->setStatus("holded");
                  $order->save();






                  share|improve this answer








                  New contributor



                  Abdul Pathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  share|improve this answer



                  share|improve this answer






                  New contributor



                  Abdul Pathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  answered Jun 12 at 15:58









                  Abdul PathanAbdul Pathan

                  1066




                  1066




                  New contributor



                  Abdul Pathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.




                  New contributor




                  Abdul Pathan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.

























                      0














                      Try following way:



                      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                      /** @var MagentoSalesModelOrder $order */
                      $order = $objectManager->create('MagentoSalesModelOrder')->load(1884);
                      $eventManager = $objectManager->create('MagentoFrameworkEventManagerInterface');
                      $eventManager->dispatch('sales_order_save_after', ['order' => $order]);





                      share|improve this answer



























                        0














                        Try following way:



                        $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                        /** @var MagentoSalesModelOrder $order */
                        $order = $objectManager->create('MagentoSalesModelOrder')->load(1884);
                        $eventManager = $objectManager->create('MagentoFrameworkEventManagerInterface');
                        $eventManager->dispatch('sales_order_save_after', ['order' => $order]);





                        share|improve this answer

























                          0












                          0








                          0







                          Try following way:



                          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          /** @var MagentoSalesModelOrder $order */
                          $order = $objectManager->create('MagentoSalesModelOrder')->load(1884);
                          $eventManager = $objectManager->create('MagentoFrameworkEventManagerInterface');
                          $eventManager->dispatch('sales_order_save_after', ['order' => $order]);





                          share|improve this answer













                          Try following way:



                          $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                          /** @var MagentoSalesModelOrder $order */
                          $order = $objectManager->create('MagentoSalesModelOrder')->load(1884);
                          $eventManager = $objectManager->create('MagentoFrameworkEventManagerInterface');
                          $eventManager->dispatch('sales_order_save_after', ['order' => $order]);






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jun 12 at 16:53









                          Sohel RanaSohel Rana

                          24.5k34765




                          24.5k34765



























                              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%2f278138%2fmagento-2-how-to-call-sales-order-save-after-observer-manually-for-testing%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