Skip to content

Conversation

@coreymckrill
Copy link
Contributor

@coreymckrill coreymckrill commented May 23, 2023

Changes proposed in this Pull Request:

  1. Populates the post_type property of WP_Screen when on an order-related admin screen with custom order tables set to authoritative, for better consistency between the posts UI and the COT UI.
  2. Adds the public is_order_screen method to the Orders PageController class, which can be used to check if the current admin screen is an order-related screen, regardless of which tables are authoritative.
  3. Adds helper methods to OrderUtil to check for specific order-related admin screens.

Fixes #37484

How to test the changes in this Pull Request:

This PR introduces new utility functions, but doesn't use them anywhere in the existing codebase. So one good way to test the new functions is with a simple mu-plugin. Add the following snippet to a new file in the wp-content/mu-plugins directory:

<?php

use Automattic\WooCommerce\Internal\Admin\Orders\PageController;
use Automattic\WooCommerce\Utilities\OrderUtil;

add_action(
	'admin_notices',
	function() {
		$page_controller = wc_get_container()->get( PageController::class );
		echo '<div class="notice"><pre>';
		printf( "Any order screen: %s\n", $page_controller->is_order_screen() ? 'true' : 'false' );
		printf( "Order list table: %s\n", OrderUtil::is_order_list_table_screen() ? 'true' : 'false' );
		printf( "Edit order: %s\n", OrderUtil::is_order_edit_screen() ? 'true' : 'false' );
		printf( "New order: %s\n", OrderUtil::is_new_order_screen() ? 'true' : 'false' );
		echo '</pre></div>';
	}
);

This will add a notice to the top of many pages in WP Admin that shows the results of running each of the new utility functions (notably, block editor screens will not show this notice).

  1. Turn on custom order tables. In WP Admin navigate to WooCommerce > Settings > Advanced > Features. Check the box for "Enable the high performance order storage feature" and save changes. Then click the link for Custom data stores. Check the box for "Keep the posts table and the orders tables synchronized" and choose "Use the WooCommerce orders tables". Save changes.
  2. Now navigate to WooCommerce > Orders and check that the results in the admin notice are accurate. Try editing an existing order and creating a new order and check the results there as well.
  3. Navigate to some other areas of WP Admin that are unrelated to orders. All of the results in the admin notice should be false.
  4. Now switch the custom order tables to that the Posts table is authoritative. Navigate to WooCommerce > Settings > Advanced > Custom data stores. Choose "Use the WordPress posts table" and save changes.
  5. Now try going back to all the same screens as the first time around, and make sure the results in the admin notice are still accurate.

@github-actions
Copy link
Contributor

github-actions bot commented May 23, 2023

Test Results Summary

Commit SHA: d6eab36

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests26700202690m 50s
E2E Tests1940010020419m 30s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

This ensures that the instance of the page controller class that
is used to set up the HPOS order admin screens is accessible and has
all its properties set correctly for use with the new is_order_screen
method.
@coreymckrill coreymckrill force-pushed the fix/37484/hpos-screen-props branch from a47c3e8 to d6eab36 Compare May 24, 2023 23:27
@coreymckrill coreymckrill marked this pull request as ready for review May 24, 2023 23:46
@coreymckrill coreymckrill requested review from a team and vedanshujain and removed request for a team May 24, 2023 23:46
@github-actions
Copy link
Contributor

Hi @vedanshujain,

Apart from reviewing the code changes, please make sure to review the testing instructions as well.

You can follow this guide to find out what good testing instructions should look like:
https://github.com/woocommerce/woocommerce/wiki/Writing-high-quality-testing-instructions

Copy link
Contributor

@vedanshujain vedanshujain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! And very cool testing instructions!

@vedanshujain vedanshujain merged commit 25843a9 into trunk Jun 1, 2023
@vedanshujain vedanshujain deleted the fix/37484/hpos-screen-props branch June 1, 2023 06:37
@github-actions github-actions bot added this to the 7.9.0 milestone Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HPOS: WP_Screen is not consistent between post table views and order table views

3 participants