2

This question already has an answer here:

We are seeing a problem where a user has placed an order that totals correctly, but when a discount is applied using a rule that can have a discount more than the total, the grand total goes to (-$0.01)

This order does have tax applied to it and flat rate shipping. Here are the order details: item 1: qty 4, price 12.87 item 2: qty 1, price 6.92 item 3: qty 1, price 7.51

Tax is 5.5% and shipping is flat 7.00

When the order is totaled and we view the cart, the numbers are correct, tax and all the grand total is 76.92.

When we apply a discount of 76.92 or less the total is correct based off of what we apply. We are using a discount that corresponds to the user's giftcard balance, so the discount can be more than the total, and in this case it is. Any discount OVER 76.92 causes the discount amount to be 76.93 and after the discount the grand total becomes (-$0.01) and Magento asks for a payment type.

We've tried this scenario on a clean 1.6.2.0 install and a 1.8.0.0 install and it appears in all environments. We've tried changing the rounding action in code/core/Mage/Sales/Model/Quote/Item/Abstract.php to no avail.

Does anyone have any idea where we could look from here?

EDIT: The problem appears to be that Magento calculates tax for discount purposes on an item by item (and child by child) basis regardless of how you have tax calculations configured.

I am implementing a temporary workaround. I copied the Store.php file from app/code/core/Mage/Core/Model to app/code/local/Mage/Core/Model and edited the function

public function roundPrice($price)
{
    return round($price, 2);
}

to be

public function roundPrice($price)
{
    return round($price, 5);
}

And I will have to search for every function that calls this roundPrice() function to make sure things are re-rounded before being inserted into the database. The cart and admin pages already round to 2 decimals, but the database will have unaccounted-for fractions of pennies otherwise. Still waiting on a better fix.

More info: Without changing or adding files, I decided to try a different configuration setting. I changed the “Tax Calculation Method Based On” and had the following results: (original setting was “Total")

With the original cart, (item 1 = 6.92 * 1, item 2 = 7.51* 1, item 3 = 12.87 * 4, Tax = 5.5%, shipping = 7.00, taxable)

Tax Calculation method based on = “Row Total” Discount Amount matches previous total (76.92) making the grand total correct

Tax Calculation method based on = “Unit Price” Discount and Total are now 76.93, one cent too much because an extra cent of Tax is being calculated both times

Split children to individual products by creating 3 new products at 12.87, instead of the last item being 12.87 * 4, now it is 12.87, item 4 is 12.87, item 5 is 12.87 and item 6 is 12.87, all one each

Tax Calculation method based on = “Row Total” Discount amount is 76.92, but the total was 76.93, so now the Grand Total after Discount is $0.01 even though the discount is configured to be way more than 76.93

Tax Calculation method based on = “Unit Price” Discount and Total are now 76.93, one cent too much because an extra cent of Tax is being calculated both times

Tax Calculation method based on = “Total” Same as original problem, final Grand total is (-$0.01) because the discount is 1 cent more than it should be

I then made my copy of the Store.php file in local and tested, all above scenarios are working fine, no extra pennies in the discount or the Grand total or tax.

marked as duplicate by Fabian Blechschmidt, Keyul Shah, Marius, Mufaddal, davidalger Mar 6 '14 at 3:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.