Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: Update vendor analytics report UI. #2405

Open
wants to merge 16 commits into
base: enhancement/analytics-reports-vendor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
5e8fd2a
fix: analytics report ui stuff & add data store cache modifier.
MdAsifHossainNadim Oct 17, 2024
2ea5b01
enhance: transfer analytics menu from dashboard to reports menu.
MdAsifHossainNadim Oct 18, 2024
3170b1e
Pass seller_id as query param in overview
mrabbani Oct 18, 2024
a9e6989
fix: caching issue for vendor and admin data rendering inconsistencie…
MdAsifHossainNadim Oct 18, 2024
fdd8e50
Merge remote-tracking branch 'origin/enhance/update-vendor-analytics-…
MdAsifHossainNadim Oct 18, 2024
b2bd7cc
Merge branch 'refs/heads/enhancement/analytics-reports-vendor' into e…
MdAsifHossainNadim Oct 30, 2024
00834f5
fix: dashboard reports rendering issue & update method name seller to…
MdAsifHossainNadim Oct 30, 2024
65e4667
enhance: add vendor earning in dashboard analytics.
MdAsifHossainNadim Oct 30, 2024
4ae956e
enhance: update vendor & admin context for report title.
MdAsifHossainNadim Oct 30, 2024
ceced67
enhance: hide chart downloads for fix vendor reports filtering issue.
MdAsifHossainNadim Oct 31, 2024
6e32526
enhance: update & sync with separate branch.
MdAsifHossainNadim Nov 7, 2024
0a7e599
enhance: remove reports submenu from free version.
MdAsifHossainNadim Nov 7, 2024
41e8898
enhance: update is analytics available method.
MdAsifHossainNadim Nov 7, 2024
e14fa95
remove: repeated method from dashboard page.
MdAsifHossainNadim Nov 7, 2024
0cd416b
remove: repeated method from dashboard page.
MdAsifHossainNadim Nov 7, 2024
6ebc4fc
Merge remote-tracking branch 'origin/enhance/update-vendor-analytics-…
MdAsifHossainNadim Nov 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed assets/js/dokan-maps-compat.js
Empty file.
2 changes: 1 addition & 1 deletion assets/js/vue-admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/vue-bootstrap.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions assets/src/js/dokan-admin-analytics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// TODO: Remove this file after introducing Dokan coupon distribution.
// TODO: Before removing the download chart hide filter, we need to remove the dashboard chart filter.
// Refer to `dokan/src/vendor-dashboard/reports/dashboard/dashboard-charts/config.js` for hide dashboard chart script.
wp.hooks.addFilter(
'woocommerce_admin_revenue_report_charts',
'dokan/remove-woocommerce-revenue-coupon-data-from/callback',
( data ) => data.filter( item => item.key !== 'coupons' )
'woocommerce_admin_dashboard_charts_filter',
'dokan/hide-woocommerce-downloads-chart/callback',
( charts ) => charts.filter( chart => chart.endpoint !== 'downloads' && chart.key !== 'download_count' )
);
26 changes: 18 additions & 8 deletions includes/Analytics/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@

