Skip to content

Commit

Permalink
Add product test.
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Apr 11, 2024
1 parent 83c2933 commit ed3e67c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion includes/widgets/search-widget/class-search-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ public function gf_query_filter( &$query, $view, $request ) {

if ( $this->is_product_field( $filter ) ) {
$original_left = clone $left;
$column = $left instanceof GF_Query_Call ? reset( $left->columns ) : $left;
$column = $left instanceof GF_Query_Call ? $left->columns[0] ?? null : $left;
$column_name = sprintf( '`%s`.`%s`', $column->alias, $column->is_entry_column() ? $column->field_id : 'meta_value' );

// Add the original join back.
Expand Down
15 changes: 12 additions & 3 deletions tests/unit-tests/GravityView_Widget_Search_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1813,9 +1813,8 @@ public function test_search_with_number_field() {
wp_generate_password( 4, false ) => array(
'id' => 'search_bar',
'search_fields' => json_encode( array(
array(
'field' => '9',
),
array( 'field' => '9' ),
array( 'field' => '26' ),
)
),
),
Expand All @@ -1824,12 +1823,14 @@ public function test_search_with_number_field() {
) );

$view = \GV\View::from_post( $post );
$currency_symbol = rgar( RGCurrency::get_currency( GFCommon::get_currency() ), 'symbol_left' );

foreach ( array( 1, 5, 7, 10, '-20.23' ) as $number ) {
$this->factory->entry->create_and_get( array(
'form_id' => $form['id'],
'status' => 'active',
'9' => $number,
'26' => 'product name|' . $currency_symbol . $number,
) );
}

Expand Down Expand Up @@ -1859,6 +1860,7 @@ public function test_search_with_number_field() {

remove_all_filters('gravityview_search_operator');

// Number field
$_GET = [ 'filter_9' => [ 'min' => -21, 'max' => 9 ], 'mode' => 'all' ];
$this->assertEquals( 4, $view->get_entries()->count() );

Expand All @@ -1868,6 +1870,13 @@ public function test_search_with_number_field() {
$entries = $view->get_entries()->all();
$this->assertSame( [ '7', '5' ], [ $entries[0]->as_entry()[9], $entries[1]->as_entry()[9] ] );

// Product field.
$_GET = [ 'filter_26' => [ 'min' => -21, 'max' => 6.50 ], 'mode' => 'all' ];
$this->assertEquals( 3, $view->get_entries()->count() );

$_GET = [ 'filter_26' => [ 'min' => -20, 'max' => 7 ], 'mode' => 'all' ];
$this->assertEquals( 3, $view->get_entries()->count() );

$_GET = array();
}
}

0 comments on commit ed3e67c

Please sign in to comment.