我正在尝试在magento 2中收听此事件sales_order_place_after,但在下订单后点击nothings发生,(同一观察者在列入其他事件如登录时工作)。 对于发生了什么有什么想法? Thanxs。
答案 0 :(得分:1)
您可以使用模块app \ code \ Vendorname \ modulename \ etc \ frontend \ events.xml中的Observer执行此操作 -
<event name="checkout_onepage_controller_success_action">
<observer name="mymodule_controller_success_action" instance="Vendorname\modulename\Observer\MyObserver" />
</event>
并在app \ code \ Vendorname \ modulename \ MyObserver.php文件中添加代码 -
<?php
namespace Vendorname\mudulename\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\App\Request\DataPersistorInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Captcha\Observer\CaptchaStringResolver;
class MyObserver implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$order = $observer->getEvent()->getOrder();
echo $orderId = $order->getId();
$comment = $this->getRequest()->getParam('comment');
print_r("Catched event succssfully !"); exit;
echo "Do your Work Here";
}
}