0

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.

I would like to know how can I integrate this file into the success.phtml ?

Thank you

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->getAllItems();
        $purchasedSkus = array();
        $count_orderItems = count($orderItems);
        for($i = 0; $i < $count_orderItems; $i++) {
            $purchasedSkus[$i] = array(
              'ITEM' => $orderItems[$i]['sku'],
                'QTY' => number_format($orderItems[$i]['qty_ordered'],0), // no decimals
                'AMT' => number_format($orderItems[$i]['price'],2) // 2 decimal places
                'DCNT' => 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')->loadByIncrementId($orderId);
        $udo = array();
        $udo['CID'] = 'XXXX';
        $udo['TYPE'] = 'XXXX';
        $udo['CURRENCY'] = 'USD';
        $udo['OID'] = $orderId;
        $udo['DISCOUNT'] = number_format(abs($order->discount_amount),2);

        $order_coupon_code = $order->coupon_code;
        if(!is_null($order_coupon_code) && !empty($order_coupon_code)) {
            $udo['COUPON'] = $order_coupon_code;
        }

        $udo['PRODUCTLIST'] = self::_getOrderProductsList($order);       

        if(Mage::getModel('core/cookie')->get('aff_commissionjunction') == 'cjafflx') {
            $udo['FIRECJ'] = "TRUE";
        }
        else {
            $udo['FIRECJ'] = "FALSE";
        }

        $masterTmsUdo['CJ'] = $udo;
        $json_masterTmsUdo = json_encode($masterTmsUdo);

        return $json_masterTmsUdo;

    }



}
1

Call the function getCommissionJunctionUdo() inside the success.phtml page using the orderId as a parameter.

I assume this file is a part of the cj extension you have installed.

  • we dont have any cj extension! – Luis Valencia Aug 9 '14 at 16:36
  • 1
    Then you can 1) either create one, actually you need just the helper class or 2) you can put entire code in the template (not recommended) and then call the function 3) or put the file in the /lib/ folder so the autoloader can find it. – Amasty Aug 9 '14 at 16:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.