How to get downloadable product links after successfull order

How to get downloadable product links after successfull order

August 1, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get downloadable product links after successfull order

As an e-commerce developer, you often find yourself needing to provide download links for purchased products directly after a successful order. This is especially common in digital goods stores or subscription-based platforms. In this guide, we’ll explore how to achieve this using Magento’s built-in functionality and some custom code.

Understanding the Downloadable Product Type

Magento provides a native downloadable product type that allows you to attach downloadable files to products. When you set up a download link for a product, it associates the download with that specific item in an order. This is crucial because it ties the download access directly to the purchased item.

Retrieving the Latest Order and Its Products

In your provided code snippet, you’re on the right track by retrieving the latest order ID from the session and then loading all items associated with that order:

$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$items = $order->getAllItems();

This allows you to iterate through each item in the cart:

foreach ($items as $item) {
    // Your code here...
}

Retrieving the Downloadable URL

To get the downloadable URL for a product, you need to access the links attribute of the loaded product model. This attribute contains an array of downloadable links associated with that product.

Here’s how you can modify your existing code to retrieve the download link:

foreach ($items as $item) {
    $product = Mage::getModel('catalog/product')->setStoreId($order->getStoreId())->load($item->getProductId());

    // Check if the product is of 'downloadable' type
    if ($product->getTypeId() == 'downloadable') {
        $links = $product->getDownloadableLinks();
        foreach ($links as $link) {
            echo '<a href="' . Mage::helper('core/url')->getUrl($link['file']) . '">Download: ' . $link['title'] . '</a><br />';
        }
    }
}

In the above code, we first check if the product type is downloadable. If it is, we retrieve all download links associated with that product using $product->getDownloadableLinks(). We then loop through each link and output a clickable URL.

Conclusion

Retrieving downloadable URLs for products in Magento after a successful order involves loading the latest order’s items and checking if each product has the downloadable type. By using the native getDownloadableLinks() method, you can easily access the URLs of all associated files.

Remember to test your implementation thoroughly, especially when dealing with sensitive data like download links. Always ensure that the user is authenticated and authorized before providing these links in a production environment.

If you’re looking for more advanced e-commerce solutions or need expert consultation on Magento development, feel free to reach out to our team at Laravel Company. We specialize in delivering high-quality, performance-optimized e-commerce platforms that drive business growth.

Checkout Catalog Orders

Our network