skip to Main Content

I’m working with Magento 1.9 and have a PHP include file that I’m using to display facebook pixel code based on the page type. IE: cart, checkout, product details, catalog, cms…

I’m looking at the page request module, controller, action, etc. However, I can’t seem to find a way to determine if they’re at /checkout/success/ or not. If I try to look at the request URI it returns /checkout/cart/

Is there a class property or method that I can use to determine that the user is in fact on the order success page?

3

Answers


  1. Chosen as BEST ANSWER

    I ended up working through it by looking at the current quote ID (which should be null), the current controller, and the last order ID.

    function getPageType($page)
    {
        $request    = $page->getRequest();
        $controller = $request->getControllerName();
        $session = Mage::getSingleton('checkout/session');
    
        if($session->getLastOrderId() && !$session->getQuoteId() && $controller == 'cart')
        {
            return 'success';
        }
    }
    

    After a purchase has been completed, the current quote is cleared. However, since we're still in the cart, then that means the purchase has been completed. I check the last order id just to be sure there was a purchase.


  2. You can use:

    if(Mage::app()->getRequest()->getActionName() == 'success'){
    // code
    }
    
    Login or Signup to reply.
  3. You may also make use of the layout handle checkout_onepage_success.

    Reference this in a layout of your custom module and in the referenced template file include the facebook pixel code.

    <checkout_onepage_success translate="label">
            <reference name="after_body_start">
                <block type="core/template" template="example/fb/conversion.phtml" />
            </reference>
    </checkout_onepage_success>
    

    And, in example/fb/conversion.phtml, do the needful processing and include the facebook pixel code.

    <script>
        fbq('track','Purchase', {
            value: <?php echo xxx ?>,
            currency: '<?php echo xxx ?>',
            content_ids: <?php echo xxx ?>,
            content_type: 'product',
            num_items: <?php echo xxx; ?>
        });
    </script>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search