Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only integrate WC queries if main query, search, or has ep_integrate #3546

Merged
merged 5 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert changes on orders
  • Loading branch information
felipeelia committed Jul 20, 2023
commit dbe3ec5ab7340ea0f585fcf2d30db0ec42923405
8 changes: 1 addition & 7 deletions includes/classes/Feature/WooCommerce/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function search_order( $wp ) {
}

/**
* Determines whether or not ES should be integrating with the provided query.
* Determines whether or not ES should be integrating with the provided query
*
* An order-related query will be integrated if:
* * Is the main query OR is a search OR has `ep_integrate` set as true
Expand All @@ -259,12 +259,6 @@ public function search_order( $wp ) {
* @return bool
*/
public function should_integrate_with_query( \WP_Query $query ) : bool {
$has_ep_integrate = isset( $query->query_vars['ep_integrate'] ) && filter_var( $query->query_vars['ep_integrate'], FILTER_VALIDATE_BOOLEAN );

if ( ! $query->is_main_query() && ! $query->is_search() && ! $has_ep_integrate ) {
return false;
}

/**
* Check the post type
*/
Expand Down
44 changes: 2 additions & 42 deletions tests/php/features/WooCommerce/TestWooCommerceOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testShopOrderPostTypeQueryOn() {


/**
* Test Shop Order post type query does not get automatically integrated when the protected content feature is activated.
* Test Shop Order post type query does get integrated when the protected content feature is activated.
*
* @group woocommerce
* @group woocommerce-orders
Expand All @@ -126,7 +126,7 @@ public function testShopOrderPostTypeQueryWhenProtectedContentEnable() {
);
$query = new \WP_Query( $args );

$this->assertNull( $query->elasticsearch_success );
$this->assertTrue( $query->elasticsearch_success );
$this->assertEquals( 1, $query->post_count );
$this->assertEquals( 1, $query->found_posts );
}
Expand Down Expand Up @@ -160,46 +160,6 @@ public function testShopOrderPostTypeQueryWhenEPIntegrateSetFalse() {
$this->assertNull( $query->elasticsearch_success );
}

/**
* Test Shop Order post type query does get integrated when the protected content feature is activated and ep_integrate is set to true.
*
* @since 4.7.0
* @group woocommerce
* @group woocommerce-orders
*/
public function testShopOrderPostTypeQueryWhenEPIntegrateSetTrue() {
ElasticPress\Features::factory()->activate_feature( 'protected_content' );
ElasticPress\Features::factory()->activate_feature( 'woocommerce' );
ElasticPress\Features::factory()->setup_features();

$args = array(
'post_type' => 'shop_order',
'ep_integrate' => true,
);
$query = new \WP_Query( $args );

$this->assertTrue( $query->elasticsearch_success );
}

/**
* Test Shop Order post type query does get integrated when the protected content feature is activated and it is the main query.
*
* @since 4.7.0
* @group woocommerce
* @group woocommerce-orders
*/
public function testShopOrderPostTypeQueryWhenMainQuery() {
global $wp_the_query;

ElasticPress\Features::factory()->activate_feature( 'protected_content' );
ElasticPress\Features::factory()->activate_feature( 'woocommerce' );
ElasticPress\Features::factory()->setup_features();

$wp_the_query->query( [ 'post_type' => 'shop_order' ] );

$this->assertTrue( $wp_the_query->elasticsearch_success );
}

/**
* Test search for shop orders by order ID
*
Expand Down