Question

I added the custom massAction to Orders List and it's executing my massAction method but it's redirecting to dashboard. for these I have written below code.

 protected function massAction(AbstractCollection $collection)
    {
        $count = 0;
        $model = $this->_objectManager->create('Magento\Sales\Model\Order');
        /** @var \Magento\Sales\Model\Order $order */
        foreach ($collection->getItems() as $order) {
            if (!$order->getEntityId()) {
                continue;
            }
            $loadedOrder = $model->load($order->getEntityId());
            $count ++;
        }

        if ($count ) {
            $this->messageManager->addSuccess(__('A total of %1 record(s) were sent to Nav.', $count ));
        }

        $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
        //$resultRedirect->setPath($this->getComponentRefererUrl());
        $resultRedirect->setPath('sales/orders/index/');
        return $resultRedirect;

    }

I have given to stay same page URL $resultRedirect->setPath($this->getComponentRefererUrl()); and $resultRedirect->setPath('sales/index/orders') but it's redirecting to dashboard.

Anything I missed? please suggest. I need to stay on the same page after executing my function.

Was it helpful?

Solution

Try $resultRedirect->setUrl($this->_redirect->getRefererUrl());

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