Skip to content

Cannot redirect url in the post dispatch event #1624

@lucbaojang

Description

@lucbaojang

I want to redirect to my page after I saved a product in the back-end. So, I used the "controller_action_postdispatch_catalog_product_save" event but it didn't work for me.

Could you please let me know what was wrong with this code?

public function adminhtmlCatalogProductSaveAfter(EventObserver $observer) {
$action = $observer->getEvent()->getControllerAction();

    $action->getActionFlag()->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
    $this->messageManager->addSuccess(__('You saved the product.'));
    $action->getResponse()->setRedirect(
        $action->getUrl('myrouter/index/index')
    );   

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions