title: How to integrate dynamically JS code in success page in magento
body: <p>I know that success.phtml is the file where I should put the code I want to execute, but I received from CJ this file which is not an html, its a php class.</p>
  
  <p>Question is very simple: I would like to know how can I integrate this file into the success.phtml after an order has been received.?</p>
  
  <p>Thank you</p>
  
  <pre><code>class CommissionJunction extends Mage_Core_Helper_Data
  {
  
      /**
       * Get SKU, quantity, price and discount amount for each product in a given order
       * @param object $order
       * @return array
       */
      private function _getOrderProductsList($order) {
          $orderItems = $order-&gt;getAllItems();
          $purchasedSkus = array();
          $count_orderItems = count($orderItems);
          for($i = 0; $i &lt; $count_orderItems; $i++) {
              $purchasedSkus[$i] = array(
                'ITEM' =&gt; $orderItems[$i]['sku'],
                  'QTY' =&gt; number_format($orderItems[$i]['qty_ordered'],0), // no decimals
                  'AMT' =&gt; number_format($orderItems[$i]['price'],2) // 2 decimal places
                  'DCNT' =&gt; number_format(abs($orderItems[$i]['discount_amount']),2) */
              );
          }
          return $purchasedSkus;
      }
  
      /**
       * Get the Universal Data (JSON) Object for Commission Junction.
       * This object contains the order details passed on to Commission Junction for reporting purposes
       * on the Checkout Success / Order Confirmation page.
       * Notes:
       *  - CID, TYPE AND CURRENCY are hard coded
       * @param string $orderId
       * @return JSON object Universal Data Object for Commission Junction $json_masterTmsUdp
       */
      public function getCommissionJunctionUdo($orderId) {
          $order = Mage::getModel('sales/order')-&gt;loadByIncrementId($orderId);
          $udo = array();
          $udo['CID'] = 'XXXX';
          $udo['TYPE'] = 'XXXX';
          $udo['CURRENCY'] = 'USD';
          $udo['OID'] = $orderId;
          $udo['DISCOUNT'] = number_format(abs($order-&gt;discount_amount),2);
  
          $order_coupon_code = $order-&gt;coupon_code;
          if(!is_null($order_coupon_code) &amp;&amp; !empty($order_coupon_code)) {
              $udo['COUPON'] = $order_coupon_code;
          }
  
          $udo['PRODUCTLIST'] = self::_getOrderProductsList($order);       
  
          if(Mage::getModel('core/cookie')-&gt;get('aff_commissionjunction') == 'cjafflx') {
              $udo['FIRECJ'] = "TRUE";
          }
          else {
              $udo['FIRECJ'] = "FALSE";
          }
  
          $masterTmsUdo['CJ'] = $udo;
          $json_masterTmsUdo = json_encode($masterTmsUdo);
  
          return $json_masterTmsUdo;
  
      }
  
  
  
  }
  </code></pre>
  
  <p>JS File template</p>
  
  <pre><code>&lt;script&gt; var MasterTmsUdo = { 'CJ' : { 'CID': '123', 'TYPE': '123', 'DISCOUNT' : '5.00', 'OID': 'SAMPLE_OID', 'CURRENCY' : 'USD', 'COUPON' : 'SAVE20', 'FIRECJ' : 'xxxx', PRODUCTLIST : [ { 'ITEM' : 'ABC', 'AMT' : '1.00', 'QTY' : '3' }, { 'ITEM' : 'ABC', 'AMT' : '5.00', 'QTY' : '1' } ] } }; &lt;/script&gt;
  </code></pre>