Don't round Closes #2861.

This commit is contained in:
Mike Jolley 2013-04-12 10:59:38 +01:00
parent cb836a5fff
commit 55b01245cd
3 changed files with 49 additions and 33 deletions

View File

@ -1571,55 +1571,71 @@ class WC_Cart {
}
}
// Set tax total to sum of all tax rows
$this->tax_total = $this->tax->get_tax_total( $this->taxes );
// VAT exemption done at this point - so all totals are correct before exemption
if ( $woocommerce->customer->is_vat_exempt() ) {
$this->shipping_tax_total = $this->tax_total = 0;
$this->taxes = $this->shipping_taxes = array();
foreach ( $this->cart_contents as $cart_item_key => $item )
$this->cart_contents[ $cart_item_key ]['line_subtotal_tax'] = $this->cart_contents[ $cart_item_key ]['line_tax'] = 0;
}
// Cart Discounts (after tax)
$this->apply_cart_discounts_after_tax();
// Only calculate the grand total + shipping if on the cart/checkout
if ( is_checkout() || is_cart() || defined('WOOCOMMERCE_CHECKOUT') || defined('WOOCOMMERCE_CART') ) {
// Total up/round taxes
if ( get_option('woocommerce_tax_round_at_subtotal') == 'no' ) {
$this->tax_total = $this->tax->get_tax_total( $this->taxes );
$this->taxes = array_map( array( $this->tax, 'round' ), $this->taxes );
} else {
$this->tax_total = array_sum( $this->taxes );
}
// Cart Shipping
$this->calculate_shipping();
// VAT exemption for shipping
if ( $woocommerce->customer->is_vat_exempt() ) {
$this->shipping_tax_total = 0;
$this->shipping_taxes = array();
// Total up/round taxes for shipping
if ( get_option('woocommerce_tax_round_at_subtotal') == 'no' ) {
$this->shipping_tax_total = $this->tax->get_tax_total( $this->shipping_taxes );
$this->shipping_taxes = array_map( array( $this->tax, 'round' ), $this->shipping_taxes );
} else {
$this->shipping_tax_total = array_sum( $this->shipping_taxes );
}
// Round cart/shipping tax rows
$this->taxes = array_map( array( $this->tax, 'round' ), $this->taxes );
$this->shipping_taxes = array_map( array( $this->tax, 'round' ), $this->shipping_taxes );
// VAT exemption done at this point - so all totals are correct before exemption
if ( $woocommerce->customer->is_vat_exempt() )
$this->remove_taxes();
// Cart Discounts (after tax)
$this->apply_cart_discounts_after_tax();
// Allow plugins to hook and alter totals before final total is calculated
do_action( 'woocommerce_calculate_totals', $this );
/**
* Grand Total
*
* Based on discounted product prices, discounted tax, shipping cost + tax, and any discounts to be added after tax (e.g. store credit)
*/
$this->total = apply_filters( 'woocommerce_calculated_total', number_format( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total - $this->discount_total + $this->fee_total, $this->dp, '.', '' ), $this );
// Grand Total - Discounted product prices, discounted tax, shipping cost + tax, and any discounts to be added after tax (e.g. store credit)
$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', number_format( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total - $this->discount_total + $this->fee_total, $this->dp, '.', '' ), $this ) );
if ( $this->total < 0 )
$this->total = 0;
} else {
// Set tax total to sum of all tax rows
$this->tax_total = $this->tax->get_tax_total( $this->taxes );
// VAT exemption done at this point - so all totals are correct before exemption
if ( $woocommerce->customer->is_vat_exempt() )
$this->remove_taxes();
// Cart Discounts (after tax)
$this->apply_cart_discounts_after_tax();
}
$this->set_session();
}
/**
* remove_taxes function.
*
* @access public
* @return void
*/
public function remove_taxes() {
$this->shipping_tax_total = $this->tax_total = 0;
$this->taxes = $this->shipping_taxes = array();
foreach ( $this->cart_contents as $cart_item_key => $item )
$this->cart_contents[ $cart_item_key ]['line_subtotal_tax'] = $this->cart_contents[ $cart_item_key ]['line_tax'] = 0;
}
/**
* looks at the totals to see if payment is actually required.
*
@ -1653,7 +1669,6 @@ class WC_Cart {
$this->shipping_total = $woocommerce->shipping->shipping_total; // Shipping Total
$this->shipping_label = $woocommerce->shipping->shipping_label; // Shipping Label
$this->shipping_taxes = $woocommerce->shipping->shipping_taxes; // Shipping Taxes
$this->shipping_tax_total = $this->tax->get_tax_total( $this->shipping_taxes ); // Shipping tax amount
}
/**

View File

@ -346,8 +346,8 @@ class WC_Checkout {
update_post_meta( $order_id, '_order_shipping', woocommerce_format_total( $woocommerce->cart->shipping_total ) );
update_post_meta( $order_id, '_order_discount', woocommerce_format_total( $woocommerce->cart->get_order_discount_total() ) );
update_post_meta( $order_id, '_cart_discount', woocommerce_format_total( $woocommerce->cart->get_cart_discount_total() ) );
update_post_meta( $order_id, '_order_tax', woocommerce_format_total( $woocommerce->cart->tax_total ) );
update_post_meta( $order_id, '_order_shipping_tax', woocommerce_format_total( $woocommerce->cart->shipping_tax_total ) );
update_post_meta( $order_id, '_order_tax', woocommerce_clean( $woocommerce->cart->tax_total ) );
update_post_meta( $order_id, '_order_shipping_tax', woocommerce_clean( $woocommerce->cart->shipping_tax_total ) );
update_post_meta( $order_id, '_order_total', woocommerce_format_total( $woocommerce->cart->total ) );
update_post_meta( $order_id, '_order_key', apply_filters('woocommerce_generate_order_key', uniqid('order_') ) );
update_post_meta( $order_id, '_customer_user', absint( $this->customer_id ) );

View File

@ -167,6 +167,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
= X =
* Feature - Option for GA _setDomainName.
* Tweak - Removed rounding when option to round at subtotal is set.
* Fix - Allow extra flat rate options even if main rate is 0.
* Fix - Fix email subject lines if options not set.
* Fix - Prevent over-sanitization of attribute terms when editing products.