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(); ?>
<?php endforeach(); ?>
    <div class="mc_ordervalue"><?php echo $_order->getGrandTotal(); ?></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...

foreach ($config['productInfos'] as $product): ?>
<div class="mc_sku">
   <?php echo $product['sku']; ?>
  • @user1704524 Are you using configurable products? – mpaepper Jun 3 '14 at 10:07
  • 2
    @user1704524 If so, then use $_order->getAllVisibleItems() instead of $_order->getAllItems(). – mpaepper Jun 3 '14 at 10:07
  • Yes I am using mainly configurable and some simple too... – user1704524 Jun 3 '14 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.