Magento checkout success page: get some order information

Magento checkout success page: get some order information

July 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento checkout success page: get some order information

Accessing Magento Order Information on the Checkout Success Page

As a new Magento developer, navigating the checkout process and accessing order information can indeed be confusing. In this post, I’ll guide you through retrieving key data points - the total price of an order and all associated article IDs - from your checkout success page.

Understanding the Current Approach

Let’s first break down the code snippet provided:

<?php
    $_customerId = Mage::getSingleton('customer/session')->getCustomerId();
    $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
    $order = Mage::getSingleton('sales/order');
    $order->load($lastOrderId);
?>

This script achieves the following:

  • It retrieves the customer ID currently logged in.
  • It fetches the ID of the last placed order using Magento’s session management.
  • It creates a sales order object and loads it with the retrieved order ID.

While this is a step forward, to extract meaningful data like total price and article IDs, you need to delve deeper into the loaded order object.

Retrieving Total Order Price

To get the total price of an order, you can use the getGrandTotal method provided by Magento:

$totalPrice = $order->getGrandTotal();

This will return the grand total amount for the order after all discounts and taxes have been applied. You can use this variable to display or log the total order price on your checkout success page.

Extracting Article IDs

To retrieve a list of article IDs (also known as product IDs) associated with an order, you need to access the order’s items:

$itemCollection = $order->getItemsCollection();

This retrieves all items in the current order. To extract just the product IDs, separated by a comma :

$productIds = implode(',', array_column($itemCollection->getData(), 'product_id'));

Here’s what happening:

  • array_column is used to get an array of all “product_id” values from the item collection.
  • The implode function then combines these IDs into a single string, separated by commas.

Putting It All Together

Combining the above code snippets gives us:

<?php
    $_customerId = Mage::getSingleton('customer/session')->getCustomerId();
    $lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
    $order = Mage::getSingleton('sales/order');
    $order->load($lastOrderId);

    // Retrieve total order price
    $totalPrice = $order->getGrandTotal();

    // Retrieve product IDs and combine into a string
    $itemCollection = $order->getItemsCollection();
    $productIds = implode(',', array_column($itemCollection->getData(), 'product_id'));
?>

This script will now give you both the total order price ($totalPrice) and all associated article IDs as a comma-separated string ($productIds).

Conclusion

Accessing order data in Magento requires understanding its object-oriented architecture. By leveraging Magento’s built-in methods, you can efficiently retrieve key information like total order price and product IDs from any point in the checkout process.

Remember that working with live customer data is sensitive, so always ensure you follow best security practices when handling and displaying this information on your website.

For more advanced techniques in Magento, I recommend exploring Laravel Company’s Magento tutorials. They provide comprehensive guides for both beginners and experienced developers looking to master Magento development.

Checkout Orders Customers Pricing

Our network