I have been trying to resolve this issue for 2 days but cannot seem to find the issue why the observers won't trigger. I hope some good soul out there might spot the issue and help me out on this on.
Background: I want to write an observers which are triggered when an item is added to the cart and when the order was confirmed/checked out. The observers will ultimately update some customField in Jira and get some files into the magento database as well. But currently they should just write two files into the /tmp directory.
etc/webapi_rest/events.xml
<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="jira-confirmation-update" instance="one\two\Observer\JiraConfirmationUpdate" />
</event>
<event name="checkout_cart_add_product_complete">
<observer name="jira-get-attachments" instance="one\two\Observer\JiraGetAttachments" />
</event>
</config>
Observer/JiraConfirmationUpdate.php
<?php
namespace one\two\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class JiraConfirmationUpdate implements ObserverInterface
{
public function __construct()
{
}
public function execute(Observer $observer)
{
$fp = fopen('/tmp/confirm.txt', 'w');
fwrite($fp, 'order confirmed!');
fclose($fp);
}
}
?>
Observer/JiraGetAttachments.php
<?php
namespace one\two\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class JiraGetAttachments implements ObserverInterface
{
public function __construct()
{
}
public function execute(Observer $observer)
{
$fp = fopen('/tmp/add2cart.txt', 'w');
fwrite($fp, 'getting attachments!');
fclose($fp);
}
}
?>
just on a side note, when i run php JiraGetAttachments.php in the terminal i get the error
PHP Fatal error: Interface 'Magento\Framework\Event\ObserverInterface' not found in /var/www/html/app/code/one/two/Observer/JiraConfirmationUpdate.php on line 7
is that the an usual behaviour?
EDIT for some reason after enabling the module I can not checkout anymore, disabling the module will make it possible to checkout again...