php - Magento 2 event observer not working -


i'm trying create simple event observer magento 2 page.

app/code/ndac/orderinfo/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="sales_order_place_after">        <observer name="orderinfo" instance="ndac\orderinfo\observer\orderinfo" />    </event>  </config> 

app/code/ndac/orderinfo/etc/module.xml

<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:nonamespaceschemalocation="urn:magento:framework:module/etc/module.xsd">     <module name="orderinfo" setup_version="1.0.0"></module> </config> 

app/code/ndac/orderinfo/registration.php

<?php \magento\framework\component\componentregistrar::register(\magento\framework\component\componentregistrar::module,"orderinfo", __dir__); 

app/code/ndac/orderinfo/observer/orderinfo.php

<?php namespace ndac\orderinfo\observer;  use magento\sales\model\order; use magento\framework\event\observer; use magento\framework\event\observerinterface;  class orderinfo implements observerinterface {     // tried constructor     public __construct() {         $file = fopen("/mnt/data/magento/test.txt", "w") or die ("die");         fwrite($file, "test");         fclose($file);     }      public function execute(observer $observer)     {         $file = fopen("/mnt/data/magento/test.txt", "w") or die ("die")         fwrite($file, "test");         fclose($file);     } } ?> 

i run following command: bin/magento setup:upgrade , module appears on dashboard, , enabled, test.txt remains empty, after place order.

there issue file naming.

app/code/ndac/orderinfo/etc/event.xml 

this has as:

app/code/ndac/orderinfo/etc/events.xml 

it has events.xml . , if event doesnt work, try checkout_onepage_controller_success_action event.

now run upgrade , clear cache.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -