Commerce Rounding
Categories
Component ID
2126609
Component name
Commerce Rounding
Component type
module
Maintenance status
Development status
Component security advisory coverage
not-covered
Downloads
1082
Component created
Component changed
Component body
Commerce Rounding adds additional line item with rounding if you need to round the price to integers or to some certain amounts of cents.
It was inspired by the solution suggested by the Commerce authors, e.g. here.
This module defines its own price type and line item type rounding and two rules (enabled by default) to update the order rounding item after each update: commerce_rounding_apply and commerce_rounding_delete_rounding_line_items.
If you need different rounding algorithm, you can easily implement your own, by setting the commerce_rounding_function variable to your own function.
Example implementation of custom rounding algorithm:
// settings.php
$conf['commerce_rounding_function'] = 'commerce_rounding_value';
// your_custom.module
/**
* Default function for rounding value.
*
* @param int $total_price
* Total price
* @param string $currency_code
* Currency code
* @return int
* Positive or negative rounding
*/
function commerce_rounding_value($total_price, $currency_code) {
$residue = $total_price % 100;
if ($residue >= 50) {
$rounding = 100 - $residue;
}
else {
$rounding = -$residue;
}
return $rounding;
}
