woocommerce/plugins/woocommerce-admin/src/Features/Analytics.php

166 lines
4.6 KiB
PHP
Raw Normal View History

<?php
/**
* WooCommerce Analytics.
* NOTE: DO NOT edit this file in WooCommerce core, this is generated from woocommerce-admin.
*
* @package Woocommerce Admin
*/
2019-08-01 18:17:08 +00:00
namespace Automattic\WooCommerce\Admin\Features;
/**
* Contains backend logic for the Analytics feature.
*/
class Analytics {
/**
* Class instance.
*
* @var Analytics instance
*/
protected static $instance = null;
/**
* Get class instance.
*/
public static function get_instance() {
if ( ! self::$instance ) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Hook into WooCommerce.
*/
public function __construct() {
add_filter( 'woocommerce_component_settings_preload_endpoints', array( $this, 'add_preload_endpoints' ) );
add_filter( 'woocommerce_admin_get_user_data_fields', array( $this, 'add_user_data_fields' ) );
add_action( 'admin_menu', array( $this, 'register_pages' ) );
}
/**
* Preload data from the countries endpoint.
*
* @param array $endpoints Array of preloaded endpoints.
* @return array
*/
public function add_preload_endpoints( $endpoints ) {
$endpoints['countries'] = '/wc-analytics/data/countries';
return $endpoints;
}
/**
* Adds fields so that we can store user preferences for the columns to display on a report.
*
* @param array $user_data_fields User data fields.
* @return array
*/
public function add_user_data_fields( $user_data_fields ) {
return array_merge(
$user_data_fields,
array(
'categories_report_columns',
'coupons_report_columns',
'customers_report_columns',
'orders_report_columns',
'products_report_columns',
'revenue_report_columns',
'taxes_report_columns',
'variations_report_columns',
)
);
}
/**
* Registers report pages.
*/
public function register_pages() {
$features = wc_admin_get_feature_config();
$report_pages = array(
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics',
'title' => __( 'Analytics', 'woocommerce-admin' ),
'path' => '/analytics/overview',
'path' => $features['homepage'] ? '/analytics/overview' : '/analytics/revenue',
2019-05-07 18:43:18 +00:00
'icon' => 'dashicons-chart-bar',
'position' => 56, // After WooCommerce & Product menu items.
),
$features['homepage'] ? array(
'id' => 'woocommerce-analytics-overview',
'title' => __( 'Overview', 'woocommerce-admin' ),
'parent' => 'woocommerce-analytics',
'path' => '/analytics/overview',
) : null,
2019-05-07 18:43:18 +00:00
array(
'id' => 'woocommerce-analytics-revenue',
'title' => __( 'Revenue', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/revenue',
),
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-orders',
'title' => __( 'Orders', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/orders',
),
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-products',
'title' => __( 'Products', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/products',
),
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-categories',
'title' => __( 'Categories', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/categories',
),
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-coupons',
'title' => __( 'Coupons', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/coupons',
),
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-taxes',
'title' => __( 'Taxes', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/taxes',
),
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-downloads',
'title' => __( 'Downloads', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/downloads',
),
'yes' === get_option( 'woocommerce_manage_stock' ) ? array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-stock',
'title' => __( 'Stock', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/stock',
) : null,
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-customers',
'title' => __( 'Customers', 'woocommerce-admin' ),
Merge Version/1.0 to master (https://github.com/woocommerce/woocommerce-admin/pull/3740) * Try: Moving Customers to main Woo Menu (https://github.com/woocommerce/woocommerce-admin/pull/3632) * Only add onboarding settings on wc-admin pages when task list should be shown. (https://github.com/woocommerce/woocommerce-admin/pull/3722) * Use cron for unsnoozing admin notes (https://github.com/woocommerce/woocommerce-admin/pull/3662) * Use wp-cron for admin note snoozing. * Remove "unsnooze" scheduled action. * Use correct version. * Avoid using deprecated method for unscheduling actions. * Onboarding: Fix toggle tracking events (https://github.com/woocommerce/woocommerce-admin/pull/3645) * Fix errant wcadmin prefix on event name * Track the onboarding toggle on the option in case enable_onboarding isn't used * Move toggle actions to separate function * Move onboarding actions * Move onboarding filters * Move help tab updates to add_toggle_actions * Only run onboarding actions when enabled * Onboarding: Add tracks events when profiler steps are completed (https://github.com/woocommerce/woocommerce-admin/pull/3726) * Add tracks for store profiler step completion * Record event when profiler is completed * Ensure continue setup loads the onboarding profiler (https://github.com/woocommerce/woocommerce-admin/pull/3646) * 'All that include' option removed when input field is empty (https://github.com/woocommerce/woocommerce-admin/pull/3700) * 'All that include' option removed when input field is empty Added a control to check that when the input field 'Search by customer name' is empty, the 'All that include' option is not appearing. * Const name improved The constant name hasValues was changed to optionsHaveValues (more descriptive) * Fix select text alignment (https://github.com/woocommerce/woocommerce-admin/pull/3723) Co-authored-by: Timmy Crawford <timmyc@users.noreply.github.com> Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com> Co-authored-by: Joshua T Flowers <joshuatf@gmail.com> Co-authored-by: Fernando <ultimoround@gmail.com> Co-authored-by: edmundcwm <edmundcwm@gmail.com>
2020-02-20 11:59:02 +00:00
'parent' => 'woocommerce',
'path' => '/customers',
),
array(
2019-05-07 18:43:18 +00:00
'id' => 'woocommerce-analytics-settings',
'title' => __( 'Settings', 'woocommerce-admin' ),
2019-05-07 18:43:18 +00:00
'parent' => 'woocommerce-analytics',
'path' => '/analytics/settings',
),
);
$report_pages = apply_filters( 'woocommerce_analytics_report_menu_items', $report_pages );
foreach ( $report_pages as $report_page ) {
if ( ! is_null( $report_page ) ) {
wc_admin_register_page( $report_page );
}
}
}
}