0

I have the following .phtml file, but I am having trouble making it work.

look at the rendered script block, there is nothing after the equals. http://screencast.com/t/zJ2DTnLF

and the code is this:

<?php
class ThePrinterDepo_Commissionjunction_Helper_Data extends Mage_Core_Helper_Abstract
{

    /**
     * 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;

    }

}

?>

<script>var MasterTmsUdo = <?php echo $this->getCommissionJunctionUdo($this->getOrderId()); ?></script>
<script>/*DO NOT ALTER *** The Printer Depo*/(function(e){var t="1340",n=document,r,i,s={http:"http://cdn.mplxtms.com/s/MasterTMS.min.js",https:"https://secure-cdn.mplxtms.com/s/MasterTMS.min.js"},o=s[/\w+/.exec(window.location.protocol)[0]];i=n.createElement("script"),i.type="text/javascript",i.async=!0,i.src=o+"#"+t,r=n.getElementsByTagName("script")[0],r.parentNode.insertBefore(i,r),i.readyState?i.onreadystatechange=function(){if(i.readyState==="loaded"||i.readyState==="complete")i.onreadystatechange=null}:i.onload=function(){try{e()}catch(t){}}})(function(){});</script>

1 Answer 1

1

You are referencing $this outside the object:

echo $this->getCommissionJunctionUdo(...);

You need to instantiate the object first and then call the method:

$myObject = new ThePrinterDepo_Commissionjunction_Helper_Data();
$myObject->getCommissionJunctionUdo(...);
Sign up to request clarification or add additional context in comments.

2 Comments

I am still getting this: screencast.com/t/8y67TYvIeqhP, please see my changed code here: screencast.com/t/BZlJGGtfI0As
seems like you forgot to echo before invoking the method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.