0

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.

1
  • 1
    when it goes in the dashboard whilst your redirect does not do this, it is often because there is an error $resultRedirect->setPath($this->getComponentRefererUrl()); should work. Best to look at the browser console with the option set "Preserve logs to verify no javascript issue is there .." Jan 3, 2019 at 7:31

1 Answer 1

1

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

0

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.