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

Fix/revenue reports #2423

Merged
merged 6 commits into from
Oct 30, 2024
Merged

Fix/revenue reports #2423

merged 6 commits into from
Oct 30, 2024

Conversation

mrabbani
Copy link
Member

@mrabbani mrabbani commented Oct 30, 2024

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

  • Full PR Link

Closes

  • Closes #

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • New Features

    • Enhanced reporting capabilities for Dokan orders with vendor-specific filtering.
  • Bug Fixes

    • Removed deprecated analytics functionality related to coupon filtering in reports.
  • Chores

    • Simplified asset management by removing the dokan-admin-analytics script from registration and enqueueing processes.
    • Updated build configuration by eliminating the entry point for dokan-admin-analytics.

Copy link
Contributor

coderabbitai bot commented Oct 30, 2024

Walkthrough

The changes in this pull request involve the removal of the dokan-admin-analytics.js file and its associated functionality from the Dokan plugin, which included filtering out coupon-related data from WooCommerce's admin revenue reports. Additionally, the QueryFilter class has been updated to enhance vendor-specific filtering in analytics reports, including the introduction of new methods and expanded logic for calculating various order metrics. The Assets class has also been modified to remove references to the deleted analytics script, and the webpack.config.js file has been updated to reflect this removal.

Changes

File Path Change Summary
assets/src/js/dokan-admin-analytics.js File deleted; functionality for filtering out coupons from revenue reports removed.
includes/Analytics/Reports/Orders/Stats/QueryFilter.php Updated to enhance vendor-specific filtering; added new method and expanded report calculation logic.
includes/Assets.php Removed dokan-admin-analytics script from registration and enqueueing processes.
webpack.config.js Removed entry point for dokan-admin-analytics from the build configuration.

Possibly related PRs

Suggested labels

Needs: Testing, Needs: Dev Review, Upcoming Release

Suggested reviewers

  • shohag121

🐇 In the world of code, changes do abound,
The analytics script, now lost, is found.
With vendor filters, our reports will gleam,
As we hop along, chasing the dream!
🥕✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@shashwatahalder01 shashwatahalder01 added Needs: Testing This requires further testing QA In Progress QA approved This PR is approved by the QA team and removed Needs: Testing This requires further testing QA In Progress labels Oct 30, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (3)
includes/Analytics/Reports/Orders/Stats/QueryFilter.php (3)

66-66: Remove unnecessary commented-out code

The commented-out line assigning $types is no longer needed and can be safely removed to keep the codebase clean and maintainable.

Apply this diff to remove the redundant code:

- // $types = $this->get_order_types_for_sql_excluding_refunds();

73-79: Clean up outdated comments to enhance readability

The comment block from lines 73 to 79 references restoring a file and includes an old code link. Since the code has evolved, this comment may no longer be relevant. Consider updating or removing it to reduce confusion.

Apply this diff to remove the outdated comment:

 /**
- * Override WC column.
- *
- * We can apply the common where clause after Dokan Coupon Distribution.
- * File to restore: @see https://github.com/getdokan/dokan/blob/2cffa360a94b32033e7591fece5950068ab758f5/includes/Analytics/Reports/Orders/Stats/QueryFilter.php#L4
- */
+ * Override WC columns to include Dokan-specific calculations.
  */

138-140: Evaluate the necessity of overriding add_where_subquery_for_vendor_filter

The method add_where_subquery_for_vendor_filter currently only calls the parent method without adding any new functionality. If no additional processing is required, consider removing this override to simplify the code. This can prevent confusion for future maintainers who might expect custom behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2cffa36 and 5c9530e.

📒 Files selected for processing (4)
  • assets/src/js/dokan-admin-analytics.js (0 hunks)
  • includes/Analytics/Reports/Orders/Stats/QueryFilter.php (4 hunks)
  • includes/Assets.php (0 hunks)
  • webpack.config.js (0 hunks)
