I have installed Google Tag Manager and want to add an additional datalayer for ecommerce tracking on success page which contains the transition id, product specific data like sku, price, name, quantity and so on.
I want something like this for my success page after open body tag (pseudocode):
<body>
<script>
<?php
if ( $this->getOrderId() ) $transactionId = $this->getOrderId();
$currentOrder = Mage::getResourceModel( 'sales/order_collection' )->byId( $transactionId );
$transactionAffiliation = Mage::app()->getStore()->getFrontendName();
$transactionTotal = $currentOrder->getTotal();
$transactionTax = $currentOrder->getTax();
$transactionShipping = $currentOrder->getShipping();
$transactionProducts = $currentOrder->getProducts();
?>
dataLayer = [{
'transactionId': <?php echo "'".$transactionId."'" ?>,
'transactionAffiliation': <?php echo "'".$transactionAffiliation."'" ?>,
'transactionTotal': <?php echo $transactionTotal ?>,
'transactionTax': <?php echo $transactionTax ?>,
'transactionShipping': <?php echo $transactionShipping ?>,
'transactionProducts': [
<?php foreach( $transactionProducts as $product ): ?>
{
'sku': <?php echo "'".$product->getSku()."'" ?>,
'name': <?php echo "'".$product->getName()."'" ?>,
'category': <?php echo "'".$product->getCategory()."'" ?>,
'price': <?php echo $product->getPrice() ?>,
'quantity': <?php echo $product->getQuantity() ?>
},
<?php endforeach; ?>
]
}];
</script>
...
So I have to replace this pseudocode with "real" Magento code to get the order details on succes page. But which correct functions should I use to implement this?
Hope you can help me :)