I am trying to add some tracking and conversion codes which require all skus from an order to be listed in the HTML tag on the checkout success page.
So far I have been able to get the QTY, Order Amount and SKU but I need to show ALL SKUs from the order not just one so need to loop but I'm doing it wrong.
Here is what I have:
<?php // Get Order info
$products = array();
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$_order = Mage::getSingleton('sales/order')->load($lastOrderId);
/* @var $item Mage_Sales_Model_Order */
foreach ($_order->getAllItems() as $item) {
$info['sku'] = trim($item->getSku());
$info['qty'] = $item->getQtyOrdered();
$info['price'] = $item->getPrice();
$products[] = $info;
}
$config['productInfos'] = $products;
$config['cartTotal'] = $_order->getGrandTotal();
$config['currency'] = Mage::app()->getBaseCurrencyCode();
?>
One I have the order info I need to populate the following HTML TAGS
<div id="mc_data" style="display:none;">
<div class="mc_event">PURCHASE</div>
<div class="mc_order_ref"><?php echo $this->getOrderId(); ?></div>
<div class="mc_retailer">Custom</div>
//Here is where I need to loop to get all the SKUS
<?php foreach(); ?>
<div class="mc_sku">
<?php echo $this->getSku(); ?>
</div>
<?php endforeach(); ?>
<div class="mc_ordervalue"><?php echo $_order->getGrandTotal(); ?></div>
</div>
I've been searching for a few hours but haven't found a good tutorial on how to get the SKUs in a foreach so could do with some assistance if possible please…
Best Answer