Work with 4dp for discounts so totals add up. Closes #2476.

This commit is contained in:
Mike Jolley 2013-02-20 18:50:28 +00:00
parent 15e6b14b58
commit 35d5e2997a
4 changed files with 9 additions and 8 deletions

File diff suppressed because one or more lines are too long

View File

@ -963,7 +963,7 @@ ul.wc_coupon_list_block {
}
}
input {
width: 60px;
width: 70px;
vertical-align:middle;
text-align: right;
}

View File

@ -1049,7 +1049,7 @@ class WC_Cart {
// Get item discount by dividing item cost by subtotal to get a %
if ( $this->subtotal_ex_tax )
$discount_percent = ( $values['data']->get_price_excluding_tax()*$values['quantity'] ) / $this->subtotal_ex_tax;
$discount_percent = ( $values['data']->get_price_excluding_tax() * $values['quantity'] ) / $this->subtotal_ex_tax;
else
$discount_percent = 0;
@ -1063,7 +1063,7 @@ class WC_Cart {
$item_discount = $item_discount / $values['quantity'];
// Pence
$price = ( $price * 100 );
$price = $price * 100;
// Check if discount is more than price
if ( $price < $item_discount )
@ -1078,7 +1078,8 @@ class WC_Cart {
$price = $price / 100;
// Cannot be below 0
if ( $price < 0 ) $price = 0;
if ( $price < 0 )
$price = 0;
// Add coupon to discount total (once, since this is a fixed cart discount and we don't want rounding issues)
if ( $add_totals ) {
@ -1419,7 +1420,7 @@ class WC_Cart {
// Line prices
$line_tax = get_option('woocommerce_tax_round_at_subtotal') == 'no' ? $this->tax->round( $discounted_tax_amount ) : $discounted_tax_amount;
$line_total = $this->tax->round( ( $discounted_price * $values['quantity'] ) - $this->tax->round( $line_tax ) );
$line_total = ( $discounted_price * $values['quantity'] ) - $this->tax->round( $line_tax );
// Add any product discounts (after tax)
$this->apply_product_discounts_after_tax( $values, $line_total + $discounted_tax_amount );

View File

@ -260,8 +260,8 @@ class WC_Checkout {
woocommerce_add_order_item_meta( $item_id, '_tax_class', $_product->get_tax_class() );
woocommerce_add_order_item_meta( $item_id, '_product_id', $values['product_id'] );
woocommerce_add_order_item_meta( $item_id, '_variation_id', $values['variation_id'] );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal', woocommerce_format_decimal( $values['line_subtotal'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'] ) );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal', woocommerce_format_decimal( $values['line_subtotal'], 4 ) );
woocommerce_add_order_item_meta( $item_id, '_line_total', woocommerce_format_decimal( $values['line_total'], 4 ) );
woocommerce_add_order_item_meta( $item_id, '_line_tax', woocommerce_format_decimal( $values['line_tax'], 4 ) );
woocommerce_add_order_item_meta( $item_id, '_line_subtotal_tax', woocommerce_format_decimal( $values['line_subtotal_tax'], 4 ) );