I am trying to observe an event when the order is placed but is not working for me. I tried with "sales_order_place_after" and "checkout_submit_all_after" events but nothing happens. The "test.log" file is not generated.
My "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="sales_order_place_after">
<observer name="send_order_tracy" instance="Tracy\ShippingMethod\Observer\SendOrderToTracy"/>
</event>
</config>
My observer class:
<?php
namespace Tracy\ShippingMethod\Observer;
class SendOrderToTracy implements \Magento\Framework\Event\ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$writer = new \Zend\Log\Writer\Stream(BP.'/var/log/test.log'); // creates new log file named test.log in var/log folder
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info("oe repinga plaicié la orden"); // this will be print in test.log file
}
}
I tried with the first event and later with the other one, changing just the event name. Is that correct? Do I need to compile or something like that? I am just flushing cache.