adding a tracking pixel in order confirmation page
-
13-12-2019 - |
Question
I have received a tracking pixel from one of our advertising company, and they asked me to place that code in my order confirmation page.
first of all can some one tell me where is the order confirmation file located in magento?
And 2nd if i need to get "order ID" value and "Amount" of the order then what to use in this pixel.
<img src="https://www.emjcd.com/u?AMOUNT=AMOUNT&CID=7777777&OID=OID&TYPE=5555555&CURRENCY=GBP&METHOD=IMG" height="1" width="20"/>
you can get more information here: http://www.pricerunner.co.uk/about/sales-tracking-instructions.html
Solution
You will need to copy your base template file from
app/design/frontend/base/default/template/checkout/success.phtml
To your ultimo theme path
app/design/frontend/ultimo/default/template/checkout
You can put below code in your success.phtml file
<?php
$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);
$grandTotal = $order->getGrandTotal();
$orderCurrency = $order->getOrderCurrencyCode();
?>
<img src="https://www.emjcd.com/u?AMOUNT=<?php echo $grandTotal; ?>&CID=7777777&OID='<?php echo $order_id;?>'&TYPE=5555555&CURRENCY=<?php echo $orderCurrency; ?>&METHOD=IMG" height="1" width="20"/>
OTHER TIPS
If you're using the rwd theme, it's in /app/design/frontend/rwd/default/template/checkout/success.phtml
The order object isn't present on the confirmation page - it's already unloaded by this stage. So you could write a module to hook into the order save function, but if you need a quick fix you could load the last order id using something like (in success.phtml):
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$_totalData =$order->getData();
$_sub = $_totalData['subtotal'];
Magento v2.1.x
Here's all what you need with some extra values as well
<?php
$merchantid = "<ID>";
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$orderId = $block->getOrderId();
$order = $objectManager
->create('Magento\Sales\Model\Order')
->loadByIncrementId($orderId);
$subtotal = $order->getSubtotal();
$discount = $order->getDiscountAmount();
$affiliateTotal = ($subtotal + $discount);
$ordered_items = $order->getAllVisibleItems();
$skulist = '';
$pricelist = '';
$quantitylist = '';
$last_index = array_search(end($ordered_items), $ordered_items, true);
foreach($ordered_items as $index => $item){
$delimiter = $index === $last_index ? '' : ',';
$skulist .= $item->getSku() . $delimiter;
$quantitylist .= ceil($item->getQtyOrdered()) . $delimiter;
$pricelist .= ($item->getProduct()->getFinalPrice() - ($item->getDiscountAmount() / $item->getQtyOrdered())) . $delimiter;
}
$couponcodes = $order->getCouponCode();
$currency = $order->getOrderCurrencyCode();
//render pixel below
?>
<img src="https://www.emjcd.com/u?tracking=<?php echo $orderId ?>&amount=<?php echo $affiliateTotal ?>&transtype=sale&merchantID=<?php echo $merchantid ?>&couponcode=<?php echo $couponcodes ?>&skulist=<?php echo $skulist ?>&quantitylist=<?php echo $quantitylist ?>&pricelist=<?php echo $pricelist ?>&currency=<?php echo $currency ?>&v=2.0" width="1" height="1">