From e6ae8d61ed1307b8e69d3ceefec23c24bfc0c0d3 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Thu, 23 Jan 2025 13:55:48 -0500 Subject: [PATCH 01/12] Updating to use the next day in the date range at 00:00:00 due to increased precision with MySQL, and less than (vs. the inclusive BETWEEN) to avoid including transactions at 00:00:00 on the next day. --- .../abstract.llms.analytics.widget.php | 24 ++++++++----------- .../class.llms.analytics.widget.sold.php | 6 ++--- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/includes/abstracts/abstract.llms.analytics.widget.php b/includes/abstracts/abstract.llms.analytics.widget.php index 1ae75d33ae..6f0a62cb5b 100644 --- a/includes/abstracts/abstract.llms.analytics.widget.php +++ b/includes/abstracts/abstract.llms.analytics.widget.php @@ -116,21 +116,18 @@ protected function get_posted_dates() { $dates = llms_filter_input_sanitize_string( INPUT_POST, 'dates', array( FILTER_REQUIRE_ARRAY ) ); return $dates ? $dates : ''; - } protected function get_posted_courses() { $courses = llms_filter_input( INPUT_POST, 'courses', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY ); return $courses ? $courses : array(); - } protected function get_posted_memberships() { $memberships = llms_filter_input( INPUT_POST, 'memberships', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY ); return $memberships ? $memberships : array(); - } protected function get_posted_posts() { @@ -140,7 +137,6 @@ protected function get_posted_posts() { protected function get_posted_students() { $students = llms_filter_input( INPUT_POST, 'students', FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY ); return $students ? $students : array(); - } protected function get_prepared_query() { @@ -169,20 +165,26 @@ protected function format_date( $date, $type ) { break; case 'end': - $date .= ' 23:23:59'; + /** + * Return 00:00:00 on the next day after this date, using PHP datetime functions to avoid issues with daylight savings time or leap years. + * + * 23:59:59 is not a safe way to capture the end of day in newer versions of MySQL, if the transaction happened at (say) 23:59:59.999. + */ + $end_date = new DateTime( $date ); + $end_date->modify( '+1 day' ); + + $date = $end_date->format( 'Y-m-d' ) . ' 00:00:00'; break; } return $date; - } protected function is_error() { return ( $this->success ) ? false : true; - } protected function set_order_data_query( $args = array() ) { @@ -235,7 +237,7 @@ protected function set_order_data_query( $args = array() ) { $order_dates = ''; if ( $date_range ) { $dates = $this->get_posted_dates(); - $order_dates = "AND orders.{$date_field} BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME )"; + $order_dates = "AND orders.{$date_field} >= %s AND orders.{$date_field} < %s"; $this->query_vars[] = $this->format_date( $dates['start'], 'start' ); $this->query_vars[] = $this->format_date( $dates['end'], 'end' ); } @@ -291,7 +293,6 @@ protected function set_order_data_query( $args = array() ) { {$wheres_clause} {$order_clause} ;"; - } /** @@ -333,7 +334,6 @@ protected function query() { $this->message = $wpdb->last_error; } - } /** @@ -384,7 +384,6 @@ public function can_be_processed() { $widget_name, $this ); - } /** @@ -409,8 +408,5 @@ public function output() { header( 'Content-Type: application/json' ); echo wp_json_encode( $this ); wp_die(); - } - - } diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php index dcba0cce1c..a971636f9e 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php @@ -114,12 +114,12 @@ public function set_query() { WHERE ( txns.post_status = 'llms-txn-succeeded' ) AND txns.post_type = 'llms_transaction' - AND txns.post_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) + AND txns.post_date >= %s + AND txns.post_date < %s AND sales.meta_key = '_llms_amount' {$txn_meta_where} ORDER BY txns.post_modified ASC ;"; - } /** @@ -136,7 +136,5 @@ protected function format_response() { return llms_price_raw( floatval( is_array( $results ) ? array_sum( wp_list_pluck( $results, 'amount' ) ) : $results ) ); } - } - } From de680e5a7eb74e196e2f2351b32693ea6cb4a6fe Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Thu, 23 Jan 2025 15:38:17 -0500 Subject: [PATCH 02/12] Switching queries to not include the 00:00:00 end date (< vs BETWEEN's <=). --- .../class.llms.analytics.widget.coursecompletions.php | 6 ++---- .../widgets/class.llms.analytics.widget.enrollments.php | 6 ++---- .../class.llms.analytics.widget.lessoncompletions.php | 7 ++----- .../widgets/class.llms.analytics.widget.refunded.php | 6 ++---- .../widgets/class.llms.analytics.widget.registrations.php | 6 ++---- .../widgets/class.llms.analytics.widget.revenue.php | 6 ++---- 6 files changed, 12 insertions(+), 25 deletions(-) diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.coursecompletions.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.coursecompletions.php index 5f1f5814a4..d9864a3e01 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.coursecompletions.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.coursecompletions.php @@ -60,7 +60,8 @@ public function set_query() { upm.meta_key = '_is_complete' AND p.post_type = 'course' AND upm.meta_value = 'yes' - AND upm.updated_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) + AND upm.updated_date >= %s + AND upm.updated_date < %s {$student_ids} {$lesson_ids} ;"; @@ -69,7 +70,6 @@ public function set_query() { $this->format_date( $dates['start'], 'start' ), $this->format_date( $dates['end'], 'end' ), ); - } protected function format_response() { @@ -79,7 +79,5 @@ protected function format_response() { return count( $this->get_results() ); } - } - } diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.enrollments.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.enrollments.php index 4ce06edbbc..e7e5a1848b 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.enrollments.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.enrollments.php @@ -59,7 +59,8 @@ public function set_query() { WHERE meta_key = '_status' AND ( meta_value = 'Enrolled' OR meta_value = 'enrolled' ) - AND updated_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) + AND updated_date >= %s + AND updated_date < %s {$student_ids} {$product_ids} ;"; @@ -68,7 +69,6 @@ public function set_query() { $this->format_date( $dates['start'], 'start' ), $this->format_date( $dates['end'], 'end' ), ); - } protected function format_response() { @@ -78,7 +78,5 @@ protected function format_response() { return count( $this->get_results() ); } - } - } diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.lessoncompletions.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.lessoncompletions.php index 3bb0f4e275..baf4ec2e9f 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.lessoncompletions.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.lessoncompletions.php @@ -58,7 +58,6 @@ private function get_lesson_ids( $products ) { } return $lessons; - } public function set_query() { @@ -90,7 +89,8 @@ public function set_query() { upm.meta_key = '_is_complete' AND p.post_type = 'lesson' AND upm.meta_value = 'yes' - AND upm.updated_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) + AND upm.updated_date >= %s + AND upm.updated_date < %s {$student_ids} {$lesson_ids} ;"; @@ -99,7 +99,6 @@ public function set_query() { $this->format_date( $dates['start'], 'start' ), $this->format_date( $dates['end'], 'end' ), ); - } protected function format_response() { @@ -109,7 +108,5 @@ protected function format_response() { return count( $this->get_results() ); } - } - } diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.refunded.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.refunded.php index 7d25407072..f0c9fa65da 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.refunded.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.refunded.php @@ -95,12 +95,12 @@ public function set_query() { WHERE ( txns.post_status = 'llms-txn-succeeded' OR txns.post_status = 'llms-txn-refunded' ) AND txns.post_type = 'llms_transaction' - AND txns.post_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) + AND txns.post_date >= %s + AND txns.post_date < %s AND refund.meta_key = '_llms_refund_amount' {$txn_meta_where} ORDER BY txns.post_modified ASC ;"; - } /** @@ -117,7 +117,5 @@ protected function format_response() { return llms_price_raw( floatval( is_array( $results ) ? array_sum( wp_list_pluck( $results, 'amount' ) ) : $results ) ); } - } - } diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.registrations.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.registrations.php index abb3544a49..da69796ab7 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.registrations.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.registrations.php @@ -48,7 +48,8 @@ public function set_query() { $this->query = "SELECT user_registered AS date FROM {$wpdb->users} WHERE - user_registered BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) + user_registered >= %s + AND user_registered < %s {$student_ids} ;"; @@ -56,7 +57,6 @@ public function set_query() { $this->format_date( $dates['start'], 'start' ), $this->format_date( $dates['end'], 'end' ), ); - } protected function format_response() { @@ -66,7 +66,5 @@ protected function format_response() { return count( $this->get_results() ); } - } - } diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.revenue.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.revenue.php index 273c7fa95d..529810d559 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.revenue.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.revenue.php @@ -91,10 +91,10 @@ public function set_query() { WHERE ( txns.post_status = 'llms-txn-succeeded' OR txns.post_status = 'llms-txn-refunded' ) AND txns.post_type = 'llms_transaction' - AND txns.post_date BETWEEN CAST( %s AS DATETIME ) AND CAST( %s AS DATETIME ) + AND txns.post_date >= %s + AND txns.post_date < %s {$txn_meta_where} ;"; - } protected function format_response() { @@ -104,7 +104,5 @@ protected function format_response() { return llms_price_raw( floatval( $this->get_results() ) ); } - } - } From b42c19e890c71ee93c68f39f597a8a3a6f52f05d Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Fri, 24 Jan 2025 10:32:01 -0500 Subject: [PATCH 03/12] Changelog. --- .changelogs/fix_date-range-widget.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changelogs/fix_date-range-widget.yml diff --git a/.changelogs/fix_date-range-widget.yml b/.changelogs/fix_date-range-widget.yml new file mode 100644 index 0000000000..0f9a0e9f6e --- /dev/null +++ b/.changelogs/fix_date-range-widget.yml @@ -0,0 +1,6 @@ +significance: minor +type: fixed +links: + - "#2858" +entry: Fixes sales reporting for transactions or orders that happened between + 23:23:59 and midnight. From 700b248ac227dafca8504515463894685a42fb33 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Fri, 24 Jan 2025 10:35:44 -0500 Subject: [PATCH 04/12] Include transactions in net sales regardless of the transaction's order status. Changelog. --- .changelogs/fix_date-range-widget-1.yml | 7 +++++++ .../reporting/widgets/class.llms.analytics.widget.sold.php | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 .changelogs/fix_date-range-widget-1.yml diff --git a/.changelogs/fix_date-range-widget-1.yml b/.changelogs/fix_date-range-widget-1.yml new file mode 100644 index 0000000000..8405ad36e9 --- /dev/null +++ b/.changelogs/fix_date-range-widget-1.yml @@ -0,0 +1,7 @@ +significance: patch +type: fixed +links: + - "#2860" + - "#2861" +entry: Sales reporting includes partially refunded transactions, and + transactions from orders regardless of status. diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php index a971636f9e..92e5655696 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php @@ -69,11 +69,6 @@ public function set_query() { 'select' => array( 'orders.ID', ), - 'statuses' => array( - 'llms-active', - 'llms-completed', - 'llms-refunded', - ), ) ); $this->query(); @@ -112,7 +107,7 @@ public function set_query() { {$txn_meta_join} JOIN {$wpdb->postmeta} AS sales ON sales.post_id = txns.ID WHERE - ( txns.post_status = 'llms-txn-succeeded' ) + ( txns.post_status = 'llms-txn-succeeded' OR txns.post_status = 'llms-txn-refunded' ) AND txns.post_type = 'llms_transaction' AND txns.post_date >= %s AND txns.post_date < %s From 9fa3ed9afed03712292f8a85d89ab237850fed71 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Fri, 24 Jan 2025 10:47:10 -0500 Subject: [PATCH 05/12] Include more statuses in the "# of sales" widget. --- .changelogs/fix_date-range-widget-2.yml | 6 ++++++ .../widgets/class.llms.analytics.widget.sales.php | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changelogs/fix_date-range-widget-2.yml diff --git a/.changelogs/fix_date-range-widget-2.yml b/.changelogs/fix_date-range-widget-2.yml new file mode 100644 index 0000000000..fe0d7daba7 --- /dev/null +++ b/.changelogs/fix_date-range-widget-2.yml @@ -0,0 +1,6 @@ +significance: patch +type: fixed +links: + - "#2860" +entry: On-hold, pending cancellation, cancelled and expired orders now included + in "# of Sales" widget. diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.sales.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.sales.php index 7299a63c75..78752ed303 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.sales.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.sales.php @@ -46,10 +46,13 @@ public function set_query() { 'statuses' => array( 'llms-active', 'llms-completed', + 'llms-on-hold', + 'llms-pending-cancel', + 'llms-cancelled', + 'llms-expired', ), ) ); - } protected function format_response() { @@ -59,7 +62,5 @@ protected function format_response() { return count( $this->get_results() ); } - } - } From 462959bc6c009fb76baffa44c39d21e67dfee9db Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Fri, 24 Jan 2025 11:36:02 -0500 Subject: [PATCH 06/12] Adding new transactions widget. Likely want to exclude fully refunded transactions. --- .../class.llms.admin.reporting.tab.sales.php | 23 ++-- ...ass.llms.analytics.widget.transactions.php | 120 ++++++++++++++++++ 2 files changed, 129 insertions(+), 14 deletions(-) create mode 100644 includes/admin/reporting/widgets/class.llms.analytics.widget.transactions.php diff --git a/includes/admin/reporting/tabs/class.llms.admin.reporting.tab.sales.php b/includes/admin/reporting/tabs/class.llms.admin.reporting.tab.sales.php index ed463c0648..6cac146319 100644 --- a/includes/admin/reporting/tabs/class.llms.admin.reporting.tab.sales.php +++ b/includes/admin/reporting/tabs/class.llms.admin.reporting.tab.sales.php @@ -27,7 +27,6 @@ public function __construct() { add_action( 'llms_reporting_after_nav', array( $this, 'output_filters' ), 10, 1 ); add_action( 'llms_reporting_content_sales', array( $this, 'output' ) ); - } public static function get_filter_data() { @@ -49,7 +48,6 @@ public static function get_filter_data() { $data['date_end'] = $data['dates']['end']; return $data; - } /** @@ -68,7 +66,7 @@ public function get_widget_data() { 'title' => __( '# of Sales', 'lifterlms' ), 'cols' => '1-4', 'content' => __( 'loading...', 'lifterlms' ), - 'info' => __( 'Number of new active or completed orders placed within this period', 'lifterlms' ), + 'info' => __( 'Number of new non-refunded orders placed within this period', 'lifterlms' ), ), 'sold' => array( 'title' => __( 'Net Sales', 'lifterlms' ), @@ -90,24 +88,24 @@ public function get_widget_data() { ), ), array( - // 'revenue' => array( - // 'title' => __( 'Grosse Revenue', 'lifterlms' ), - // 'cols' => '1-4', - // 'content' => __( 'loading...', 'lifterlms' ), - // 'info' => __( 'Total of all transactions minus all refunds processed during this period', 'lifterlms' ), - // ), - 'coupons' => array( + 'coupons' => array( 'title' => __( '# of Coupons Used', 'lifterlms' ), 'cols' => '1-4', 'content' => __( 'loading...', 'lifterlms' ), 'info' => __( 'Number of orders completed using coupons during this period', 'lifterlms' ), ), - 'discounts' => array( + 'discounts' => array( 'title' => __( 'Amount of Coupons', 'lifterlms' ), 'cols' => '1-4', 'content' => __( 'loading...', 'lifterlms' ), 'info' => __( 'Total amount of coupons used during this period', 'lifterlms' ), ), + 'transactions' => array( + 'title' => __( '# of Transactions', 'lifterlms' ), + 'cols' => '1-4', + 'content' => __( 'loading...', 'lifterlms' ), + 'info' => __( 'Number of transactions within this period', 'lifterlms' ), + ), ), ) ); @@ -129,7 +127,6 @@ public function output() { 'widget_data' => $this->get_widget_data(), ) ); - } /** @@ -146,8 +143,6 @@ public function output_filters( $tab ) { llms_get_template( 'admin/reporting/nav-filters.php', self::get_filter_data() ); } - } - } return new LLMS_Admin_Reporting_Tab_Sales(); diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.transactions.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.transactions.php new file mode 100644 index 0000000000..8061aa17b5 --- /dev/null +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.transactions.php @@ -0,0 +1,120 @@ + 'count', + 'header' => array( + 'id' => 'sold', + 'label' => __( '# of Transactions', 'lifterlms' ), + 'type' => 'number', + ), + ); + } + + public function set_query() { + + global $wpdb; + + $txn_meta_join = ''; + $txn_meta_where = ''; + // Create an "IN" clause that can be used for later in WHERE clauses. + if ( $this->get_posted_students() || $this->get_posted_posts() ) { + + // Get an array of order based on posted students & products. + $this->set_order_data_query( + array( + 'date_range' => false, + 'query_function' => 'get_col', + 'select' => array( + 'orders.ID', + ), + ) + ); + $this->query(); + $order_ids = $this->get_results(); + + $this->temp_q = $wpdb->last_query; + $this->temp = $order_ids; + + if ( $order_ids ) { + $txn_meta_join = "JOIN {$wpdb->postmeta} AS txn_meta ON txn_meta.post_id = txns.ID"; + $txn_meta_where .= " AND txn_meta.meta_key = '_llms_order_id'"; + $txn_meta_where .= ' AND txn_meta.meta_value IN ( ' . implode( ', ', $order_ids ) . ' )'; + } else { + + $this->query_function = 'get_var'; + $this->query = 'SELECT 0'; + return; + + } + } + + // Date range will be used to get transactions between given dates. + $dates = $this->get_posted_dates(); + $this->query_vars = array( + $this->format_date( $dates['start'], 'start' ), + $this->format_date( $dates['end'], 'end' ), + ); + + $this->query_function = 'get_results'; + $this->output_type = OBJECT; + + // TODO: Exclude transactions fully refunded? + $this->query = "SELECT + txns.id + FROM {$wpdb->posts} AS txns + {$txn_meta_join} + WHERE + ( txns.post_status = 'llms-txn-succeeded' OR txns.post_status = 'llms-txn-refunded' ) + AND txns.post_type = 'llms_transaction' + AND txns.post_date >= %s + AND txns.post_date < %s + {$txn_meta_where} + ORDER BY txns.post_modified ASC + ;"; + } + + protected function format_response() { + + if ( ! $this->is_error() ) { + + return count( $this->get_results() ); + + } + } +} From 99d10ddd38d9e0432131f52e3243cd46816a6129 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Fri, 24 Jan 2025 11:37:23 -0500 Subject: [PATCH 07/12] Modifying "Net Sales" to subtract refunded amounts from the total. --- .../class.llms.analytics.widget.sold.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php b/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php index 92e5655696..f6663ce82d 100644 --- a/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php +++ b/includes/admin/reporting/widgets/class.llms.analytics.widget.sold.php @@ -97,21 +97,31 @@ public function set_query() { $this->format_date( $dates['end'], 'end' ), ); - $this->query_function = 'get_results'; + $this->query_function = 'get_var'; $this->output_type = OBJECT; - $this->query = "SELECT - txns.post_modified AS date - , sales.meta_value AS amount + $this->query = "SELECT ( + IFNULL( SUM( ( + SELECT price.meta_value + FROM {$wpdb->postmeta} AS price + WHERE + price.meta_key = '_llms_amount' + AND price.post_id IN( txns.ID ) + ) ), 0 ) - IFNULL( SUM(( + SELECT refund.meta_value + FROM {$wpdb->postmeta} AS refund + WHERE + refund.meta_key = '_llms_refund_amount' + AND refund.post_id IN( txns.ID ) + ) ), 0 ) + ) AS sales FROM {$wpdb->posts} AS txns {$txn_meta_join} - JOIN {$wpdb->postmeta} AS sales ON sales.post_id = txns.ID WHERE ( txns.post_status = 'llms-txn-succeeded' OR txns.post_status = 'llms-txn-refunded' ) AND txns.post_type = 'llms_transaction' AND txns.post_date >= %s AND txns.post_date < %s - AND sales.meta_key = '_llms_amount' {$txn_meta_where} ORDER BY txns.post_modified ASC ;"; @@ -122,13 +132,13 @@ public function set_query() { * * @since unknown * @since 3.36.3 Avoid running `wp_list_pluck()` on non arrays. + * @since [version] Using aggregate sum of net sales rather than summing up the txn records. */ protected function format_response() { if ( ! $this->is_error() ) { - $results = $this->get_results(); - return llms_price_raw( floatval( is_array( $results ) ? array_sum( wp_list_pluck( $results, 'amount' ) ) : $results ) ); + return llms_price_raw( floatval( $this->get_results() ) ); } } From 5c1493e963408a43759cf2ff3e2282114162d85f Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Fri, 24 Jan 2025 11:38:33 -0500 Subject: [PATCH 08/12] Changelog. --- .changelogs/fix_date-range-widget-3.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelogs/fix_date-range-widget-3.yml diff --git a/.changelogs/fix_date-range-widget-3.yml b/.changelogs/fix_date-range-widget-3.yml new file mode 100644 index 0000000000..5e1323a287 --- /dev/null +++ b/.changelogs/fix_date-range-widget-3.yml @@ -0,0 +1,3 @@ +significance: patch +type: added +entry: New "# of transactions" sales reporting widget. From c4476045babaa3ee307977d61e0193e2cfb4ca13 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Fri, 24 Jan 2025 11:47:19 -0500 Subject: [PATCH 09/12] Changelog. --- .changelogs/fix_date-range-widget-1.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelogs/fix_date-range-widget-1.yml b/.changelogs/fix_date-range-widget-1.yml index 8405ad36e9..637353d251 100644 --- a/.changelogs/fix_date-range-widget-1.yml +++ b/.changelogs/fix_date-range-widget-1.yml @@ -3,5 +3,5 @@ type: fixed links: - "#2860" - "#2861" -entry: Sales reporting includes partially refunded transactions, and +entry: Net Sales reporting includes partially refunded transactions, and transactions from orders regardless of status. From 9839c1da60bde0954dac3264b0100712a11a30a3 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Mon, 27 Jan 2025 14:32:35 -0500 Subject: [PATCH 10/12] Debugging. --- tests/e2e/tests/page-restrictions/course.test.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/e2e/tests/page-restrictions/course.test.js b/tests/e2e/tests/page-restrictions/course.test.js index b62823d90d..677a173421 100644 --- a/tests/e2e/tests/page-restrictions/course.test.js +++ b/tests/e2e/tests/page-restrictions/course.test.js @@ -23,6 +23,8 @@ describe( 'CourseRestrictions', () => { await clickAndWait( '.llms-builder-launcher a.llms-button-primary' ); course = await page.evaluate( () => window.llms_builder.course ); + console.log("COURSE OBJECT in BEFOREALL", course); + lessons = course.sections[0].lessons; } ); @@ -36,7 +38,7 @@ describe( 'CourseRestrictions', () => { } ); it ( 'should see enrolled user content on the course page', async () => { - + console.log("COURSE OBJECT", course); await page.goto( course.permalink ); expect( await page.$eval( '.entry-content #enrolled-user-content', el => el.textContent ) ).toBe( 'Enrolled user content.' ); From 0a1b5a24feb30d64f7ddd61f30aa0f7971f6b9b1 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Mon, 27 Jan 2025 15:32:51 -0500 Subject: [PATCH 11/12] Undoing debugging. Looks like it's flaky but works. --- tests/e2e/tests/page-restrictions/course.test.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/e2e/tests/page-restrictions/course.test.js b/tests/e2e/tests/page-restrictions/course.test.js index 677a173421..0f47c5defa 100644 --- a/tests/e2e/tests/page-restrictions/course.test.js +++ b/tests/e2e/tests/page-restrictions/course.test.js @@ -23,7 +23,6 @@ describe( 'CourseRestrictions', () => { await clickAndWait( '.llms-builder-launcher a.llms-button-primary' ); course = await page.evaluate( () => window.llms_builder.course ); - console.log("COURSE OBJECT in BEFOREALL", course); lessons = course.sections[0].lessons; @@ -38,7 +37,7 @@ describe( 'CourseRestrictions', () => { } ); it ( 'should see enrolled user content on the course page', async () => { - console.log("COURSE OBJECT", course); + await page.goto( course.permalink ); expect( await page.$eval( '.entry-content #enrolled-user-content', el => el.textContent ) ).toBe( 'Enrolled user content.' ); From 357223846d55eaf7b043177568fbd20bf143e9c0 Mon Sep 17 00:00:00 2001 From: Brian Hogg Date: Mon, 27 Jan 2025 15:33:15 -0500 Subject: [PATCH 12/12] Removing space. --- tests/e2e/tests/page-restrictions/course.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/tests/page-restrictions/course.test.js b/tests/e2e/tests/page-restrictions/course.test.js index 0f47c5defa..b62823d90d 100644 --- a/tests/e2e/tests/page-restrictions/course.test.js +++ b/tests/e2e/tests/page-restrictions/course.test.js @@ -23,7 +23,6 @@ describe( 'CourseRestrictions', () => { await clickAndWait( '.llms-builder-launcher a.llms-button-primary' ); course = await page.evaluate( () => window.llms_builder.course ); - lessons = course.sections[0].lessons; } );