2

I am working in simple event/observer module, but it does not work. I am trying to log the message in deubug.log when click place order button.

I have listed below what I have done

app/code/Gworks/Sms/etc/frontend/events.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="checkout_directpost_placeOrder">
    <observer name="get_place_order" instance="Gworks\Sms\Observer\LogAddMessage"/>
    </event>
</config>

app/code/Gworks/Sms/etc/module.xml

<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Gworks_Sms" setup_version="1.0.0"/>
</config>

app/code/Gworks/Sms/Observer/LogAddMessage.php

<?php
namespace Gworks\Sms\Observer;
use Magento\Framework\Event\ObserverInterface;
class LogAddMessage implements ObserverInterface
{
    protected $_logger;
    public function __construct(
    \Psr\Log\LoggerInterface $logger, //log injection
    array $data = []
    ) {
    $this->_logger = $logger;
    //parent::__construct($data);
    }
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
       $this->_logger->addDebug('getplace oreder event occured successfully!');
    }
}

app/code/Gworks/Sms/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Gworks_Sms',
    __DIR__
);

Thanks

7

Your event checkout_directpost_placeOrder is wrong.It is only fire whenever Payment method is Authorizenet Directpost

use sales_order_place_after event.

  • thank you it solved @Amit Bera please update how to find right events, its become more useful answer :-) – Bilal Usean Apr 26 '16 at 6:40
  • it totally depend on my concept .directpost word give me some signel :) – Amit Bera Apr 26 '16 at 9:52
  • in which file/line sales_order_place_after is dispatched? – LucScu Aug 31 '16 at 10:17
  • you can see a list of the events in this site cyrillschumacher.com/magento2-list-of-all-dispatched-events . Thanks Amit – Ervin Jan 12 '17 at 19:52
1

You can use one of the events for your case.All events are used for place order after logic.

sales_order_place_after

checkout_onepage_controller_success_action

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.