Skip to content

Commit 52b5dc7

Browse files
committed
Cleanup
1 parent fedf2e4 commit 52b5dc7

5 files changed

Lines changed: 38 additions & 21 deletions

File tree

includes/classes/Feature/WooCommerce/Orders.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,12 @@ public function hpos_compatibility_notice( array $notices ): array {
375375
return $notices;
376376
}
377377

378-
if ( $this->is_hpos_compatible() ) {
378+
if ( ! $this->is_hpos_enabled() || $this->is_hpos_compatible() ) {
379379
return $notices;
380380
}
381381

382382
$notices['wc_orders_incompatible'] = [
383-
'html' => esc_html__( "Although the WooCommerce and Protected Content features are enabled, ElasticPress will not integrate with the WooCommerce Orders list if WooCommerce's High-performance order storage is enabled on WooCommerce versions below 9.8.0. HPOS is compatible with ElasticPress on WooCommerce 9.8.0 and greater.", 'elasticpress' ),
383+
'html' => esc_html__( "Although the WooCommerce and Protected Content features are enabled, ElasticPress will not integrate with the WooCommerce Orders list while WooCommerce's High-performance order storage is enabled. HPOS integration requires WooCommerce 9.8.0 or greater.", 'elasticpress' ),
384384
'type' => 'warning',
385385
'dismiss' => true,
386386
'scope' => 'site',

includes/classes/Feature/WooCommerce/OrdersAutosuggest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,10 @@ public function is_enabled(): bool {
528528
* @return boolean
529529
*/
530530
public function is_hpos_compatible() {
531+
if ( ! $this->woocommerce->orders->is_hpos_enabled() ) {
532+
return true;
533+
}
534+
531535
return $this->woocommerce->orders->is_hpos_compatible();
532536
}
533537

tests/e2e/src/specs/woocommerce.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -916,24 +916,24 @@ test.describe('WooCommerce Feature', { tag: '@group2' }, () => {
916916
test('Will show a navigable list of suggested results when searching orders', async ({
917917
loggedInPage,
918918
}) => {
919-
await goToAdminPage(loggedInPage, 'edit.php?post_type=shop_order');
919+
await goToAdminPage(loggedInPage, 'admin.php?page=wc-orders');
920920

921921
// The combobox will not render if not using ElasticPress.io
922922
if (!isEpIo()) {
923923
await expect(
924-
loggedInPage.locator('#posts-filter .ep-combobox__input'),
924+
loggedInPage.locator('#wc-orders-filter .ep-combobox__input'),
925925
).not.toBeVisible();
926926
return;
927927
}
928928

929929
// Prepare aliases
930930
const apiRequestPromise = loggedInPage.waitForResponse('**/api/v1/search/orders/*');
931-
const input = loggedInPage.locator('#posts-filter .ep-combobox__input');
931+
const input = loggedInPage.locator('#wc-orders-filter .ep-combobox__input');
932932
const description = loggedInPage.locator(
933-
'#posts-filter .ep-combobox > .screen-reader-text',
933+
'#wc-orders-filter .ep-combobox > .screen-reader-text',
934934
);
935-
const listbox = loggedInPage.locator('#posts-filter .ep-combobox__list');
936-
const submit = loggedInPage.locator('#posts-filter .search-box .button');
935+
const listbox = loggedInPage.locator('#wc-orders-filter .ep-combobox__list');
936+
const submit = loggedInPage.locator('#wc-orders-filter .search-box .button');
937937

938938
// Search for "Antwon". 3 suggestions should appear
939939
await input.fill('Antwon');
@@ -1003,7 +1003,7 @@ test.describe('WooCommerce Feature', { tag: '@group2' }, () => {
10031003
await expect(loggedInPage).toHaveURL(/.*post\.php\?post=/);
10041004

10051005
// Test clicking suggestions
1006-
await goToAdminPage(loggedInPage, 'edit.php?post_type=shop_order');
1006+
await goToAdminPage(loggedInPage, 'admin.php?page=wc-orders');
10071007
await input.fill('Antwon');
10081008
await loggedInPage.waitForResponse('**/api/v1/search/orders/*');
10091009
await listbox.locator('> *').nth(1).click();

tests/php/features/WooCommerce/TestWooCommerceOrders.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,20 +356,21 @@ public function test_hpos_compatibility_notice() {
356356
ElasticPress\Features::factory()->activate_feature( 'protected_content' );
357357
$this->assertCount( 1, $this->orders->hpos_compatibility_notice( $notices ) );
358358

359-
$this->enable_hpos();
360-
361359
// Force an unsupported WooCommerce version requirement.
362-
add_filter(
363-
'ep_woocommerce_hpos_min_version',
364-
function () {
365-
return '99.0.0';
366-
}
367-
);
360+
$change_min_version = function () {
361+
return '99.0.0';
362+
};
363+
add_filter( 'ep_woocommerce_hpos_min_version', $change_min_version );
364+
365+
// While orders are stored as posts there is nothing to warn about.
366+
$this->assertCount( 1, $this->orders->hpos_compatibility_notice( $notices ) );
367+
368+
$this->enable_hpos();
368369

369370
$new_notices = $this->orders->hpos_compatibility_notice( $notices );
370371
$this->assertCount( 2, $new_notices );
371372
$this->assertArrayHasKey( 'wc_orders_incompatible', $new_notices );
372-
$this->assertStringContainsString( '9.8.0 and greater', $new_notices['wc_orders_incompatible']['html'] );
373+
$this->assertStringContainsString( 'requires WooCommerce 9.8.0 or greater', $new_notices['wc_orders_incompatible']['html'] );
373374

374375
/**
375376
* Test if the notice is hidden when the user already dismissed it

tests/php/features/WooCommerce/TestWooCommerceOrdersAutosuggest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,34 @@ public function test_is_enabled() {
366366
public function test_is_hpos_compatible() {
367367
$this->assertTrue( $this->orders_autosuggest->is_hpos_compatible() );
368368

369+
// Force an unsupported WooCommerce version requirement.
370+
$change_min_version = function () {
371+
return '99.0.0';
372+
};
373+
add_filter( 'ep_woocommerce_hpos_min_version', $change_min_version );
374+
375+
// Orders stored as posts are supported on any WooCommerce version.
376+
$this->assertTrue( $this->orders_autosuggest->is_hpos_compatible() );
377+
369378
// Turn HPOS on
370379
$custom_orders_table = \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::CUSTOM_ORDERS_TABLE_USAGE_ENABLED_OPTION;
371380
$change_custom_orders_table = function () {
372381
return 'yes';
373382
};
374383
add_filter( 'pre_option_' . $custom_orders_table, $change_custom_orders_table );
375384

376-
// Force an unsupported WooCommerce version requirement.
385+
$this->assertFalse( $this->orders_autosuggest->is_hpos_compatible() );
386+
387+
// HPOS is supported on WooCommerce versions that allow query integration.
388+
remove_filter( 'ep_woocommerce_hpos_min_version', $change_min_version );
377389
add_filter(
378390
'ep_woocommerce_hpos_min_version',
379391
function () {
380-
return '99.0.0';
392+
return '0.0.1';
381393
}
382394
);
383395

384-
$this->assertFalse( $this->orders_autosuggest->is_hpos_compatible() );
396+
$this->assertTrue( $this->orders_autosuggest->is_hpos_compatible() );
385397
}
386398

387399
/**

0 commit comments

Comments
 (0)