Skip to content

Showing multiple discounts and amount from sales_order_item in external script

I’m trying to show multiple discounts in a public php script that sends orders to our ERP system. The problem im having is when an order has more than one discount, it is only pulling one discount with a total discount amount for both. I need it instead to show 2 xml nodes with the correct discount amounts. Is there a way to do this with a direct query? This is what im doing so far:

foreach ($dissur as $dissur_tax_code => $dissur_amount) {
        if ($dissur_amount != 0) {
            $dissur_desc = $order->discount_description;
            $dissur_desc = trim($dissur_desc);

        //if coupon description over 80 characters grab it directly from the
        //database sales_order table

        $dissur_desc = ($ecom->validateDiscountDesription($dissur_desc,$orderID));

        if (empty($dissur_desc) || $magento->use_generic_dissur_description) {
            $dissur_desc = ($dissur_amount > 0) ? 'WebDiscount' : 'WebSurcharge';
        }

        if ($magento->append_tax_code_to_order_discount_description) {
            $dissur_desc .= " - " . $dissur_tax_code;
        }

        $order_details->discounts[] = array(
            'description' => "Website-" . $dissur_desc,
            'tax_code' => $dissur_tax_code,
            'price' => round(abs($dissur_amount),2),
        );
    }
}