💤 Files with no reviewable changes (3)
  • assets/src/js/dokan-admin-analytics.js
  • includes/Assets.php
  • webpack.config.js
🔇 Additional comments (2)
includes/Analytics/Reports/Orders/Stats/QueryFilter.php (2)

6-6: Import statement approved

The addition of the OrderType import is appropriate and necessary for the updated functionality.


33-37: Confirm the replacement of filter callbacks

You've commented out the previous filters using add_where_subquery and replaced them with add_where_subquery_for_vendor_filter. Ensure that the new method fully replicates or enhances the functionality of the old one to avoid any regression.

To verify that the new filters produce the desired effect, consider testing the analytics reports to confirm that vendor filtering works as intended.

Comment on lines +58 to 61
public function modify_admin_report_columns( array $column, string $context, string $table_name ): array {
if ( $context !== $this->context ) {
return $column;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update the docblock parameter name to match the method signature

The parameter in the method docblock is still named $wc_table_name, but it has been renamed to $table_name in the method signature. Update the docblock to reflect this change for consistency and clarity.

Apply this diff to update the docblock:

 /**
  * Modifies the admin report columns to include Dokan-specific data.
  *
  * @param array  $column        The existing report columns.
  * @param string $context       The context of the report.
- * @param string $wc_table_name The WooCommerce table name being queried.
+ * @param string $table_name    The WooCommerce table name being queried.
  *
  * @return array Modified report columns.
  */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public function modify_admin_report_columns( array $column, string $context, string $table_name ): array {
if ( $context !== $this->context ) {
return $column;
}
/**
* Modifies the admin report columns to include Dokan-specific data.
*
* @param array $column The existing report columns.
* @param string $context The context of the report.
* @param string $table_name The WooCommerce table name being queried.
*
* @return array Modified report columns.
*/
public function modify_admin_report_columns( array $column, string $context, string $table_name ): array {
if ( $context !== $this->context ) {
return $column;
}

Comment on lines +63 to +71
$dokan_table_name = $this->get_dokan_table();
$order_types = $this->get_order_types_for_sql_excluding_refunds();
$types = implode( ',', ( new OrderType() )->get_vendor_order_types() );
// $types = $this->get_order_types_for_sql_excluding_refunds();

$parent_order_types_str = implode( ',', ( new OrderType() )->get_admin_order_types_excluding_refunds() );
$refund_order_types_str = implode( ',', ( new OrderType() )->get_vendor_refund_types() );

$order_count = "SUM( CASE WHEN {$dokan_table_name}.order_type IN($order_types) THEN 1 ELSE 0 END )";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Ensure consistent usage of $types and $order_types variables

There is potential confusion between the variables $order_types and $types. In line 71, you use $order_types within the SQL string, but elsewhere $types is used for similar purposes. For consistency and to avoid errors, consider standardizing the variable names or verifying that each variable is correctly used.

Option 1: Update the SQL expression to use $types if that is the intended variable.

- $order_count = "SUM( CASE WHEN {$dokan_table_name}.order_type IN($order_types) THEN 1 ELSE 0 END )";
+ $order_count = "SUM( CASE WHEN {$dokan_table_name}.order_type IN($types) THEN 1 ELSE 0 END )";

Option 2: If $order_types is intended, ensure its value matches the expected format and usage throughout the code.

Committable suggestion was skipped due to low confidence.

@mrabbani mrabbani merged commit c6dcc61 into develop Oct 30, 2024
1 of 2 checks passed
@mrabbani mrabbani deleted the fix/revenue-reports branch October 30, 2024 11:03
@coderabbitai coderabbitai bot mentioned this pull request Oct 30, 2024
12 tasks
@shashwatahalder01
Copy link
Contributor

shashwatahalder01 commented Oct 31, 2024

Scenario:
Showing HPOS incompatible warning upon activating zip
N.B. Overall test issue

Steps to reproduce:

  1. activate plugin
  2. see plugin pages

Screenshot:
Screenshot at Oct 31 09-06-42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
QA approved This PR is approved by the QA team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants