Tests when tax is not enabled
This commit is contained in:
parent
fb64e77f24
commit
fe847630b2
|
@ -1043,7 +1043,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
$item = $this->get_item( $item_id, false );
|
||||
|
||||
// If the prices include tax, discounts should be taken off the tax inclusive prices like in the cart.
|
||||
if ( $this->get_prices_include_tax() ) {
|
||||
if ( $this->get_prices_include_tax() && wc_tax_enabled() ) {
|
||||
$amount_tax = WC_Tax::get_tax_total( WC_Tax::calc_tax( $amount, WC_Tax::get_rates( $item->get_tax_class() ), true ) );
|
||||
$amount -= $amount_tax;
|
||||
$item->set_total( max( 0, $item->get_total() - $amount ) );
|
||||
|
@ -1083,7 +1083,7 @@ abstract class WC_Abstract_Order extends WC_Abstract_Legacy_Order {
|
|||
foreach ( $all_discounts[ $coupon_code ] as $item_id => $item_discount_amount ) {
|
||||
$item = $this->get_item( $item_id, false );
|
||||
|
||||
if ( $this->get_prices_include_tax() ) {
|
||||
if ( $this->get_prices_include_tax() && wc_tax_enabled() ) {
|
||||
$amount_tax = array_sum( WC_Tax::calc_tax( $item_discount_amount, WC_Tax::get_rates( $item->get_tax_class() ), true ) );
|
||||
$discount_tax += $amount_tax;
|
||||
$amount = $amount - $amount_tax;
|
||||
|
|
|
@ -80,12 +80,12 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
|
|||
$coupon_item_1->set_props( array(
|
||||
'code' => 'test-coupon-1',
|
||||
'discount' => 1,
|
||||
'discount_tax' => 0.1,
|
||||
'discount_tax' => get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ? 0.1 : 0,
|
||||
) );
|
||||
$coupon_item_2->set_props( array(
|
||||
'code' => 'this-is-a-virtal-coupon',
|
||||
'discount' => 200,
|
||||
'discount_tax' => 20,
|
||||
'discount_tax' => get_option( 'woocommerce_calc_taxes', 'no' ) === 'yes' ? 20 : 0,
|
||||
) );
|
||||
}
|
||||
|
||||
|
@ -320,4 +320,59 @@ class WC_Tests_Order_Coupons extends WC_Unit_Test_Case {
|
|||
$order->apply_coupon( 'test-coupon-2' );
|
||||
$this->assertEquals( '639.2', $order->get_total(), $order->get_total() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test: test_remove_coupon_from_order_no_tax
|
||||
*/
|
||||
function test_remove_coupon_from_order_no_tax_inc_prices_on() {
|
||||
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
||||
update_option( 'woocommerce_calc_taxes', 'no' );
|
||||
$this->setUp();
|
||||
|
||||
$order_id = $this->objects['order']->get_id();
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
// Check it's expected.
|
||||
$this->assertEquals( 'shop_order', $order->get_type() );
|
||||
$this->assertEquals( '799', $order->get_total(), $order->get_total() );
|
||||
|
||||
// Remove the virtual coupon. Total should be 999.
|
||||
$order->remove_coupon( 'this-is-a-virtal-coupon' );
|
||||
$this->assertEquals( '999', $order->get_total(), $order->get_total() );
|
||||
|
||||
// Remove the other coupon. Total should be 1000.
|
||||
$order->remove_coupon( 'test-coupon-1' );
|
||||
$this->assertEquals( '1000', $order->get_total(), $order->get_total() );
|
||||
|
||||
// Reset.
|
||||
$this->setUp();
|
||||
|
||||
$order_id = $this->objects['order']->get_id();
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
// Check it's expected.
|
||||
$this->assertEquals( 'shop_order', $order->get_type() );
|
||||
$this->assertEquals( '799', $order->get_total(), $order->get_total() );
|
||||
|
||||
// Do the above tests in reverse.
|
||||
$order->remove_coupon( 'test-coupon-1' );
|
||||
$this->assertEquals( '800', $order->get_total(), $order->get_total() );
|
||||
$order->remove_coupon( 'this-is-a-virtal-coupon' );
|
||||
$this->assertEquals( '1000', $order->get_total(), $order->get_total() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Test: test_add_coupon_to_order_no_tax
|
||||
*/
|
||||
function test_add_coupon_to_order_no_tax_inc_prices_on() {
|
||||
update_option( 'woocommerce_prices_include_tax', 'yes' );
|
||||
update_option( 'woocommerce_calc_taxes', 'no' );
|
||||
$this->setUp();
|
||||
|
||||
$order_id = $this->objects['order']->get_id();
|
||||
$order = wc_get_order( $order_id );
|
||||
|
||||
$order->apply_coupon( 'test-coupon-2' );
|
||||
$this->assertEquals( '639.2', $order->get_total(), $order->get_total() );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue