I am working on Magento 2 platform. I have created my custom modue name MerchantTrack. Into events.xml (MagentoSite\app\code\Magento\MerchantTrack\Checkout\etc\frontend\events.xml) written code 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="checkout_onepage_controller_success_action ">
<observer name="merchanttrack_checkout_onepage_controller_success_action" instance="Magento\MerchantTrack\Checkout\Observer\MyObserver" />
</event>
</config>
Into MyObserver.php(MagentoSite\app\code\Magento\MerchantTrack\Checkout\Observer\MyObserver.php) written code below
<?php
namespace Magento\MerchantTrack\Checkout\Observer;
use Magento\Framework\Event\ObserverInterface;
class MyObserver implements ObserverInterface {
public function execute(\Magento\Framework\Event\Observer $observer)
{
$orderIds = $observer->getEvent()->getOrderIds();
echo $orderId = $orderIds[0]; exit;
}
}
When placed order, into success (/MagentoSite/checkout/onepage/success/) page i can not see orderid which i echo into observer page. So I can not understand my event is fired or not.
What am I doing wrong?
You have to follow module directory structure properly. See: https://devdocs.magento.com/guides/v2.3/extension-dev-guide/build/module-file-structure.html#module-file-structure
MagentoSite\app\code\Magento\MerchantTrack\Checkout\etc\frontend\events.xml
You have created extra folder i.e Magento
Your directory should look like this. MagentoSite\app\code\MerchantTrack\Checkout\etc\frontend\events.xml