0

when i echo

"Mage::app()->getFrontController()->getRequest()->getActionName();" 

on

"checkout/onepage/success" 

page it gives me values as "index". As per url i suppose output should be "success".

I want to identify if current page is checkout success page, so i tried to use the above code, but it gives undesired output.

3
  • In my experience if you're having to test the name of a controller you're probably not approaching an issue correctly. What exactly are you trying to accomplish once you know it's the success page?
    – philwinkle
    Commented Jul 28, 2014 at 16:35
  • I wanted to implement Google trusted Store Code, and for that their is 2 script code available. One code that is needed through out website, i have placed it on footer while other needs to be places on checkout success page. On testing i got error that more than once code was available. Thats why i need to identify checkout success page so that i can avoid loading the first code placed on footer section. Commented Jul 29, 2014 at 7:35
  • I figured as much. I will add an answer that includes adding a script block to the checkout success route only. This way no sniffing of controller actions required.
    – philwinkle
    Commented Jul 29, 2014 at 9:00

3 Answers 3

6

Magento page layout is matching with FullActionName().

Mage::app()->getFrontController()->getAction()->getFullActionName();

If this code returns true

Mage::app()->getFrontController()->getAction()->getFullActionName() === 'checkout_onepage_success'

it means that this page is the checkout success page

3

The answer from @mbalparda indeed answers your original question. However, based on the comments, it sounds like what you really need is a layout.

If you placed the code in the footer.phtml template file you'll have a hard time removing it on the success page. In that case we'll create a layout instruction so that we can remove it once we're on the success page.

1. Create two static blocks

Name them google-trusted-general and google-trusted-success. Place your scripts (script tag and all) into each.

2. Update (or create) your local.xml theme layout

In your theme's layout folder add this to your local.xml file (if it doesn't exist, create it):

<?xml version="1.0"?>
<layout>
    <default>
        <reference name="before_body_end">
            <block type="cms/block" name="trusted">
                <action method="setBlockId"><block_id>google-trusted-general</block_id></action>
            </block> 
        </reference>
    </default>
    <checkout_onepage_success>
        <reference name="before_body_end">
            <remove name="trusted"/>
        </reference>
        <reference name="checkout.success">
            <block type="core/text" as="trusted" name="trusted">
                <block type="cms/block" name="trusted">
                    <action method="setBlockId"><block_id>google-trusted-success</block_id></action>
                </block> 
            </block>
        </reference>
    </checkout_onepage_success>
</layout>

This will add the script to the entire site and remove on the success page, displaying a new block.

4
  • 2
    This should be the way to go, but when the cache is onm the footer is cached and calling a remove statement may be useless. Or am I wrong?
    – Marius
    Commented Jul 29, 2014 at 14:38
  • That's a fantastic point
    – philwinkle
    Commented Jul 29, 2014 at 14:45
  • @marius moving it out of the footer would be harmless - I think i'll just do it that way!
    – philwinkle
    Commented Jul 29, 2014 at 16:30
  • 1
    Yep. Since is javascript....
    – Marius
    Commented Jul 29, 2014 at 17:12
0

Use

Mage::app()->getFrontController()->getRequest()

and there you will see the entire request and not only the action name. Dont echo it but var_dump() it since its an array.

This can be useful too:

**
 * get Controller name
 */
$this->getRequest()->getControllerName();

/**
 * get Action name, i.e. the function inside the controller
 */
$this->getRequest()->getActionName();

/**
 * get Router name
 */
$this->getRequest()->getRouteName();

/**
 * get module name
 */
$this->getRequest()->getModuleName();

from here.

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.