0

I am using "controller_action_predispatch_sales_order_reorder" event to find out whether an order is reorder or not. Using this event I am able to get original orderId but along with that I want Order details as well which were ordered in the original order.

How can I get that from this event? I have already tried getOrder(), getProduct(), getQoute(), getAllItems() everything is coming up as null.

Here is my code

<?xml version="1.0"?>

<!--    Reorder from Admin side-->
<event name="sales_convert_order_to_quote">
    <observer name="admin_reorder" instance="VoltLighting\OrderInfo\Observer\AdminReorder"/>
</event>

<!--    Reorder from customer side-->
<event name="controller_action_predispatch_sales_order_reorder">
    <observer name="customer_reorder" instance="VoltLighting\OrderInfo\Observer\CustomerReorder"/>
</event>

<event name="checkout_onepage_controller_success_action">
    <observer name="customer_reorder_success" instance="VoltLighting\OrderInfo\Observer\CustomerReorderSuccess"/>
</event>

<event name="checkout_cart_product_add_after">
    <observer name="customer_predispatch_cart" instance="VoltLighting\OrderInfo\Observer\CustomerReorderCart"/>
</event>

Here is my Observer file

<?php

namespace VoltLighting\OrderInfo\Observer;

use Magento\Customer\Model\Session; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface;

class CustomerReorder implements ObserverInterface { protected $customerSession; public function __construct(Session $customerSession) { $this->customerSession = $customerSession; }

public function execute(Observer $observer)
{
    $order = $observer->getEvent();
    $entity_id = $order->getRequest()->getParam('order_id');
    $customer = $this->customerSession;
    $parentOrder = [$entity_id, []];
    $customer->setMyValue($parentOrder);
}

}

2
  • Hello @shivani, I guess the event "controller_action_predispatch_sales_order_reorder" does not exist in vendor/magento, is that a custom event? Jan 27 at 16:42
  • No, it's not. I am using it directly in my events without creating anything else. Jan 27 at 16:49
0

In order to get the order details, you need to load the order using the order id, as this event only contains the request which includes the order id, not the order data.

If you need any other clarification, let me know.

UPDATE

protected $orderRepository;

public function __construct(
\Magento\Sales\Api\OrderRepositoryInterface $orderRepository
){
$this->orderRepository = $orderRepository;
}

Then you can do following:

$order = $this->orderRepository->get($orderId);
5
  • thanks for the clarification this helped. Jan 27 at 18:08
  • hey can you tell me how to load order using order entity id. Jan 27 at 18:17
  • I have added the code to load order using order id (entity_id), hope it helps. Accept if it solves your problem Jan 27 at 18:22
  • It is entity id Jan 27 at 18:40
  • thanks it worked :) Jan 27 at 18:45

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.