I wanted to save the orders from magento2
to my local Database
.
I am planning to Create a module
and add Observer
to catch once a order is placed
.
I don't know much about the Events & observer
, just gone through this link
Please help me is there any Event
already given by Magento2
after new Order
. if there is no default event for Order placement Where do I have to write a event for new order.
Thanks in Advance.
Edit:
app\code\Autosynch\Sale\registration.php
<?php /**
* Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Autosynch_sale',
__DIR__
);
app\cpde\Autosynch\Sale\Observer\OrderPlaceAfter.php
<?php
namespace Autosynch\Sale\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;
use \Psr\Log\LoggerInterface;
class OrderPlaceAfter implements ObserverInterface
{
public function execute(Observer $observer, LoggerInterface $logger)
{
$order = $observer->getEvent()->getOrder();
$logger->info($order->getData());
$logger->debug($order->getData());
var_dump($order->getData());
exit;
}
}
app\code\Autosynch\Sale\etc\module.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details.
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Autosynch_Sale" setup_version="0.0.1">
</module>
</config>
app\code\Autosynch\Sale\etc\event.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="checkout_submit_all_after">
<observer name="modulename_sales_order_place_after" instance="Autosynch\Sale\Observer\OrderPlaceAfter" />
</event>
</config>
Please help me where I am missing.