Skip to content

Commit 2bb951c

Browse files
committed
Log skipped line items and add a test for a truthy non-numeric price
1 parent d5f071d commit 2bb951c

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

classes/class-wc-connect-taxjar-integration.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,9 @@ protected function get_line_items( $wc_cart_object ) {
10651065
'discount' => $discount,
10661066
'tax_location' => $tax_location,
10671067
);
1068+
} else {
1069+
// A cart left with no numeric line sends no request, so this is its only trace.
1070+
$this->_log( 'Skipping line item for product ' . $id . ': non-numeric price "' . $unit_price . '"' );
10681071
}
10691072
}
10701073

tests/php/test-class-wc-connect-taxjar-integration.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,7 @@ public function test_get_line_items_structure() {
447447
}
448448

449449
/**
450-
* A pricing filter can empty a price after the item is already in the cart.
451-
* wc_format_decimal() passes that through, and a non-numeric unit price is fatal
452-
* in the totals arithmetic, so the line is skipped.
450+
* Test that a line emptied by a pricing filter after being added to the cart is skipped.
453451
*/
454452
public function test_get_line_items_skips_line_with_non_numeric_price() {
455453
$this->product = WC_Helper_Product::create_simple_product();
@@ -465,10 +463,29 @@ public function test_get_line_items_skips_line_with_non_numeric_price() {
465463
}
466464

467465
/**
468-
* A zero price is legitimate and must keep reaching TaxJar, so the guard has to be
469-
* is_numeric() and not a truthiness check. See
470-
* test_zero_amount_response_persists_real_itemized_rates() for what the response to
471-
* a $0 line carries.
466+
* Test that a '-' price is skipped, being truthy and non-empty where '' is neither.
467+
*/
468+
public function test_get_line_items_skips_line_with_dash_price() {
469+
$this->assertSame( '-', wc_format_decimal( '-' ) );
470+
471+
$this->product = WC_Helper_Product::create_simple_product();
472+
$this->product->save();
473+
474+
WC()->cart->add_to_cart( $this->product->get_id(), 2 );
475+
476+
$dash_price = function () {
477+
return '-';
478+
};
479+
480+
add_filter( 'woocommerce_product_get_price', $dash_price );
481+
$line_items = $this->invoke_protected_method( 'get_line_items', array( WC()->cart ) );
482+
remove_filter( 'woocommerce_product_get_price', $dash_price );
483+
484+
$this->assertSame( array(), $line_items );
485+
}
486+
487+
/**
488+
* Test that a zero price still reaches TaxJar, being falsy but numeric.
472489
*/
473490
public function test_get_line_items_keeps_line_priced_zero() {
474491
$this->product = WC_Helper_Product::create_simple_product();

0 commit comments

Comments
 (0)