0

I have activated reorder on my magento 2 site. Now I want a event which can catch reorder both in frontend and backend (admin). I am using "controller_action_predispatch_sales_order_reorder" for my front end which is working perfectly fine but I want to catch reorder on the backend as well. Can anyone tell me which event to use for backend as "controller_action_predispatch_adminhtml_sales_order_create_reorder" is not working for backend?

Here is my code:

Event file app/code/VoltLighting/OrderInfo/etc/adminhtml/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="controller_action_predispatch_adminhtml_sales_order_create_reorder">
    <observer name="admin_reorder_observer" instance="VoltLighting\OrderInfo\Observer\AdminReorder" />
</event>

<event name="checkout_submit_all_after">
    <observer name="admin_order_observer" instance="VoltLighting\OrderInfo\Observer\AdminOrder" />
</event>

Observer file app/code/VoltLighting/OrderInfo/Observer/AdminReorder.php

<?php
namespace VoltLighting\OrderInfo\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class AdminReorder implements ObserverInterface
{

    public function execute(Observer $observer)
    {
        $order= $observer->getEvent();

        echo "hello world";
        exit;
      
    }
}

enter image description here

11
  • what exactly you would want to achieve with the event.? as such there might be other events that may fulfill your requirement by placing the event in the global events.xml file for the module i.e vendor/module/etc/events.xml which will work for both front and backend.
    – mp196
    Jan 21 at 18:58
  • I want to find out whether my order is reorder or not and get the original order ID along with the products associated with my original order and store it in a custom table. Jan 21 at 19:09
  • sales_order_create_reorder should really cover both frontend and backend reordering as they use the same models for both frontend and backend Jan 21 at 19:48
  • I tried sales_order_create_reorder and refereshed my cache. It didn't work :( Jan 21 at 20:32
  • 1
    @ShawnAbramson sure you can present it. Jan 22 at 21:58
0

Observer the sales_convert_order_to_quote event. This fires when converting a previous order into a new quote ... aka preparing to reorder.

You will probably need to set some sort of flag on the quote and then at the time the quote converts to an order, pass the flag. Something like $quote->setData('is_reorder', true). The admin panel ordering process is a bit different than the frontend.

If you look at the admin reorder controller, you will see $this->_getOrderCreateModel()->initFromOrder($order);. The observer event mentioned above is dispatched inside of the initFromOrder function.

0

I think the sales_order_place_after event will be the one you want to hook into.

0

I think adminhtml_customer_orders_add_action_renderer event will be use. path is herevendor/magento/module-sales/Block/Adminhtml/Reorder/Renderer/Action.php

1
  • I already tried "adminhtml_customer_orders_add_action_renderer" event, this one is not working. Jan 22 at 16:16

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.