diff --git a/classes/Visualizer/Module.php b/classes/Visualizer/Module.php index d15d7f2cb..ebee83aed 100644 --- a/classes/Visualizer/Module.php +++ b/classes/Visualizer/Module.php @@ -732,7 +732,7 @@ public static function can_show_feature( $feature ) { public static final function get_features_for_license( $plan ) { switch ( $plan ) { case 1: - return array( 'import-wp', 'db-query' ); + return array( 'import-wp', 'db-query', 'import-wc-report' ); case 2: return array( 'schedule-chart', 'chart-permissions' ); } diff --git a/classes/Visualizer/Module/Chart.php b/classes/Visualizer/Module/Chart.php index 7dc438712..211553d0e 100644 --- a/classes/Visualizer/Module/Chart.php +++ b/classes/Visualizer/Module/Chart.php @@ -135,6 +135,20 @@ public function setJsonSchedule() { ) ); + if ( Visualizer_Module::is_pro() ) { + $is_woocommerce_report = filter_input( + INPUT_POST, + 'is_woocommerce_report', + FILTER_VALIDATE_BOOLEAN + ); + + if ( $is_woocommerce_report ) { + update_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ); + } else { + delete_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE ); + } + } + delete_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE ); if ( -1 < $time ) { @@ -246,6 +260,14 @@ public function setJsonData() { add_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_PAGING, $params['paging'] ); } + if ( Visualizer_Module::is_pro() ) { + if ( ! empty( $params['vz_woo_source'] ) ) { + update_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE, $params['vz_woo_source'] ); + } else { + delete_post_meta( $chart->ID, Visualizer_Plugin::CF_JSON_WOOCOMMERCE_SOURCE ); + } + } + $time = filter_input( INPUT_POST, 'time', @@ -832,6 +854,7 @@ private function _handleDataAndSettingsPage() { 'json_tag_separator' => Visualizer_Source_Json::TAG_SEPARATOR, 'json_tag_separator_view' => Visualizer_Source_Json::TAG_SEPARATOR_VIEW, 'is_front' => false, + 'rest_base' => get_rest_url( null, 'wc/v3/reports/' ), ) ); diff --git a/classes/Visualizer/Module/Frontend.php b/classes/Visualizer/Module/Frontend.php index 27a21050c..0a1f42d42 100644 --- a/classes/Visualizer/Module/Frontend.php +++ b/classes/Visualizer/Module/Frontend.php @@ -319,6 +319,10 @@ public function renderChart( $atts ) { return ''; } + if ( ! is_admin() && ! empty( $chart_data['is_woocommerce_report'] ) ) { + return ''; + } + // in case revisions exist. // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.Found if ( true === ( $revisions = $this->undoRevisions( $chart->ID, true ) ) ) { @@ -639,8 +643,9 @@ private function getChartData( $cache_key = '', $chart_id = 0 ) { // Get chart by ID. $chart = get_post( $chart_id ); if ( $chart && Visualizer_Plugin::CPT_VISUALIZER === $chart->post_type ) { - $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); - $series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ); + $settings = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SETTINGS, true ); + $series = get_post_meta( $chart->ID, Visualizer_Plugin::CF_SERIES, true ); + $is_woocommerce_report = get_post_meta( $chart->ID, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ); if ( isset( $settings['series'] ) && ! ( count( $settings['series'] ) - count( $series ) > 1 ) ) { $diff_total_series = abs( count( $settings['series'] ) - count( $series ) ); @@ -651,11 +656,12 @@ private function getChartData( $cache_key = '', $chart_id = 0 ) { } } $chart_data = array( - 'chart' => $chart, - 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ), - 'settings' => $settings, - 'series' => $series, - 'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ), + 'chart' => $chart, + 'type' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_TYPE, true ), + 'settings' => $settings, + 'series' => $series, + 'chart_image' => get_post_meta( $chart->ID, Visualizer_Plugin::CF_CHART_IMAGE, true ), + 'is_woocommerce_report' => $is_woocommerce_report, ); // Put the results in a transient. Expire after 12 hours. diff --git a/classes/Visualizer/Plugin.php b/classes/Visualizer/Plugin.php index ecdc7a087..43352864f 100644 --- a/classes/Visualizer/Plugin.php +++ b/classes/Visualizer/Plugin.php @@ -102,6 +102,8 @@ class Visualizer_Plugin { const PRO_TEASER_TITLE = 'Check PRO version '; const CF_CHART_CACHE = 'visualizer-chart-cache'; + const CF_JSON_WOOCOMMERCE_SOURCE = 'visualizer-woocommerce-source'; + const CF_IS_WOOCOMMERCE_SOURCE = 'visualizer-is-woocommerce-source'; /** * Name of the option for WordPress DB. diff --git a/classes/Visualizer/Render/Layout.php b/classes/Visualizer/Render/Layout.php index 8258f8d10..8affd1ef9 100644 --- a/classes/Visualizer/Render/Layout.php +++ b/classes/Visualizer/Render/Layout.php @@ -139,6 +139,7 @@ public static function _renderJsonScreen( $args ) { ) ); + $is_wc_source = get_post_meta( $id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ); $url = get_post_meta( $id, Visualizer_Plugin::CF_JSON_URL, true ); $root = get_post_meta( $id, Visualizer_Plugin::CF_JSON_ROOT, true ); $paging = get_post_meta( $id, Visualizer_Plugin::CF_JSON_PAGING, true ); @@ -171,9 +172,11 @@ public static function _renderJsonScreen( $args ) { name="url" value="" placeholder="" - class="visualizer-input json-form-element"> + class="visualizer-input json-form-element" + + > - +

