Hi,

I have a product which costs 5,35€. I apply a discount rule which recalculates the price by multiplying by 0.85.
The new price is 5,35 * 0.85 = 4,5475€. I display the price with only 2 decimals (4,55€).
I order 201 products. So 201 * 4,55€ = 914,55€, but the cart displays 914,05€.

The total price should use the price displayed with 2 decimals to be calculated.

This patch http://drupal.org/node/1137840 works fine with VAT tax type, but not with custom rule.

Comments

rszrama’s picture

StatusFileSize
new14.95 KB

The attached patch fixes this by abstracting our custom rounding support out of the Tax module and allowing rounding to be applied on a per-unit price alteration basis; the 5 actions pertaining to manipulating the amount of a unit price now have the option to round the resultant amount using the same modes we support for tax rounding.

I'm still investigating an upgrade path, but the patch is here for testing on new rules. Using your precise scenario, I get the math showing up properly... even when used in conjunction with VAT rounding!

rszrama’s picture

Title: Wrong calculation of the total price with a discount rule » Add a parameter to unit price manipulation actions to round the update amount
Component: Price » Line item
Status: Active » Fixed
StatusFileSize
new17.75 KB

Ok, as it turns out, I was able to add an update function to accommodate this new rounding mode setting I added. I'm going to actually default the new behavior to round up like we need it for our project, and it should work for a majority of use cases (except in those rare instances where you might need to round down... but it's easily configurable via the action form).

The only hitch here is that there's a bug in Rules versions preceding 7.x-2.0-rc2 that will cause the fix to be ignored. Rules added a "dirty" parameter that marks Rules as containing invalid configuration, and a fix was committed for the rc2 that checks and removes this dirty parameter on save of the Rule. So, to use the working update path, you must first update to Rules 7.x-2.0-rc2 or apply the patch in #1270042-7: Rules remain dirty even if they've been fixed via the UI.

Once you have that, update your code to the latest Commerce dev version or apply the attached patch. Then go to update.php and run Line Item update 7000 to have your Rules updated to use the new rounding mode parameter. Voila! You're fixed. : )

guguss’s picture

Well done, it works fine.

I finally chose to update Commerce to the DEV version (instead of using the patch) and to update Rules to the RC2 version.

I did some testing with different use cases and it seems to work as wanted.

Thanks again.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.