Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top