PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.14
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.14
1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 1.3.52 1.3.51 1.3.50 1.3.49 1.3.48 1.3.47 1.3.46 1.3.45 All 177 releases
disco / app / Analytics / Controllers / IntentPerformanceController.php

IntentPerformanceController.php in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.14, at app/Analytics/Controllers/IntentPerformanceController.php

55 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php //phpcs:ignore
2
3 /**
4 * IntentPerformanceController — assembles the /analytics/intents-performance response.
5 *
6 * @package Disco
7 * @subpackage Disco\App\Analytics\Controllers
8 * @since 1.3.23
9 */
10
11 namespace Disco\App\Analytics\Controllers;
12
13 use Disco\App\Analytics\Queries\IntentQuery;
14
15 /**
16 * Returns intent-wise sales for the current period only (no comparison).
17 *
18 * Reuses IntentQuery; keeps data flat: intent, sales, orders, percentage.
19 */
20 class IntentPerformanceController extends BaseController {
21
22 /**
23 * Returns intent performance data for the given request args.
24 *
25 * @param array $args Request args with date_from and date_to as Y-m-d strings (optional).
26 */
27 public static function get_intent_performance( array $args ): array {
28 $current = self::resolve_current_period( $args );
29 $compare = self::resolve_compare_period( $current );
30
31 $rows = ( new IntentQuery )->get_intent_sales( $current );
32 $total = array_sum( array_column( $rows, 'revenue' ) );
33
34 $data = array_map(
35 function ( $row ) use ( $total ) {
36 return array(
37 'intent' => $row['intent'],
38 'revenue' => $row['revenue'],
39 'orders' => $row['orders'],
40 'percentage' => $total > 0 ? round( $row['revenue'] / $total * 100, 2 ) : 0,
41 );
42 },
43 $rows
44 );
45
46 return array(
47 'current_period' => array( 'from' => $current['from'], 'to' => $current['to'] ),
48 'compare_period' => array( 'from' => $compare['from'], 'to' => $compare['to'] ),
49 'total_revenue' => round( $total, 2 ),
50 'data' => $data,
51 );
52 }
53
54 }
55