HummingbirdUK main logo

Coding solutions to business problems

About us

We use code to create solutions to business challenges, bottle-necks and headaches.

If you think your business has a problem that can be solved through code, we are happy to chat things through without any obligation.

Get in touch

Rakuten LinkShare order tracking for Magento

Home / Blog / Rakuten LinkShare order tracking for Magento

Written by Giles Bennett

A recent job involved creating the relevant code to add a tracking image for a client to the order confirmation page in Magento for Rakuten LinkShare.

Rakuten Linkshare provide a very detailed specification PDF document, which runs to five or so pages - what it boils down to is that the success page has to output an image link, and the source address of that image link contains various bits of information relating to the order that has just been completed.

The end tracking code will need to follow this format :

<img src="">

Where the values are as follows :

'mid' = Merchant ID number (this comes from Rakuten).

'ord' = Order number (the Order Increment ID, in Magento terms)

'skulist' = a list of the SKUs in the order, pipe (|) delimited

'qlist' = a list of the quantities of each SKU in the skulist, also pipe delimited

'amtlist' = the sale price, excluding tax and shipping, of each item in the skulist, also pipe delimited

'cur' = the base currency of the store in ISO three letter country code format

'namelist' = the list of item names for each item in the skulist

Note that the 'namelist' entry is optional, but for sake of completeness I've included it here.

Since this code snipped is being placed on the template / checkout / success.phtml file (it doesn't matter where, as the image is invisible) then the OrderID of the relevant order is already available to us.

To get started, therefore, our code needs to take that OrderID and load the full order details from it into $order, then load all the visible items (ie. exclude configurable products, just include the underlying simple products) into it :

$lastOrder = $this->getOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($lastOrder);
$items = $order->getAllVisibleItems();

We're going to hold the relevant information in four arrays, so let's instantiate them :


Then we need to loop through each item in the array of purchased items and for each one get its SKU, the quantity ordered, the amount paid for each item, and the item name.

foreach($items as $item) {

Then add that information to each of the four arrays. Note that the specification requires the amount to be (a) in pence, and (b) the line total, so we're multiplying it by 100 first, then by the corresponding quantity of items for that line :


And finally close off the loop :


If a discount code has been used, we should pass that information too - Rakuten allows two methods of doing it, but the easiest from Magento's point of view is adding the discount to the list of products as its own product, like so :

$discountUsed = $order->getCouponCode();
if ($discountUsed != "") {
	$amounts[]=($order->getDiscountAmount()) * 100;

Our four arrays are now bursting at the seams with the relevant information, so it's time to start building the final output. The Merchant ID will be static, so insert it here, and the Order ID we can get as we did earlier :

$final="<img src=\"".$this->getOrderId();

Then it's a case of running through each of the four arrays and outputting each item, separated by a pipe. We're also outputting the currency (hardcoded in this instance, but it wouldn't be too tricky to make it dependant upon the store settings) :

$final.=implode("|", $skus);
$final.=implode("|", $quantities);
$final.=implode("|", $amounts);
$final.=implode("|", $names);

So then let's output the final code :

echo $final;
Author : Giles Bennett

About the author

Giles Bennett built his first website in 1996, and is old enough to miss Netscape Navigator. Initially a lawyer, he jumped ship to IT in 2008, and after 5 years as a freelancer, he founded HummingbirdUK in 2013. He can be reached by email at