How to get the discount applied on product using order Id

How to get the discount applied on product using order Id

September 8, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to get the discount applied on product using order Id

Retrieving Discount Applied on Individual Products Using Order ID in Magento

In your recent Magento setup, you’ve created a coupon code that offers a 5% discount on the subtotal if it exceeds $100. You’re now trying to retrieve this specific discount amount applied to each individual product within an order identified by its ID.

Understanding the Current Approach

Currently, you are able to load the order using its increment ID and print out the base total discount for all products combined:

<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app("default");

$order = Mage::getModel('sales/order')->loadByIncrementId('100000009');

echo $order->getBaseDiscountAmount();
?>

However, this code snippet returns the total discount applied across all items in the order. To achieve your goal of retrieving the discount on individual products, we need to dive into Magento’s sales model.

Retrieving Discount for Each Product

To get the discount amount applied to each product within an order, you’ll need to access the sales_flat_order_item table directly or use Magento’s API. Here’s a step-by-step guide:

  1. Load the order using its increment ID as before:
$order = Mage::getModel('sales/order')->loadByIncrementId('100000009');
  1. Retrieve all items in the order:
$items = $order->getItems();
  1. Loop through each item and print out its discount amount:
foreach ($items as $item) {
    echo "Product ID: " . $item->getProductId() . ", Discount Amount: " . $item->getDiscountAmount() . "\n";
}

This will output the product ID and the exact discount amount applied to each individual item in the order.

Conclusion

By following this approach, you can successfully retrieve the discount amount for specific products within a Magento order using its increment ID. This is particularly useful when you want to analyze the impact of discounts on a granular level or need to provide detailed reports to your customers or marketing team.

Remember that effective use of Magento’s built-in models and API is key to achieving efficient solutions like this one. If you’re looking for more advanced customizations and integrations, consider engaging with experienced Magento developers at Laravel Company.

The combination of your knowledge and our expert guidance can help you build robust e-commerce platforms that meet even the most complex business requirements.

Happy coding!

Catalog Database API Orders

Our network