问题描述:

I have a code that its executed only on the head tag of the success page. This code is to track if the buyer is coming from Comission Junction.

I need to set a variable to true if the original referrer comes from commission junction affiliate links which looks like this:

http://www.jdoqocy.com/click-1245-2342423?SID=TrackingTest

is there an easy way to do this?

I was thinking about referral url but I guess that variable changes each time you go from page to page: add to cart -> billing address -> shipping address -> payment -> overview -> success

My code is

 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(referral url come from CJ)

{

$udo['FIRECJ'] = "TRUE";

}

else {

$udo['FIRECJ'] = "FALSE";

}

$masterTmsUdo['CJ'] = $udo;

$json_masterTmsUdo = json_encode($masterTmsUdo);

return $json_masterTmsUdo;

}

Thanks

网友答案:

You can observe the event controller_action_predispatch.
it is dispatched for every page in magento.
Then you can check if the $_SERVER['HTTP_REFERER'] (or Mage::app()->getRequest()->getServer('HTTP_REFERER') if you want to be "politically correct") matches your needs.
If so, then set a value to the session.

Mage::getSingleton('core/session')->setComissionJunctionReferer(true);

Then, in your checkout page you can just check if the value is set.

if (Mage::getSingleton('core/session')->getComissionJunctionReferer()) {
    //your magic here
}
网友答案:

L.V try below

Mage::app()->getRequest()->getServer('HTTP_REFERER');
网友答案:

$_SERVER['HTTP_REFERER'] will give you the referrer page's URL if there exists any. try it

相关阅读:
Top