@@ -670,7 +673,12 @@ public static function _renderTabBasic( $args ) { ); // this will allow us to open the correct source tab by default. - $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); + $source_of_chart = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ) ); + // Import from woocommerce report. + $is_woocommerce_source = strtolower( get_post_meta( $chart_id, Visualizer_Plugin::CF_IS_WOOCOMMERCE_SOURCE, true ) ); + if ( ! empty( $is_woocommerce_source ) ) { + $source_of_chart .= '_wc'; + } // both import from wp and import from db have the same source so we need to differentiate. $filter_config = get_post_meta( $chart_id, Visualizer_Plugin::CF_FILTER_CONFIG, true ); // if filter config is present, then its import from wp. @@ -920,6 +928,104 @@ class="dashicons dashicons-lock">
+ + esc_html__( 'Sales', 'visualizer' ), + 'endpoint' => esc_attr( 'sales' ), + ), + array( + 'name' => esc_html__( 'Top Sellers', 'visualizer' ), + 'endpoint' => esc_attr( 'top_sellers' ), + ), + array( + 'name' => esc_html__( 'Coupons Totals', 'visualizer' ), + 'endpoint' => esc_attr( 'coupons/totals' ), + ), + array( + 'name' => esc_html__( 'Customers Totals', 'visualizer' ), + 'endpoint' => esc_attr( 'customers/totals' ), + ), + array( + 'name' => esc_html__( 'Orders Totals', 'visualizer' ), + 'endpoint' => esc_attr( 'orders/totals' ), + ), + array( + 'name' => esc_html__( 'Products Totals', 'visualizer' ), + 'endpoint' => esc_attr( 'products/totals' ), + ), + array( + 'name' => esc_html__( 'Reviews Totals', 'visualizer' ), + 'endpoint' => esc_attr( 'reviews/totals' ), + ), + ) + ); + ?> +
  • +

    +
    +
    +

    this tutorial', 'visualizer' ); ?>

    +
    +
    + +

    + +

    + +
    + + + > + > +
    + +
    +
    +
  • + '); }); @@ -520,17 +535,19 @@ }); // update the schedule - $('#json-chart-save-button').on('click', function(e){ + $('#json-chart-save-button, #woo-chart-save-button').on('click', function(e){ e.preventDefault(); $('#canvas').lock(); + var btnID = jQuery( this ).attr( 'id' ); $.ajax({ url : ajaxurl, method : 'post', data : { 'action' : visualizer.ajax['actions']['json_set_schedule'], 'security' : visualizer.ajax['nonces']['json_set_schedule'], - 'chart' : $('#vz-json-time').attr('data-chart'), - 'time' : $('#vz-json-time').val() + 'chart' : $('#vz-json-time, #vz-woo-time').attr('data-chart'), + 'time' : $('#vz-json-time, #vz-woo-time').val(), + 'is_woocommerce_report': 'woo-chart-save-button' === btnID, }, success : function(data){ // do nothing. @@ -541,6 +558,18 @@ }); }); + // Select WooCommerce report endpoint. + $( '#vz-woo-source' ).on( 'click', function( e ) { + // Trigger change action. + $( 'body' ).trigger( 'visualizer:change:action' ); + + if ( '' !== $( this ).val() ) { + $( '#woo-chart-button, #woo-chart-save-button' ).removeAttr( 'disabled' ); + } else { + $( '#woo-chart-button, #woo-chart-save-button' ).attr( 'disabled', true ); + } + } ); + } function init_editor_table() {