Fixed wrong number of decimal precision, closes #11368

This commit is contained in:
Claudio Sanches 2016-07-11 17:26:54 +02:00
parent 7d9d091767
commit 7778583340
8 changed files with 20 additions and 8 deletions

View File

@ -1484,7 +1484,7 @@ abstract class WC_Abstract_Order {
$total_discount = (double) $this->cart_discount + (double) $this->cart_discount_tax;
}
}
return apply_filters( 'woocommerce_order_amount_total_discount', round( $total_discount, WC_ROUNDING_PRECISION ), $this );
return apply_filters( 'woocommerce_order_amount_total_discount', round( $total_discount, wc_get_rounding_precision() ), $this );
}
/**

View File

@ -277,7 +277,7 @@ class WC_Admin_Assets {
'currency_format_decimal_sep' => esc_attr( wc_get_price_decimal_separator() ),
'currency_format_thousand_sep' => esc_attr( wc_get_price_thousand_separator() ),
'currency_format' => esc_attr( str_replace( array( '%1$s', '%2$s' ), array( '%s', '%v' ), get_woocommerce_price_format() ) ), // For accounting JS
'rounding_precision' => WC_ROUNDING_PRECISION,
'rounding_precision' => wc_get_rounding_precision(),
'tax_rounding_mode' => WC_TAX_ROUNDING_MODE,
'product_types' => array_unique( array_merge( array( 'simple', 'grouped', 'variable', 'external' ), array_keys( wc_get_product_types() ) ) ),
'i18n_download_permission_fail' => __( 'Could not grant access - the user may already have permission for this file or billing email is not set. Ensure the billing email is set, and the order has been saved.', 'woocommerce' ),

View File

@ -1260,7 +1260,7 @@ class WC_Cart {
$line_subtotal_tax = 0;
$line_subtotal = $line_price;
$line_tax = 0;
$line_total = round( $discounted_price * $values['quantity'], WC_ROUNDING_PRECISION );
$line_total = round( $discounted_price * $values['quantity'], wc_get_rounding_precision() );
/**
* Prices include tax.
@ -1283,7 +1283,7 @@ class WC_Cart {
$taxes = WC_Tax::calc_tax( $line_price, $base_tax_rates, true, true );
// Now we have a new item price (excluding TAX)
$line_subtotal = round( $line_price - array_sum( $taxes ), WC_ROUNDING_PRECISION );
$line_subtotal = round( $line_price - array_sum( $taxes ), wc_get_rounding_precision() );
$taxes = WC_Tax::calc_tax( $line_subtotal, $item_tax_rates );
$line_subtotal_tax = array_sum( $taxes );

View File

@ -737,7 +737,7 @@ class WC_Coupon {
}
}
$discount = wc_cart_round_discount( $discount, WC_ROUNDING_PRECISION );
$discount = wc_cart_round_discount( $discount, wc_get_rounding_precision() );
return apply_filters( 'woocommerce_coupon_get_discount_amount', $discount, $discounting_amount, $cart_item, $single, $this );
}

View File

@ -35,7 +35,7 @@ class WC_Tax {
* @access public
*/
public static function init() {
self::$precision = WC_ROUNDING_PRECISION;
self::$precision = wc_get_rounding_precision();
self::$round_at_subtotal = 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' );
}

View File

@ -1353,3 +1353,17 @@ function wc_product_attribute_uasort_comparison( $a, $b ) {
}
return ( $a['position'] < $b['position'] ) ? -1 : 1;
}
/**
* Get rounding precision.
*
* @since 2.6.3
* @return int
*/
function wc_get_rounding_precision() {
if ( defined( 'WC_ROUNDING_PRECISION' ) ) {
return absint( WC_ROUNDING_PRECISION );
}
return wc_get_price_decimals() + 2;
}

View File

@ -46,7 +46,6 @@ class WC_Tests_Main_Class extends WC_Unit_Test_Case {
$this->assertEquals( $this->wc->version, WC_VERSION );
$this->assertEquals( WC_VERSION, WOOCOMMERCE_VERSION );
$this->assertEquals( 4, WC_ROUNDING_PRECISION );
$this->assertContains( WC_TAX_ROUNDING_MODE, array( 2, 1 ) );
$this->assertEquals( '|', WC_DELIMITER );
$this->assertNotEquals( WC_LOG_DIR, '' );

View File

@ -181,7 +181,6 @@ final class WooCommerce {
$this->define( 'WC_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
$this->define( 'WC_VERSION', $this->version );
$this->define( 'WOOCOMMERCE_VERSION', $this->version );
$this->define( 'WC_ROUNDING_PRECISION', 4 );
$this->define( 'WC_DISCOUNT_ROUNDING_MODE', 2 );
$this->define( 'WC_TAX_ROUNDING_MODE', 'yes' === get_option( 'woocommerce_prices_include_tax', 'no' ) ? 2 : 1 );
$this->define( 'WC_DELIMITER', '|' );