class Assets implements Hookable {
public function register_hooks(): void {
if ( ! dokan_is_analytics_enabled() ) {
return;
}

add_action( 'wp_enqueue_scripts', [ $this, 'register_all_scripts' ], 8 );

if ( ! is_admin() ) {
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_front_scripts' ] );
}
if ( ! is_admin() ) {
add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_front_scripts' ] );
}

add_filter( 'woocommerce_admin_shared_settings', [ $this, 'localize_wc_admin_settings' ] );

( new VendorDashboardManager() )->register_hooks();
( new Reports\DataStoreCacheModifier() )->register_hooks();
}

/**
Expand All @@ -24,10 +30,14 @@ public function register_hooks(): void {
* @return array
*/
public function localize_wc_admin_settings( $settings ) {
$preload_data_endpoints = apply_filters( 'woocommerce_component_settings_preload_endpoints', array() );
$preload_data = [];
$settings['vendorBalance'] = dokan_get_seller_balance( dokan_get_current_user_id(), 2 );
$settings['stockStatuses'] = wc_get_product_stock_status_options();
$settings['isAnalyticsEnabled'] = dokan_is_analytics_enabled();

$preload_data = [];
$preload_data_endpoints = apply_filters( 'woocommerce_component_settings_preload_endpoints', array() );

if ( ! empty( $preload_data_endpoints ) ) {
if ( ! empty( $preload_data_endpoints ) ) {
// @see https://github.com/woocommerce/woocommerce/blob/f469bba6f28edd8616b5423755c6559912d47a4a/plugins/woocommerce/src/Internal/Admin/Settings.php#L140-L146
$preload_data = array_reduce(
array_values( $preload_data_endpoints ),
Expand Down Expand Up @@ -100,10 +110,10 @@ public function enqueue_front_scripts() {
wp_enqueue_script( 'vendor_analytics_script' );
wp_localize_script(
'vendor_analytics_script', 'vendorAnalyticsDokanConfig', [
'seller_id' => dokan_get_current_user_id(),
'seller_id' => dokan_get_current_user_id(),
'orderListPageUlr' => dokan_get_navigation_url( 'orders' ),
]
);
wp_enqueue_style( 'vendor_analytics_style' );
wp_enqueue_style( 'vendor_analytics_style' );
}
}
46 changes: 46 additions & 0 deletions includes/Analytics/Reports/DataStoreCacheModifier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

namespace WeDevs\Dokan\Analytics\Reports;

use WeDevs\Dokan\Analytics\Reports\Orders\QueryFilter;
use WeDevs\Dokan\Contracts\Hookable;

/**
* DataStoreCacheModifier class
*
* @since DOKAN_SINCE
*/
class DataStoreCacheModifier implements Hookable {

/**
* Register hooks for modify vendor specific analytics data.
* This method will be called automatically to register the hooks.
*
* @return void
*/
public function register_hooks(): void {
add_filter( 'woocommerce_analytics_orders_query_args', [ $this, 'add_query_param' ] );
add_filter( 'woocommerce_analytics_orders_stats_query_args', [ $this, 'add_query_param' ] );
add_filter( 'woocommerce_analytics_products_stats_query_args', [ $this, 'add_query_param' ] );
add_filter( 'woocommerce_analytics_coupons_stats_query_args', [ $this, 'add_query_param' ] );
add_filter( 'woocommerce_analytics_taxes_stats_query_args', [ $this, 'add_query_param' ] );
add_filter( 'woocommerce_analytics_variations_stats_query_args', [ $this, 'add_query_param' ] );

add_filter( 'woocommerce_analytics_products_query_args', [ $this, 'add_query_param' ] );
add_filter( 'woocommerce_analytics_revenue_stats_query_args', [ $this, 'add_query_param' ] );
add_filter( 'woocommerce_analytics_revenue_query_args', [ $this, 'add_query_param' ] );
add_filter( 'woocommerce_analytics_variations_query_args', [ $this, 'add_query_param' ] );
}

/**
* Add seller_id query param to the analytics query.
*
* @param array $params
*
* @return array
*/
public function add_query_param( array $params ): array {
$params['seller_id'] = dokan()->get_container()->get( QueryFilter::class )->get_vendor_id();
return $params;
}
}
117 changes: 35 additions & 82 deletions includes/Analytics/VendorDashboardManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
class VendorDashboardManager implements Hookable {
public function register_hooks(): void {
add_filter( 'woocommerce_rest_check_permissions', [ $this, 'woocommerce_rest_check_permissions' ], 20, 4 );
add_filter( 'dokan_dashboard_nav_submenu', [ $this, 'add_report_submenu' ], 10, 2 );

// Dummy hook for testing.
add_filter( 'dokan_product_listing_template_render', [ $this, 'control_product_listing_render' ] );
add_action( 'dokan_dashboard_content_inside_before', [ $this, 'add_dashboard_content' ] );

add_filter( 'woocommerce_rest_product_object_query', [ $this, 'product_query_args' ], 10, 2 );
Expand All @@ -21,15 +21,36 @@ public function register_hooks(): void {
add_filter( 'woocommerce_rest_report_sort_performance_indicators', [ $this, 'sort_performance_indicators' ] );
}

// This is dummy function for testing.
/**
* Determine whether to hide the product listing on the analytics report page.
*
* @since DOKAN_SINCE
*
* @param bool $render Whether to render the product listing.
*
* @return bool True to hide product listing on analytics report page, original $render otherwise.
*/
public function control_product_listing_render( bool $render ): bool {
$path = isset( $_GET['path'] ) ? sanitize_text_field( wp_unslash( $_GET['path'] ) ) : ''; // phpcs:ignore

return $path !== '/analytics/products' ? $render : true;
}

/**
* Add a dummy content to the dashboard.
*
* @since DOKAN_SINCE
*
* @return void
*/
public function add_dashboard_content() {
echo '<div id="dokan-analytics-test">hello</div>';
echo '<div id="dokan-analytics-test"></div>';
}

public function woocommerce_rest_check_permissions( $permission, $context, $int_val, $object ) {
if ( ! $permission && in_array( $object, [ 'reports', 'settings' ] ) && $context === 'read' ) {
public function woocommerce_rest_check_permissions( $permission, $context, $int_val, $obj ) {
if ( ! $permission && in_array( $obj, [ 'reports', 'settings' ], true ) && $context === 'read' ) {
$current_user_id = dokan_get_current_user_id();
$permission = dokan_is_user_seller( $current_user_id );
$permission = dokan_is_user_seller( $current_user_id );
}

return $permission;
Expand All @@ -56,80 +77,6 @@ public function product_query_args( array $args, WP_REST_Request $request ) {
return $args;
}

/**
* Adds a new order menu item to the Dokan dashboard navigation.
*
* @param array $submenu_items Existing submenu items.
* @param string $nav_key Navigation key.
*
* @return array Modified submenu items.
* @since DOKAN_PRO_SINCE
*/
public function add_report_submenu( array $submenu_items, string $nav_key ): array {
$parent_menu = 'dashboard';

if ( $parent_menu === $nav_key && dokan_is_seller_enabled( dokan_get_current_user_id() ) ) {
$submenu_items['report_overview'] = [
'title' => __( 'Overview', 'dokan-lite' ),
// 'icon' => '<i class="far fa-credit-card"></i>',
'url' => dokan_get_navigation_url( $parent_menu ) . '?path=%2Fanalytics%2FOverview',
'pos' => 50,
'permission' => 'dokan_view_store_payment_menu',

];
$submenu_items['report_products'] = [
'title' => __( 'Products', 'dokan-lite' ),
// 'icon' => '<i class="far fa-credit-card"></i>',
'url' => dokan_get_navigation_url( $parent_menu ) . '?path=%2Fanalytics%2Fproducts',
'pos' => 50,
'permission' => 'dokan_view_store_payment_menu',

];
$submenu_items['report_revenue'] = [
'title' => __( 'Revenue', 'dokan-lite' ),
// 'icon' => '<i class="far fa-credit-card"></i>',
'url' => dokan_get_navigation_url( $parent_menu ) . '?path=%2Fanalytics%2Frevenue',
'pos' => 50,
'permission' => 'dokan_view_store_payment_menu',

];

$submenu_items['report_orders'] = [
'title' => __( 'Orders', 'dokan-lite' ),
// 'icon' => '<i class="far fa-credit-card"></i>',
'url' => dokan_get_navigation_url( $parent_menu ) . '?path=%2Fanalytics%2Forders',
'pos' => 50,
'permission' => 'dokan_view_store_payment_menu',
];

$submenu_items['report_variations'] = [
'title' => __( 'Variations', 'dokan-lite' ),
// 'icon' => '<i class="far fa-credit-card"></i>',
'url' => dokan_get_navigation_url( $parent_menu ) . '?path=%2Fanalytics%2Fvariations',
'pos' => 50,
'permission' => 'dokan_view_store_payment_menu',
];

$submenu_items['report_categories'] = [
'title' => __( 'Categories', 'dokan-lite' ),
// 'icon' => '<i class="far fa-credit-card"></i>',
'url' => dokan_get_navigation_url( $parent_menu ) . '?path=%2Fanalytics%2Fcategories',
'pos' => 50,
'permission' => 'dokan_view_store_payment_menu',
];

$submenu_items['report_stock'] = [
'title' => __( 'Stock', 'dokan-lite' ),
// 'icon' => '<i class="far fa-credit-card"></i>',
'url' => dokan_get_navigation_url( $parent_menu ) . '?path=%2Fanalytics%2Fstock',
'pos' => 50,
'permission' => 'dokan_view_store_payment_menu',
];
}

return $submenu_items;
}

public function add_additional_fields_schema1( $reports ) {
$reports[] = array(
'slug' => 'revenue/total_seller_earning',
Expand All @@ -140,8 +87,12 @@ public function add_additional_fields_schema1( $reports ) {
}

public function revenue_stats_schema( $reports ) {
$is_vendor_dashboard = dokan_is_seller_dashboard();

$reports['totals']['properties']['total_seller_earning'] = array(
'description' => __( 'Total Seller Earning', 'dokan-lite' ),
'description' => $is_vendor_dashboard
? esc_html__( 'Total Earning', 'dokan-lite' )
: esc_html__( 'Total Vendor Earning', 'dokan-lite' ),
'type' => 'number',
'context' => array( 'view', 'edit' ),
'readonly' => true,
Expand All @@ -150,7 +101,9 @@ public function revenue_stats_schema( $reports ) {
);

$reports['totals']['properties']['total_admin_commission'] = array(
'description' => __( 'Total Admin Commission', 'dokan-lite' ),
'description' => $is_vendor_dashboard
? esc_html__( 'Total Admin Commission', 'dokan-lite' )
: esc_html__( 'Total Commission', 'dokan-lite' ),
'type' => 'number',
'context' => array( 'view', 'edit' ),
'readonly' => true,
Expand Down
2 changes: 2 additions & 0 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ public function enqueue_front_scripts() {
$default_script = [
'ajaxurl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'dokan_reviews' ),
'order_nonce' => wp_create_nonce( 'dokan_view_order' ),
'product_edit_nonce' => wp_create_nonce( 'dokan_edit_product_nonce' ),
'ajax_loader' => DOKAN_PLUGIN_ASSEST . '/images/ajax-loader.gif',
'seller' => [
'available' => __( 'Available', 'dokan-lite' ),
Expand Down
19 changes: 19 additions & 0 deletions includes/Product/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,22 @@ function dokan_store_product_catalog_orderby() {

return $orderby_options;
}

/**
* Check if product listing should be rendered.
*
* @since DOKAN_SINCE
*
* @return bool
*/
function dokan_should_skip_product_listing_render(): bool {

/**
* Filter to control product listing template rendering.
*
* @since DOKAN_SINCE
*
* @param bool $should_render Whether to render the product listing template.
*/
return apply_filters( 'dokan_product_listing_template_render', false );
}
24 changes: 24 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use WeDevs\Dokan\Cache;
use WeDevs\Dokan\Utilities\OrderUtil;
use Automattic\WooCommerce\Internal\Admin\Analytics;

/**
* Dokan Admin menu position
Expand Down Expand Up @@ -162,6 +163,29 @@ function dokan_is_seller_dashboard() {
return false;
}

/**
* Check if analytics is enabled for the current seller.
*
* This checks if the seller is enabled and the analytics toggle option is set to "yes".
*
* @since DOKAN_SINCE
*
* @return bool True if analytics is enabled, false otherwise.
*/
function dokan_is_analytics_enabled(): bool {
$is_seller_enabled = dokan_is_seller_enabled( dokan_get_current_user_id() );
$is_analytics_enabled = 'yes' === get_option( Analytics::TOGGLE_OPTION_NAME, 'no' );

/**
* Filter to modify the analytics enabled status for the current seller.
*
* @since DOKAN_SINCE
*
* @param bool $is_enabled Whether analytics is enabled for the current seller.
*/
return apply_filters( 'dokan_is_analytics_enabled', ( $is_seller_enabled && $is_analytics_enabled ) );
}

/**
* Redirect to login page if not already logged in
*
Expand Down
18 changes: 10 additions & 8 deletions src/vendor-dashboard/reports/analytics/report/stock/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ import { CurrencyContext } from "@woocommerce/currency";
import ReportTable from "../../components/report-table";
import { isLowStock } from "./utils";
import { getAdminSetting } from "reports/utils/admin-settings";
import { mapToDashboardRoute } from "../../../helper";

const stockStatuses = getAdminSetting("stockStatuses", {});
const stockStatuses = getAdminSetting( 'stockStatuses', {
'instock' : __( 'In stock', 'dokan' ),
'outofstock' : __( 'Out of stock', 'dokan' ),
'onbackorder' : __( 'On backorder', 'dokan' )
});

console.log("Stock Statuses-->", stockStatuses);
class StockReportTable extends Component {
constructor() {
super();
Expand Down Expand Up @@ -74,13 +78,11 @@ class StockReportTable extends Component {

const name = decodeEntities(product.name);

const productDetailLink = getNewPath(
persistedQuery,
"/analytics/products",
{
filter: "single_product",
const productDetailLink = mapToDashboardRoute(
getNewPath( persistedQuery, '/analytics/products', {
filter: 'single_product',
products: parentId || id,
}
} )
);

const nameLink = (
Expand Down
Loading
Loading