Updated:
I am trying to make an observer which on order confirmation, prints This Works in debug.log file.
When clicking on Place Order in checkout, the Observer gives 500 Internal Server Error with this in console with this in the error log:
<b>Fatal error</b>: Class 'My/Plugin/Observer/Dummy' not found in <b>/var/www/html/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php</b> on line <b>97</b>
Also, my checkout hangs when clicked on Place Order.
My app/code/My/Plugin/Observer/Dummy.php File:
<?php
namespace My\Plugin\Observer;
use Magento\Framework\Event\ObserverInterface;
class Dummy implements ObserverInterface
{
protected $_logger;
public function __construct(
\Psr\Log\LoggerInterface $logger,
array $data = []
) {
$this->_logger = $logger;
}
public function execute(\Magento\Framework\Event\Observer $observer) {
$event = $observer->getEvent();
$quote = $event->getQuote();
$myfile = fopen("var/log/debug.log", "a+") or die("Unable to open file!");
fwrite($myfile, print("This Works"));
fclose($myfile);
}
}
My app/code/My/Plugin/etc/events.xml File:
<?xml version="1.0" encoding="UTF-8" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_save_commit_after">
<observer name="my_sales_observer" instance="My/Plugin/Observer/Dummy" />
</event>
</config>
Any Idea where am I doing wrong??
My/Plugin
is just a placeholder forInfinia/SalesOrder
or that's how the files are named in your code?