How to get order event after placing order using observer in admin side?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingMagento 2 : Problem while adding custom button order view page?Get order in observer after placing orderLeft join order grid collection using observer method. Magento 1.9Magento 2.2.5: Overriding Admin Controller sales/orderI 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 Options

ssTTsSTtRrriinInnnnNNNIiinngg

Examples of smooth manifolds admitting inbetween one and a continuum of complex structures

How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)

Can my sorcerer use a spellbook only to collect spells and scribe scrolls, not cast?

Can I run a new neutral wire to repair a broken circuit?

What about the virus in 12 Monkeys?

Do scales need to be in alphabetical order?

One verb to replace 'be a member of' a club

Which is the best way to check return result?

What is the most common color to indicate the input-field is disabled?

Cursor Replacement for Newbies

Apex Framework / library for consuming REST services

What exploit Are these user agents trying to use?

Why didn't Boeing produce its own regional jet?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

Why is this clock signal connected to a capacitor to gnd?

Is it acceptable for a professor to tell male students to not think that they are smarter than female students?

Venezuelan girlfriend wants to travel the USA to be with me. What is the process?

Is it logically or scientifically possible to artificially send energy to the body?

What killed these X2 caps?

What is the idiomatic way to say "clothing fits"?

What method can I use to design a dungeon difficult enough that the PCs can't make it through without killing them?

How badly should I try to prevent a user from XSSing themselves?

How much of data wrangling is a data scientist's job?



How to get order event after placing order using observer in admin side?


How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existSet custom price of product when adding to cart code not workingMagento 2 : Problem while adding custom button order view page?Get order in observer after placing orderLeft join order grid collection using observer method. Magento 1.9Magento 2.2.5: Overriding Admin Controller sales/orderI 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 Options













2















i want to get the order event and want to use the order object data , tried this but something is missing, here is what i tried
and how can i use this data in my helper/block class or controller action?




etc/adminhtml/events.xml




<?xml version="1.0"?>


<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

<event name="test_order">
<observer name="afterOrderObserver" instance="VendorModuleObserverOrder"/>
</event>
</config>



Observer/TestOrder.php




<?php

namespace VendorModuleModelObserver;

use MagentoFrameworkEventObserverInterface;

class TestOrder implements ObserverInterface

/**
* Order Model
*
* @var MagentoSalesModelOrder $order
*/
protected $order;

public function __construct(
MagentoSalesModelOrder $order
)

$this->order = $order;


public function execute(MagentoFrameworkEventObserver $observer)

$orderId = $observer->getEvent()->getOrderIds();
$order = $this->order->load($orderId);

//get Order All Item
$itemCollection = $order->getItemsCollection();
$customer = $order->getCustomerId(); // using this id you can get customer name












share|improve this question




























    2















    i want to get the order event and want to use the order object data , tried this but something is missing, here is what i tried
    and how can i use this data in my helper/block class or controller action?




    etc/adminhtml/events.xml




    <?xml version="1.0"?>


    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

    <event name="test_order">
    <observer name="afterOrderObserver" instance="VendorModuleObserverOrder"/>
    </event>
    </config>



    Observer/TestOrder.php




    <?php

    namespace VendorModuleModelObserver;

    use MagentoFrameworkEventObserverInterface;

    class TestOrder implements ObserverInterface

    /**
    * Order Model
    *
    * @var MagentoSalesModelOrder $order
    */
    protected $order;

    public function __construct(
    MagentoSalesModelOrder $order
    )

    $this->order = $order;


    public function execute(MagentoFrameworkEventObserver $observer)

    $orderId = $observer->getEvent()->getOrderIds();
    $order = $this->order->load($orderId);

    //get Order All Item
    $itemCollection = $order->getItemsCollection();
    $customer = $order->getCustomerId(); // using this id you can get customer name












    share|improve this question


























      2












      2








      2








      i want to get the order event and want to use the order object data , tried this but something is missing, here is what i tried
      and how can i use this data in my helper/block class or controller action?




      etc/adminhtml/events.xml




      <?xml version="1.0"?>


      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

      <event name="test_order">
      <observer name="afterOrderObserver" instance="VendorModuleObserverOrder"/>
      </event>
      </config>



      Observer/TestOrder.php




      <?php

      namespace VendorModuleModelObserver;

      use MagentoFrameworkEventObserverInterface;

      class TestOrder implements ObserverInterface

      /**
      * Order Model
      *
      * @var MagentoSalesModelOrder $order
      */
      protected $order;

      public function __construct(
      MagentoSalesModelOrder $order
      )

      $this->order = $order;


      public function execute(MagentoFrameworkEventObserver $observer)

      $orderId = $observer->getEvent()->getOrderIds();
      $order = $this->order->load($orderId);

      //get Order All Item
      $itemCollection = $order->getItemsCollection();
      $customer = $order->getCustomerId(); // using this id you can get customer name












      share|improve this question
















      i want to get the order event and want to use the order object data , tried this but something is missing, here is what i tried
      and how can i use this data in my helper/block class or controller action?




      etc/adminhtml/events.xml




      <?xml version="1.0"?>


      <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

      <event name="test_order">
      <observer name="afterOrderObserver" instance="VendorModuleObserverOrder"/>
      </event>
      </config>



      Observer/TestOrder.php




      <?php

      namespace VendorModuleModelObserver;

      use MagentoFrameworkEventObserverInterface;

      class TestOrder implements ObserverInterface

      /**
      * Order Model
      *
      * @var MagentoSalesModelOrder $order
      */
      protected $order;

      public function __construct(
      MagentoSalesModelOrder $order
      )

      $this->order = $order;


      public function execute(MagentoFrameworkEventObserver $observer)

      $orderId = $observer->getEvent()->getOrderIds();
      $order = $this->order->load($orderId);

      //get Order All Item
      $itemCollection = $order->getItemsCollection();
      $customer = $order->getCustomerId(); // using this id you can get customer name









      magento2 orders event-observer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 '18 at 9:11









      PY Yick

      1,795821




      1,795821










      asked Nov 12 '18 at 8:09









      sheraz khansheraz khan

      17011




      17011




















          3 Answers
          3






          active

          oldest

          votes


















          3














          Please modify your code like below



           <?xml version="1.0"?>
          <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

          <event name="sales_order_place_after">
          <observer name="order_data" instance="VendorModuleObserverOrderData" />
          </event>
          </config>


          OrderData.php



          class OrderData implements MagentoFrameworkEventObserverInterface

          public function execute(MagentoFrameworkEventObserver $observer)

          $order = $observer->getEvent()->getOrder();
          echo $order->getId();
          exit;




          make sure you place events.xml under etc/adminhtml let me know if any help needed.






          share|improve this answer























          • thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;

            – sheraz khan
            Nov 12 '18 at 9:33



















          1














          Event name tag indicates the name of the event you want to observe



          In your case you'd take a look at vendor/magento/module-sales/Model/Order.php class, in concrete place() method. You'll see 2 events fired there



          public function place()

          $this->_eventManager->dispatch('sales_order_place_before', ['order' => $this]);
          $this->_placePayment();
          $this->_eventManager->dispatch('sales_order_place_after', ['order' => $this]);
          return $this;



          If you want to run your code after order has been placed, then you should change



          <event name="test_order">


          And use



          <event name="sales_order_place_after">


          Note that the object attached to this event is $order, you should be able to access it in your observer using



          $order = $observer->getEvent()->getOrder();





          share|improve this answer






























            0














            I'm finding that and Observer for sales_order_place_after and code -



            $order = $observer->getEvent()->getOrder();
            $orderID = $order->getId();



            Returns a null orderID, although the event does return an order.
            As per the rules of the Observer, the Event.xml goes into neither the frontend nor the adminhtml directories since this event is fired from both areas. I did (just for fun)try placing the event in adminhtml but it didn't trigger the observer.



            I'm thinking that the orderid is not yet assigned at this point, as It's not the call to ->orderId(), sine in the debugger the order object itself has a null orderid.



            Anyone else run into this timing issue?





            share























              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%2f249687%2fhow-to-get-order-event-after-placing-order-using-observer-in-admin-side%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              Please modify your code like below



               <?xml version="1.0"?>
              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

              <event name="sales_order_place_after">
              <observer name="order_data" instance="VendorModuleObserverOrderData" />
              </event>
              </config>


              OrderData.php



              class OrderData implements MagentoFrameworkEventObserverInterface

              public function execute(MagentoFrameworkEventObserver $observer)

              $order = $observer->getEvent()->getOrder();
              echo $order->getId();
              exit;




              make sure you place events.xml under etc/adminhtml let me know if any help needed.






              share|improve this answer























              • thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;

                – sheraz khan
                Nov 12 '18 at 9:33
















              3














              Please modify your code like below



               <?xml version="1.0"?>
              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

              <event name="sales_order_place_after">
              <observer name="order_data" instance="VendorModuleObserverOrderData" />
              </event>
              </config>


              OrderData.php



              class OrderData implements MagentoFrameworkEventObserverInterface

              public function execute(MagentoFrameworkEventObserver $observer)

              $order = $observer->getEvent()->getOrder();
              echo $order->getId();
              exit;




              make sure you place events.xml under etc/adminhtml let me know if any help needed.






              share|improve this answer























              • thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;

                – sheraz khan
                Nov 12 '18 at 9:33














              3












              3








              3







              Please modify your code like below



               <?xml version="1.0"?>
              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

              <event name="sales_order_place_after">
              <observer name="order_data" instance="VendorModuleObserverOrderData" />
              </event>
              </config>


              OrderData.php



              class OrderData implements MagentoFrameworkEventObserverInterface

              public function execute(MagentoFrameworkEventObserver $observer)

              $order = $observer->getEvent()->getOrder();
              echo $order->getId();
              exit;




              make sure you place events.xml under etc/adminhtml let me know if any help needed.






              share|improve this answer













              Please modify your code like below



               <?xml version="1.0"?>
              <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">

              <event name="sales_order_place_after">
              <observer name="order_data" instance="VendorModuleObserverOrderData" />
              </event>
              </config>


              OrderData.php



              class OrderData implements MagentoFrameworkEventObserverInterface

              public function execute(MagentoFrameworkEventObserver $observer)

              $order = $observer->getEvent()->getOrder();
              echo $order->getId();
              exit;




              make sure you place events.xml under etc/adminhtml let me know if any help needed.







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 12 '18 at 9:12









              Ramkishan SutharRamkishan Suthar

              2,28721435




              2,28721435












              • thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;

                – sheraz khan
                Nov 12 '18 at 9:33


















              • thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;

                – sheraz khan
                Nov 12 '18 at 9:33

















              thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;

              – sheraz khan
              Nov 12 '18 at 9:33






              thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;

              – sheraz khan
              Nov 12 '18 at 9:33














              1














              Event name tag indicates the name of the event you want to observe



              In your case you'd take a look at vendor/magento/module-sales/Model/Order.php class, in concrete place() method. You'll see 2 events fired there



              public function place()

              $this->_eventManager->dispatch('sales_order_place_before', ['order' => $this]);
              $this->_placePayment();
              $this->_eventManager->dispatch('sales_order_place_after', ['order' => $this]);
              return $this;



              If you want to run your code after order has been placed, then you should change



              <event name="test_order">


              And use



              <event name="sales_order_place_after">


              Note that the object attached to this event is $order, you should be able to access it in your observer using



              $order = $observer->getEvent()->getOrder();





              share|improve this answer



























                1














                Event name tag indicates the name of the event you want to observe



                In your case you'd take a look at vendor/magento/module-sales/Model/Order.php class, in concrete place() method. You'll see 2 events fired there



                public function place()

                $this->_eventManager->dispatch('sales_order_place_before', ['order' => $this]);
                $this->_placePayment();
                $this->_eventManager->dispatch('sales_order_place_after', ['order' => $this]);
                return $this;



                If you want to run your code after order has been placed, then you should change



                <event name="test_order">


                And use



                <event name="sales_order_place_after">


                Note that the object attached to this event is $order, you should be able to access it in your observer using



                $order = $observer->getEvent()->getOrder();





                share|improve this answer

























                  1












                  1








                  1







                  Event name tag indicates the name of the event you want to observe



                  In your case you'd take a look at vendor/magento/module-sales/Model/Order.php class, in concrete place() method. You'll see 2 events fired there



                  public function place()

                  $this->_eventManager->dispatch('sales_order_place_before', ['order' => $this]);
                  $this->_placePayment();
                  $this->_eventManager->dispatch('sales_order_place_after', ['order' => $this]);
                  return $this;



                  If you want to run your code after order has been placed, then you should change



                  <event name="test_order">


                  And use



                  <event name="sales_order_place_after">


                  Note that the object attached to this event is $order, you should be able to access it in your observer using



                  $order = $observer->getEvent()->getOrder();





                  share|improve this answer













                  Event name tag indicates the name of the event you want to observe



                  In your case you'd take a look at vendor/magento/module-sales/Model/Order.php class, in concrete place() method. You'll see 2 events fired there



                  public function place()

                  $this->_eventManager->dispatch('sales_order_place_before', ['order' => $this]);
                  $this->_placePayment();
                  $this->_eventManager->dispatch('sales_order_place_after', ['order' => $this]);
                  return $this;



                  If you want to run your code after order has been placed, then you should change



                  <event name="test_order">


                  And use



                  <event name="sales_order_place_after">


                  Note that the object attached to this event is $order, you should be able to access it in your observer using



                  $order = $observer->getEvent()->getOrder();






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 '18 at 8:43









                  Raul SanchezRaul Sanchez

                  2,16031335




                  2,16031335





















                      0














                      I'm finding that and Observer for sales_order_place_after and code -



                      $order = $observer->getEvent()->getOrder();
                      $orderID = $order->getId();



                      Returns a null orderID, although the event does return an order.
                      As per the rules of the Observer, the Event.xml goes into neither the frontend nor the adminhtml directories since this event is fired from both areas. I did (just for fun)try placing the event in adminhtml but it didn't trigger the observer.



                      I'm thinking that the orderid is not yet assigned at this point, as It's not the call to ->orderId(), sine in the debugger the order object itself has a null orderid.



                      Anyone else run into this timing issue?





                      share



























                        0














                        I'm finding that and Observer for sales_order_place_after and code -



                        $order = $observer->getEvent()->getOrder();
                        $orderID = $order->getId();



                        Returns a null orderID, although the event does return an order.
                        As per the rules of the Observer, the Event.xml goes into neither the frontend nor the adminhtml directories since this event is fired from both areas. I did (just for fun)try placing the event in adminhtml but it didn't trigger the observer.



                        I'm thinking that the orderid is not yet assigned at this point, as It's not the call to ->orderId(), sine in the debugger the order object itself has a null orderid.



                        Anyone else run into this timing issue?





                        share

























                          0












                          0








                          0







                          I'm finding that and Observer for sales_order_place_after and code -



                          $order = $observer->getEvent()->getOrder();
                          $orderID = $order->getId();



                          Returns a null orderID, although the event does return an order.
                          As per the rules of the Observer, the Event.xml goes into neither the frontend nor the adminhtml directories since this event is fired from both areas. I did (just for fun)try placing the event in adminhtml but it didn't trigger the observer.



                          I'm thinking that the orderid is not yet assigned at this point, as It's not the call to ->orderId(), sine in the debugger the order object itself has a null orderid.



                          Anyone else run into this timing issue?





                          share













                          I'm finding that and Observer for sales_order_place_after and code -



                          $order = $observer->getEvent()->getOrder();
                          $orderID = $order->getId();



                          Returns a null orderID, although the event does return an order.
                          As per the rules of the Observer, the Event.xml goes into neither the frontend nor the adminhtml directories since this event is fired from both areas. I did (just for fun)try placing the event in adminhtml but it didn't trigger the observer.



                          I'm thinking that the orderid is not yet assigned at this point, as It's not the call to ->orderId(), sine in the debugger the order object itself has a null orderid.



                          Anyone else run into this timing issue?






                          share











                          share


                          share










                          answered 9 mins ago









                          Phil SchmidtPhil Schmidt

                          111




                          111



























                              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%2f249687%2fhow-to-get-order-event-after-placing-order-using-observer-in-admin-side%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

                              Disable / Remove link to Product Items in Cart Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How can I limit products that can be bought / added to cart?Remove item from cartHide “Add to Cart” button if specific products are already in cart“Prettifying” the custom options in cart pageCreate link in cart sidebar to view all added items After limit reachedLink products together in checkout/cartHow to Get product from cart and add it againHide action-edit on cart page if simple productRemoving Cart items - ObserverRemove wishlist items when added to cart

                              Helsingin valtaus Sisällysluettelo Taustaa | Yleistä sotatoimista | Osapuolet | Taistelut Helsingin ympäristössä | Punaisten antautumissuunnitelma | Taistelujen kulku Helsingissä | Valtauksen jälkeen | Tappiot | Muistaminen | Kirjallisuutta | Lähteet | Aiheesta muualla | NavigointivalikkoTeoksen verkkoversioTeoksen verkkoversioGoogle BooksSisällissota Helsingissä päättyi tasan 95 vuotta sittenSaksalaisten ylivoima jyräsi punaisen HelsinginSuomalaiset kuvaavat sotien jälkiä kaupungeissa – katso kuvat ja tarinat tutuilta kulmiltaHelsingin valtaus 90 vuotta sittenSaksalaiset valtasivat HelsinginHyökkäys HelsinkiinHelsingin valtaus 12.–13.4. 1918Saksalaiset käyttivät ihmiskilpiä Helsingin valtauksessa 1918Teoksen verkkoversioTeoksen verkkoversioSaksalaiset hyökkäävät Etelä-SuomeenTaistelut LeppävaarassaSotilaat ja taistelutLeppävaara 1918 huhtikuussa. KapinatarinaHelsingin taistelut 1918Saksalaisten voitonparaati HelsingissäHelsingin valtausta juhlittiinSaksalaisten Helsinki vuonna 1918Helsingin taistelussa kaatuneet valkokaartilaisetHelsinkiin haudatut taisteluissa kaatuneet punaiset12.4.1918 Helsingin valtauksessa saksalaiset apujoukot vapauttavat kaupunginVapaussodan muistomerkkejä Helsingissä ja pääkaupunkiseudullaCrescendo / Vuoden 1918 Kansalaissodan uhrien muistomerkkim

                              Adjektiivitarina Tarinan tekeminen | Esimerkki: ennen | Esimerkki: jälkeen | Navigointivalikko