1
Magento 2ページのシンプルなイベントオブザーバを作成しようとしています。Magento 2イベントオブザーバが動作しない
アプリケーション/コード/ 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>
アプリケーション/コード/ 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>
アプリケーション/コード/ NDAC/ORDERINFO/registration.php
アプリケーション/コード/ NDAC/ORDERINFO /オブザーバー/ 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 it with 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);
}
}
?>
私は次のコマンドを実行します:bin/magento setup:upgrade
モジュールはダッシュボードに表示され、有効になっていますが、注文後にtest.txtは空のままです。