Event when order created from backendExecute custom Javascript code in Frontend/Admin on sales_order_place_after eventgetting order details from sales_order_save_commit_after eventEvent to trigger when admin Hold an order500 when trying to create order on the backendEvent to use when order comment is postCan not called my CreateController while edit an order from backendMagento 2: How to override newsletter Subscriber modelMagento2 - plugin / event after invoice is createdmagento simple popup when create order from adminError creating new order from Backend

Do beef farmed pastures net remove carbon emissions?

What is a "soap"?

My cat is a houdini

What kind of liquid can be seen 'leaking' from the upper surface of the wing of a Boeing 737-800?

Clarification on Integrability

Why did Saruman lie?

Swap on SSD in 2019?

Are there really no countries that protect Freedom of Speech as the United States does?

Corroded Metal vs Magical Armor, should it melt it?

Help, I cannot decide when to start the story

Should I email my professor about a recommendation letter if he has offered me a job?

Why is Python 2.7 still the default Python version in Ubuntu?

PhD advisor lost funding, need advice

Can a bald person be a Nazir?

Boss wants me to ignore a software API license prohibiting mass download

How can I communicate my issues with a potential date's pushy behavior?

How was the murder committed?

In which case does the Security misconfiguration vulnerability apply to?

What is the farthest a camera can see?

Symbol: Put a smile symbol under a plus

What is the hottest thing in the universe?

Is this n-speak?

What can Amex do if I cancel their card after using the sign up bonus miles?

Word for an event that will likely never happen again



Event when order created from backend


Execute custom Javascript code in Frontend/Admin on sales_order_place_after eventgetting order details from sales_order_save_commit_after eventEvent to trigger when admin Hold an order500 when trying to create order on the backendEvent to use when order comment is postCan not called my CreateController while edit an order from backendMagento 2: How to override newsletter Subscriber modelMagento2 - plugin / event after invoice is createdmagento simple popup when create order from adminError creating new order from Backend






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








0















I've used sales_order_place_after to get order id after order placed from backend but it doesnt return order id. Not sure what's missing here.



Here's my observer



public function execute(MagentoFrameworkEventObserver $observer)

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



Above code executed but if it doesnt print order id.



Any suggestions for this ? For all those who are curious I need to store order data after order plaed into custom table.










share|improve this question


























  • make sure you place events.xml under etc/adminhtml

    – MSA
    Aug 2 at 9:57











  • have you solved your problem?

    – Ketan Borada
    Aug 10 at 8:50











  • Yes I was able to solve issue.

    – Vivek
    2 days ago

















0















I've used sales_order_place_after to get order id after order placed from backend but it doesnt return order id. Not sure what's missing here.



Here's my observer



public function execute(MagentoFrameworkEventObserver $observer)

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



Above code executed but if it doesnt print order id.



Any suggestions for this ? For all those who are curious I need to store order data after order plaed into custom table.










share|improve this question


























  • make sure you place events.xml under etc/adminhtml

    – MSA
    Aug 2 at 9:57











  • have you solved your problem?

    – Ketan Borada
    Aug 10 at 8:50











  • Yes I was able to solve issue.

    – Vivek
    2 days ago













0












0








0








I've used sales_order_place_after to get order id after order placed from backend but it doesnt return order id. Not sure what's missing here.



Here's my observer



public function execute(MagentoFrameworkEventObserver $observer)

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



Above code executed but if it doesnt print order id.



Any suggestions for this ? For all those who are curious I need to store order data after order plaed into custom table.










share|improve this question
















I've used sales_order_place_after to get order id after order placed from backend but it doesnt return order id. Not sure what's missing here.



Here's my observer



public function execute(MagentoFrameworkEventObserver $observer)

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



Above code executed but if it doesnt print order id.



Any suggestions for this ? For all those who are curious I need to store order data after order plaed into custom table.







magento2 event-observer admin-order-create






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 2 at 9:58









Limbani Himanshu

3321 silver badge9 bronze badges




3321 silver badge9 bronze badges










asked Aug 2 at 9:46









VivekVivek

1,9991 gold badge9 silver badges38 bronze badges




1,9991 gold badge9 silver badges38 bronze badges















  • make sure you place events.xml under etc/adminhtml

    – MSA
    Aug 2 at 9:57











  • have you solved your problem?

    – Ketan Borada
    Aug 10 at 8:50











  • Yes I was able to solve issue.

    – Vivek
    2 days ago

















  • make sure you place events.xml under etc/adminhtml

    – MSA
    Aug 2 at 9:57











  • have you solved your problem?

    – Ketan Borada
    Aug 10 at 8:50











  • Yes I was able to solve issue.

    – Vivek
    2 days ago
















make sure you place events.xml under etc/adminhtml

– MSA
Aug 2 at 9:57





make sure you place events.xml under etc/adminhtml

– MSA
Aug 2 at 9:57













have you solved your problem?

– Ketan Borada
Aug 10 at 8:50





have you solved your problem?

– Ketan Borada
Aug 10 at 8:50













Yes I was able to solve issue.

– Vivek
2 days ago





Yes I was able to solve issue.

– Vivek
2 days ago










2 Answers
2






active

oldest

votes


















0














You need to just change your code like this.



public function execute(MagentoFrameworkEventObserver $observer)

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






share|improve this answer

























  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:38


















0














add observer only for admin appcodeVendorModuleetcadminhtmlevents.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="sales_order_place_after">
<observer name="load_custom_handler" instance="VendorModuleObserverGetOrder" />
</event>
</config>


add observer file appcodeVendorModuleObserverGetOrder.php



