1

Is there a way to check if am I on Success page on Magento 2?

I know in Magento 1 we can check and compare the action name, for example. But in Magento 2, there is something similar?

3 Answers 3

2

It depends where in the flow you need to detect it, for styling purposes, you can see in the body tag of the success page this css class: checkout-onepage-success

If you need to interact with data in the page you could hook to this event: checkout_onepage_controller_success_action

And in Magento2 you also have action/module names and handles that you could use in your php/phtml code:

Magento 2: How to get controller, module, action and router name?

Current page layout handle Magento2

0

Yes, you can do the same at Magento 2. Get Full action can at your class or file .

Magento 2: getting Full Action name inside custom Model class?

if( $this->request->getFullActionName() === 'checkout_onepage_success){
// then checkout page
}
 
3
  • Thanx, but I will run my code inside the head tag, so it's not possible go with "$this". There is an alternative, like in Magento 1 we had "Mage::app()"?
    – Ralf O
    Commented Nov 18, 2020 at 18:39
  • what you want to under head tag , if you will inject \Magento\Framework\App\Request\Http respective code then you can get full action
    – Amit Bera
    Commented Nov 19, 2020 at 2:49
  • Thank you, Amit :)
    – Ralf O
    Commented Nov 19, 2020 at 12:29
0

I found the code below here

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$request = $objectManager->get('Magento\Framework\App\Action\Context')->getRequest();


if ($request->getFullActionName() == 'checkout_onepage_success') {
//you are on the success page
}

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.