onepage checkout – Inject third party javascript on a onecheckout page in Magento 1

First, let me say that I don't know Magento 1 at all. This is a job I do for someone, so you have to endure me and apologize for the apparent lack of knowledge.

I am creating a custom checkout built into a third party that is PCI / DSS compliant. The reason for this is that the current merchant is not PCI / DSS compatible and therefore cannot handle credit card data properly.

I use the standard purchase process from Magento 1. I understand that it is referred to as a one-page checkout. I want to inject some javascript after the order is placed. The Javascript is custom and comes from a URL on a third-party server.

My goal is this:

  • User comes to checkout and to Clicking the "Send order" button will insert Javascript into the page

  • The Javascript shows the cash register of a third party

  • After the user has paid, they will be redirected to the "Thanks" page in Magento

Sounds simple enough.

So far I've added an observer controller_action_postdispatch_checkout_onepage_saveOrder. My understanding of this observer is that it is called after the order has been saved in Mangeto.

Note: this is not all of the code. However, the observer works perfectly.


    
        
            singleton
            XXXXX_Model_Observer
            output_tco_redirect
        
    

Within this function I have the following code:

public function output_tco_redirect (Varien_Object $ Observer)
{
$ js = & # 39;

& # 39 ;;
/ ** @var Mage_Core_Model_Layout $ layout * /
$ layout = Mage :: getSingleton (& # 39; core / layout & # 39;);
/ ** @var Mage_Core_Block_Text $ block * /
$ block = $ layout-> createBlock (& ​​# 39; Mage_Core_Block_Text & # 39 ;, & # 39; tco_js & # 39;);
$ block-> setText ($ js);
/ ** @var Mage_Page_Block_Html_Head $ head * /
$ head = $ layout-> getBlock (& ​​# 39; head & # 39;);
// block header is wrong here
$ head-> append ($ block);

return $ this;
}}

I admit I have no idea if this is the right way to go or if it works at all to be with him.

Currently the problem is that the $head Block is always wrong. I assumed that a head Block will always exist, regardless of the page. I was obviously wrong.

I'm not against using another method to achieve what I'm trying to do. Unfortunately I don't know any other at the moment.