<?php 
namespace VendorModuleObserver;
use MagentoFrameworkEventObserverInterface;

class GetOrder implements ObserverInterface

protected $orderFactory;

public function __construct(MagentoSalesModelOrder $orderFactory)

$this->orderFactory = $orderFactory;


public function execute(MagentoFrameworkEventObserver $observer)


$orderIds = $observer->getEvent()->getOrderIds();
$orderId= $orderIds[0]; //Do your logic here

$order = $this->orderFactory->load($orderId);







share|improve this answer



























  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:37












  • i've updated my answer

    – Ketan Borada
    Aug 2 at 10:58













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%2f284206%2fevent-when-order-created-from-backend%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









0














You need to just change your code like this.



public function execute(MagentoFrameworkEventObserver $observer)

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






share|improve this answer

























  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:38















0














You need to just change your code like this.



public function execute(MagentoFrameworkEventObserver $observer)

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






share|improve this answer

























  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:38













0












0








0







You need to just change your code like this.



public function execute(MagentoFrameworkEventObserver $observer)

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






share|improve this answer













You need to just change your code like this.



public function execute(MagentoFrameworkEventObserver $observer)

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







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 2 at 10:13









Dhiren VasoyaDhiren Vasoya

4,9305 gold badges20 silver badges47 bronze badges




4,9305 gold badges20 silver badges47 bronze badges















  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:38

















  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:38
















Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

– Vivek
Aug 2 at 10:38





Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

– Vivek
Aug 2 at 10:38













0














add observer only for admin appcodeVendorModuleetcadminhtmlevents.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="sales_order_place_after">
<observer name="load_custom_handler" instance="VendorModuleObserverGetOrder" />
</event>
</config>


add observer file appcodeVendorModuleObserverGetOrder.php



<?php 
namespace VendorModuleObserver;
use MagentoFrameworkEventObserverInterface;

class GetOrder implements ObserverInterface

protected $orderFactory;

public function __construct(MagentoSalesModelOrder $orderFactory)

$this->orderFactory = $orderFactory;


public function execute(MagentoFrameworkEventObserver $observer)


$orderIds = $observer->getEvent()->getOrderIds();
$orderId= $orderIds[0]; //Do your logic here

$order = $this->orderFactory->load($orderId);







share|improve this answer



























  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:37












  • i've updated my answer

    – Ketan Borada
    Aug 2 at 10:58















0














add observer only for admin appcodeVendorModuleetcadminhtmlevents.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="sales_order_place_after">
<observer name="load_custom_handler" instance="VendorModuleObserverGetOrder" />
</event>
</config>


add observer file appcodeVendorModuleObserverGetOrder.php



<?php 
namespace VendorModuleObserver;
use MagentoFrameworkEventObserverInterface;

class GetOrder implements ObserverInterface

protected $orderFactory;

public function __construct(MagentoSalesModelOrder $orderFactory)

$this->orderFactory = $orderFactory;


public function execute(MagentoFrameworkEventObserver $observer)


$orderIds = $observer->getEvent()->getOrderIds();
$orderId= $orderIds[0]; //Do your logic here

$order = $this->orderFactory->load($orderId);







share|improve this answer



























  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:37












  • i've updated my answer

    – Ketan Borada
    Aug 2 at 10:58













0












0








0







add observer only for admin appcodeVendorModuleetcadminhtmlevents.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="sales_order_place_after">
<observer name="load_custom_handler" instance="VendorModuleObserverGetOrder" />
</event>
</config>


add observer file appcodeVendorModuleObserverGetOrder.php



<?php 
namespace VendorModuleObserver;
use MagentoFrameworkEventObserverInterface;

class GetOrder implements ObserverInterface

protected $orderFactory;

public function __construct(MagentoSalesModelOrder $orderFactory)

$this->orderFactory = $orderFactory;


public function execute(MagentoFrameworkEventObserver $observer)


$orderIds = $observer->getEvent()->getOrderIds();
$orderId= $orderIds[0]; //Do your logic here

$order = $this->orderFactory->load($orderId);







share|improve this answer















add observer only for admin appcodeVendorModuleetcadminhtmlevents.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="sales_order_place_after">
<observer name="load_custom_handler" instance="VendorModuleObserverGetOrder" />
</event>
</config>


add observer file appcodeVendorModuleObserverGetOrder.php



<?php 
namespace VendorModuleObserver;
use MagentoFrameworkEventObserverInterface;

class GetOrder implements ObserverInterface

protected $orderFactory;

public function __construct(MagentoSalesModelOrder $orderFactory)

$this->orderFactory = $orderFactory;


public function execute(MagentoFrameworkEventObserver $observer)


$orderIds = $observer->getEvent()->getOrderIds();
$orderId= $orderIds[0]; //Do your logic here

$order = $this->orderFactory->load($orderId);








share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 2 at 10:58

























answered Aug 2 at 10:11









Ketan BoradaKetan Borada

1,00913 silver badges41 bronze badges




1,00913 silver badges41 bronze badges















  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:37












  • i've updated my answer

    – Ketan Borada
    Aug 2 at 10:58

















  • Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

    – Vivek
    Aug 2 at 10:37












  • i've updated my answer

    – Ketan Borada
    Aug 2 at 10:58
















Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

– Vivek
Aug 2 at 10:37






Its not working cant able to get order id error is "An ID is needed. Set the ID and try again."

– Vivek
Aug 2 at 10:37














i've updated my answer

– Ketan Borada
Aug 2 at 10:58





i've updated my answer

– Ketan Borada
Aug 2 at 10:58

















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%2f284206%2fevent-when-order-created-from-backend%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

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

Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?