How to get order event after placing order using observer in admin side?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
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
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
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
magento2 orders event-observer
edited Nov 12 at 9:11
PY Yick
1,629720
1,629720
asked Nov 12 at 8:09
sheraz khan
10811
10811
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
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.
thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;
– sheraz khan
Nov 12 at 9:33
add a comment |
up vote
1
down vote
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();
thanks for the help !
– sheraz khan
Nov 12 at 9:34
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
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.
thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;
– sheraz khan
Nov 12 at 9:33
add a comment |
up vote
3
down vote
accepted
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.
thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;
– sheraz khan
Nov 12 at 9:33
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
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.
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.
answered Nov 12 at 9:12
Ramkishan Suthar
1,4161829
1,4161829
thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;
– sheraz khan
Nov 12 at 9:33
add a comment |
thanks for pointing out the mistake,one another mistake of namespace, namespace should be namespace VendorModuleObserver; instead of VendorModuleModelObserver;
– sheraz khan
Nov 12 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 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 at 9:33
add a comment |
up vote
1
down vote
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();
thanks for the help !
– sheraz khan
Nov 12 at 9:34
add a comment |
up vote
1
down vote
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();
thanks for the help !
– sheraz khan
Nov 12 at 9:34
add a comment |
up vote
1
down vote
up vote
1
down vote
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();
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();
answered Nov 12 at 8:43
Raul Sanchez
1,84131134
1,84131134
thanks for the help !
– sheraz khan
Nov 12 at 9:34
add a comment |
thanks for the help !
– sheraz khan
Nov 12 at 9:34
thanks for the help !
– sheraz khan
Nov 12 at 9:34
thanks for the help !
– sheraz khan
Nov 12 at 9:34
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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