Dont set empty strings as tax totals

This commit is contained in:
Claudiu Lodromanean 2017-03-20 15:14:41 -07:00
parent 84692282d2
commit c0a01a1fe4
2 changed files with 51 additions and 2 deletions

View File

@ -77,7 +77,7 @@ class WC_Order_Item_Tax extends WC_Order_Item {
* @throws WC_Data_Exception
*/
public function set_tax_total( $value ) {
$this->set_prop( 'tax_total', wc_format_decimal( $value ) );
$this->set_prop( 'tax_total', $value ? wc_format_decimal( $value ) : 0 );
}
/**
@ -86,7 +86,7 @@ class WC_Order_Item_Tax extends WC_Order_Item {
* @throws WC_Data_Exception
*/
public function set_shipping_tax_total( $value ) {
$this->set_prop( 'shipping_tax_total', wc_format_decimal( $value ) );
$this->set_prop( 'shipping_tax_total', $value ? wc_format_decimal( $value ) : 0 );
}
/**

View File

@ -0,0 +1,49 @@
<?php
/**
* Order Item Tax Tests.
* @package WooCommerce\Tests\Order_Items
* @since 3.0.0
*/
class WC_Tests_Order_Item_Tax extends WC_Unit_Test_Case {
/**
* Test set_tax_total/get_tax_total.
*
* @since 3.0.0
*/
function test_set_get_tax_totals() {
$item = new WC_Order_Item_Tax;
$this->assertEquals( 0, $item->get_tax_total() );
$item->set_tax_total( "1.50" );
$this->assertEquals( "1.50", $item->get_tax_total() );
$item->set_tax_total( "" );
$this->assertEquals( 0, $item->get_tax_total() );
$item->set_tax_total( 10.99 );
$this->assertEquals( "10.99", $item->get_tax_total() );
}
/**
* Test set_tax_total/get_tax_total.
*
* @since 3.0.0
*/
function test_set_get_shipping_tax_totals() {
$item = new WC_Order_Item_Tax;
$this->assertEquals( 0, $item->get_shipping_tax_total() );
$item->set_shipping_tax_total( "1.50" );
$this->assertEquals( "1.50", $item->get_shipping_tax_total() );
$item->set_shipping_tax_total( "" );
$this->assertEquals( 0, $item->get_shipping_tax_total() );
$item->set_shipping_tax_total( 10.99 );
$this->assertEquals( "10.99", $item->get_shipping_tax_total() );
}
}