in Programming, Web Development

Add affiliate window to Magento

It’s straight forward to add affiliate window into Magento, there are a few extensions but you don’t need them.

Edit your checkout success page which would usually be in app/design/frontend/yourpackage/yourtheme/checkout/success.phtml

Add near the top inside the php tags

// get the order
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
// get the total
$total = $order->getGrandTotal();
// get order data
$_totalData = $order->getData();
// helper for the price formatting
$helper = Mage::helper('core');

Then add anywhere in html part of the page (replace MERCHANT_ID with your merchant ID). I’ve omitted the Category here as it’s optional

<!-- Image Pixel Tracking - Mandatory -->
    <img src="https://www.awin1.com/sread.img?tt=ns&tv=2&merchant=MERCHANT_ID&amount=<?php echo $helper->currency($order->getGrandTotal(),false,false); ?>&cr=<?php echo $_totalData['order_currency_code']; ?>&ref=<?php echo $this->getOrderId() ?>&parts=default:<?php echo $helper->currency($order->getGrandTotal(),false,false); ?>&vc=<?php echo $_totalData['coupon_code']; ?>&ch=aw&testmode=0&cr=<?php echo $_totalData['order_currency_code']; ?>" />

    <form style="display:none;" name="aw_basket_form">
        <textarea wrap="physical" id="aw_basket">
            <?php

            $items = $order->getAllItems();

            foreach ($items as $item) {

                echo "AW:P|MERCHANT_ID|".$this->getOrderId()."|".$item->getProductId()."|".$item->getName()."|".$helper->currency($item->getPrice(),false,false)."|".$item->getQtyToInvoice()."|".$item->getSku()."|default|";

            }

            ?>
        </textarea>
    </form>
    <!-- Javascript Tracking - Mandatory -->
    <script type="text/javascript">
        //<![CDATA[
        /*** Do not change ***/
        var AWIN = {};
        AWIN.Tracking = {};
        AWIN.Tracking.Sale = {};

        /*** Set your transaction parameters ***/
        AWIN.Tracking.Sale.amount = '<?php echo $helper->currency($order->getGrandTotal(),false,false); ?>';
        AWIN.Tracking.Sale.currency = '<?php echo $_totalData['order_currency_code']; ?>';
        AWIN.Tracking.Sale.orderRef = '<?php echo $this->getOrderId() ?>';
        AWIN.Tracking.Sale.parts = 'default:<?php echo $helper->currency($order->getGrandTotal(),false,false); ?>';
        AWIN.Tracking.Sale.voucher = '<?php echo $_totalData['coupon_code']; ?>';
        AWIN.Tracking.Sale.test = '0';
        AWIN.Tracking.Sale.channel = 'aw';
        //]]>
    </script>

Finally in your footer app/design/frontend/yourpackage/yourtheme/page/html/footer.phtml

<script src="https://www.dwin1.com/5715.js" type="text/javascript" defer="defer"></script>

Write a Comment

Comment