From eff341d832cd02c82eecef8d61153aefce4f36b7 Mon Sep 17 00:00:00 2001 From: Peter Fabian Date: Wed, 23 Jan 2019 16:58:03 +0100 Subject: [PATCH] Made the interval sorting stable (second level sort by time_interval). This is required so that intervals are sorted in the same way each time when going through pages of results. --- .../data-stores/class-wc-admin-reports-data-store.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php index ef1fef5cc43..73eb9d693c6 100644 --- a/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php +++ b/plugins/woocommerce-admin/includes/data-stores/class-wc-admin-reports-data-store.php @@ -76,7 +76,15 @@ class WC_Admin_Reports_Data_Store { // TODO: should return WP_Error here perhaps? } if ( $a[ $this->order_by ] === $b[ $this->order_by ] ) { - return 0; + // As relative order is undefined in case of equality in usort, second-level sorting by date needs to be enforced + // so that paging is stable. + if ( $a['time_interval'] === $b['time_interval'] ) { + return 0; // This should never happen. + } elseif ( $a['time_interval'] > $b['time_interval'] ) { + return 1; + } elseif ( $a['time_interval'] < $b['time_interval'] ) { + return -1; + } } elseif ( $a[ $this->order_by ] > $b[ $this->order_by ] ) { return strtolower( $this->order ) === 'desc' ? -1 : 1; } elseif ( $a[ $this->order_by ] < $b[ $this->order_by ] ) {