0

I want to override an event checkout_type_onepage_save_order_after. For this I already tried below code :

etc/frontend/events.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
     <event name="checkout_type_onepage_save_order_after">
        <observer name="mycustomobserver" instance="Namespace\Module\Observer\CreateTestFormObserver"/>
     </event>
</config>

Namespace\Module\Observer\CreateTestFormObserver.php

<?php
namespace Namespace\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer as EventObserver;

class CreateTestFormObserver implements ObserverInterface
{
  private $logger;
  protected $messageManager;

   public function __construct(
     \Psr\Log\LoggerInterface $logger) {
        $this->logger = $logger;
   }
   public function execute(EventObserver $observer)
   {
       $this->logger->addDebug('CreateTestFormObserver');
   }
}

But my file is not called after placing an order. I identify this by my log, which is not generated on or after placing an order.

0

3 Answers 3

1

I found solution which is as below :

Change event.xml file position to etc/events.xml and code is :

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_type_onepage_save_order_after">
       <observer name="mycustomobserver" instance="Namespace\Module\Observer\Frontend\CreateTestForm"/>
   </event>
</config>

And put folder of event at Namespace\Module\Observer\Frontend\CreateTestForm.php and now code is :

<?php
namespace Namespace\Module\Observer\Frontend;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer as EventObserver;

class CreateTestForm implements ObserverInterface
{
    private $logger;
    protected $messageManager;

    public function __construct(
     \Psr\Log\LoggerInterface $logger) {
    $this->logger = $logger;
  }
  public function execute(EventObserver $observer)
  {
    $this->logger->addDebug('CreateTestFormObserver');
  }
}
1
  • I think also you have to change 'checkout_type_onepage_save_order_after' event because of it is not working on place order. please check it after cler cache if working then inform to me. i have already try but not sucess with this event. Commented Apr 20, 2016 at 13:36
0

You can do it using event checkout_onepage_controller_success_action,

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
     <event name="checkout_onepage_controller_success_action">
        <observer name="mycustomobserver" instance="Namespace\Module\Observer\CreateTestFormObserver"/>
     </event>
</config>

For using above event, you can debug your code and its same as your event.

Basically checkout event flow for place order is display below,

checkout_controller_onepage_save_shipping_method

sales_order_place_after

checkout_type_onepage_save_order_after

checkout_onepage_controller_success_action

So change event and try again using remove var folder.

Thanks.

0

create events.xml in etc/ insted of etc/frontend/events.xml

and add below code to event.xml

<event name="sales_order_save_commit_after">
     <observer name="my_test_observer" instance="Namespace\Module\Observer\CreateTestFormObserver" />
</event>

let me know if you have any issue.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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