Skip to content

Commit

Permalink
Sync: Ensure filtering orders by status when doing HPOS Checksums (#3…
Browse files Browse the repository at this point in the history
…9020)

* Make sure we filter by status when doing HPOS checksums

* Changelog

* Version bump

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/10557681423

Upstream-Ref: Automattic/jetpack@549db1f
  • Loading branch information
darssen authored and matticbot committed Aug 26, 2024
1 parent 11af6ce commit 912f5e4
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 94 deletions.
58 changes: 29 additions & 29 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions vendor/automattic/jetpack-sync/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ This is an alpha version! The changes listed here are not final.
### Changed
- Sync: Updated allowed order types in HPOS Module

### Fixed
- Sync: Ensure filtering orders by status when doing HPOS Checksums

## [3.7.1] - 2024-08-23
### Changed
- Updated package dependencies. [#39004]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function get_objects_by_id( $object_type, $ids ) {
array(
'post__in' => $ids,
'type' => self::get_order_types_to_sync( true ),
'post_status' => $this->get_all_possible_order_status_keys(),
'post_status' => self::get_all_possible_order_status_keys(),
'limit' => -1,
)
);
Expand Down Expand Up @@ -301,7 +301,7 @@ private function filter_order_data( $order_object ) {
if ( '' === $filtered_order_data['status'] ) {
$filtered_order_data['status'] = 'pending';
}
$filtered_order_data['status'] = $this->get_wc_order_status_with_prefix( $filtered_order_data['status'] );
$filtered_order_data['status'] = self::get_wc_order_status_with_prefix( $filtered_order_data['status'] );

/**
* Filter the order data before syncing.
Expand All @@ -317,13 +317,13 @@ private function filter_order_data( $order_object ) {
/**
* Returns all possible order status keys, including 'auto-draft' and 'trash'.
*
* @access protected
* @access public
*
* @return array An array of all possible status keys, including 'auto-draft' and 'trash'.
*/
protected function get_all_possible_order_status_keys() {
public static function get_all_possible_order_status_keys() {
$order_statuses = array( 'auto-draft', 'trash' );
$wc_order_statuses = $this->wc_get_order_status_keys();
$wc_order_statuses = self::wc_get_order_status_keys();

return array_unique( array_merge( $wc_order_statuses, $order_statuses ) );
}
Expand All @@ -335,8 +335,8 @@ protected function get_all_possible_order_status_keys() {
*
* @return string The WC order status with the 'wc-' prefix if it's a valid order status, initial $status otherwise.
*/
protected function get_wc_order_status_with_prefix( string $status ) {
return in_array( 'wc-' . $status, $this->wc_get_order_status_keys(), true ) ? 'wc-' . $status : $status;
protected static function get_wc_order_status_with_prefix( string $status ) {
return in_array( 'wc-' . $status, self::wc_get_order_status_keys(), true ) ? 'wc-' . $status : $status;
}

/**
Expand All @@ -346,7 +346,7 @@ protected function get_wc_order_status_with_prefix( string $status ) {
*
* @return array Filtered order metadata.
*/
private function wc_get_order_status_keys() {
private static function wc_get_order_status_keys() {
$wc_order_statuses = array();
if ( function_exists( 'wc_get_order_statuses' ) ) {
$wc_order_statuses = array_keys( wc_get_order_statuses() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,14 @@ protected function get_default_tables() {
'checksum_fields' => array( 'date_updated_gmt', 'total_amount' ),
'checksum_text_fields' => array( 'type', 'status' ),
'filter_values' => array(
'type' => array(
'type' => array(
'operator' => 'IN',
'values' => WooCommerce_HPOS_Orders::get_order_types_to_sync( true ),
),
'status' => array(
'operator' => 'IN',
'values' => WooCommerce_HPOS_Orders::get_all_possible_order_status_keys(),
),
),
'is_table_enabled_callback' => 'Automattic\Jetpack\Sync\Replicastore\Table_Checksum::enable_woocommerce_hpos_tables',
),
Expand Down
Loading

0 comments on commit 912f5e4

Please sign in to comment.