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
  • Loading branch information
darssen authored Aug 26, 2024
1 parent cbe7799 commit 549db1f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Sync: Ensure filtering orders by status when doing HPOS Checksums
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

0 comments on commit 549db1f

Please sign in to comment.