8000 fix: Admin reports order data not reflecting after updated the orders data. by MdAsifHossainNadim · Pull Request #2754 · getdokan/dokan · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Admin reports order data not reflecting after updated the orders data. #2754

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

Conversation

MdAsifHossainNadim
Copy link
Contributor
@MdAsifHossainNadim MdAsifHossainNadim commented May 30, 2025

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

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

fix: Admin reports was not reflecting after orders data was updated.

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

  • Bug Fixes

    • Improved accuracy of vendor earnings and order total calculations, ensuring correct values are stored and compared.
  • Chores

    • Enhanced caching logic to better differentiate between calculation modes, leading to more reliable data retrieval.
    • Added notifications for cache deletions to improve system consistency and cache management.

@MdAsifHossainNadim MdAsifHossainNadim self-assigned this May 30, 2025
Copy link
Contributor
coderabbitai bot commented May 30, 2025

"""

Walkthrough

The changes introduce an optional $raw parameter to the get_earning_from_order_table method in the Commission class, enabling retrieval of detailed earning data as an array. The Order/VendorBalanceUpdateHandler.php logic is updated to use this new capability, ensuring accurate calculation and update of vendor earnings and order totals, with cache keys adjusted accordingly. Additionally, cache deletion triggers an action hook to maintain cache consistency.

Changes

File(s) Change Summary
includes/Commission.php Added optional $raw parameter to get_earning_from_order_table, updated return type and logic, modified cache keys.
includes/Order/VendorBalanceUpdateHandler.php Updated earning retrieval to use new $raw flag, ensured float casting, adjusted order total and net earning calculations, updated cache deletion keys, added method to remove raw cache on cache deletion action.
includes/Traits/ObjectCache.php Modified delete method to trigger dokan_cache_deleted action hook after cache deletion.

Sequence Diagram(s)

sequenceDiagram
    participant Admin
    participant WooCommerce
    participant VendorBalanceUpdateHandler
    participant Commission
    participant DB
    participant Cache

    Admin->>WooCommerce: Edit order total
    WooCommerce->>VendorBalanceUpdateHandler: Trigger update_dokan_order_table(order_id)
    VendorBalanceUpdateHandler->>Commission: get_earning_from_order_table(order_id, 'seller', true)
    Commission->>DB: Fetch order earning data
    Commission-->>VendorBalanceUpdateHandler: Return {net_amount, order_total}
    VendorBalanceUpdateHandler->>DB: Update dokan_orders table with new values if changed
    VendorBalanceUpdateHandler->>Cache: Delete cache for order_id + "_true"
    Cache->>VendorBalanceUpdateHandler: Trigger dokan_cache_deleted action
    VendorBalanceUpdateHandler->>Cache: Remove raw cache variant
Loading

Assessment against linked issues

Objective Addressed Explanation
Vendor earnings recalculated and updated when order total is edited (#4358)
Changes reflected in Vendor Dashboard > Orders and Dokan > Reports > All Logs (#4358)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested labels

QA approved, Upcoming Release

Suggested reviewers

  • mrabbani
  • shohag121

Poem

A rabbit hopped through lines of code,
Updating earnings as orders flowed.
With every edit, numbers aligned,
Vendor and admin, perfectly timed.
Reports now sparkle, clear and bright—
Bugs are gone, and all is right!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f360e51 and 8ea01e8.

📒 Files selected for processing (1)
  • includes/Commission.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Commission.php
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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 8000 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.

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: 0

🧹 Nitpick comments (1)
includes/Commission.php (1)

326-327: Use wp_json_encode() instead of json_encode() for WordPress standards.

WordPress coding standards recommend using wp_json_encode() instead of json_encode() for better compatibility and error handling.

Apply this diff to follow WordPress coding standards:

-        $raw_key   = json_encode( $raw );
+        $raw_key   = wp_json_encode( $raw );
🧰 Tools
🪛 GitHub Check: Run PHPCS inspection

[warning] 326-326:
json_encode() is discouraged. Use wp_json_encode() instead.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6d02fc8 and 9987e86.

📒 Files selected for processing (2)
  • includes/Commission.php (2 hunks)
  • includes/Order/VendorBalanceUpdateHandler.php (2 hunks)
🧰 Additional context used
🪛 GitHub Check: Run PHPCS inspection
includes/Commission.php

[warning] 326-326:
json_encode() is discouraged. Use wp_json_encode() instead.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: api tests (1, 1)
  • GitHub Check: e2e tests (1, 3)
🔇 Additional comments (6)
includes/Order/VendorBalanceUpdateHandler.php (4)

158-158: LGTM: Proper type casting.

Explicit float casting ensures type consistency and prevents potential type-related issues in calculations.


164-167: LGTM: Enhanced data retrieval with proper type safety.

The changes correctly utilize the new $raw parameter to retrieve detailed earning data as an array, with proper float casting for both net_amount and order_total. The order totals calculation is also properly cast to float for consistency.


172-172: LGTM: Improved conditional logic.

The enhanced conditional check now compares both order total and net earning, providing more accurate validation before skipping the database update. This should help ensure admin reports reflect the actual order state.


191-191: LGTM: Cache key consistency.

The cache deletion key correctly includes the "_true" suffix to match the updated cache key format that incorporates the $raw parameter.

includes/Commission.php (2)

321-323: LGTM: Well-designed API enhancement.

The addition of the optional $raw parameter with a default value of false maintains backward compatibility while enabling new functionality. The updated return type annotation correctly reflects that the method can now return either a float or an array.


345-352: LGTM: Clean conditional logic implementation.

The conditional logic properly handles both the raw array return (with explicit float casting) and the legacy calculated value return based on context. The implementation maintains the existing behavior when $raw is false while providing the new detailed data when $raw is true.

@MdAsifHossainNadim MdAsifHossainNadim added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels May 30, 2025
@mrabbani mrabbani added 👍 Dev Review Done Upcoming Release and removed Needs: Dev Review It requires a developer review and approval labels Jun 2, 2025
@shohag121 shohag121 added DO NOT MERGE Don't merge this PR and removed Upcoming Release labels Jun 3, 2025
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5151dc5 and 69c2c7b.

📒 Files selected for processing (3)
  • includes/Commission.php (2 hunks)
  • includes/Order/VendorBalanceUpdateHandler.php (3 hunks)
  • includes/Traits/ObjectCache.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Order/VendorBalanceUpdateHandler.php
🧰 Additional context used
🪛 GitHub Check: Run PHPCS inspection
includes/Commission.php

[failure] 330-330:
Expected 1 space after ":"; 2 found

🪛 GitHub Actions: Inspections
includes/Commission.php

[error] 1-1: PHP CodeSniffer: Expected 1 space after ":"; 2 found.

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: api tests (1, 1)
🔇 Additional comments (3)
includes/Traits/ObjectCache.php (1)

133-146: LGTM! Well-designed cache deletion notification.

The implementation correctly maintains the original method behavior while adding a useful notification mechanism. The action hook dokan_cache_deleted provides a clean way for other components to react to cache deletions without modifying core logic.

includes/Commission.php (2)

320-324: Excellent enhancement for raw data retrieval.

The addition of the $raw parameter is well-implemented:

  • Maintains backward compatibility with default parameter value
  • Proper separation of cache keys for raw vs computed data
  • Correct calculation logic using the raw earning array
  • Good use of filter hooks for extensibility

The functionality will enable more detailed analysis of earning data while preserving existing behavior.

Also applies to: 346-373


327-331: Efficient dual caching strategy.

The separate cache keys for raw and computed data (cache_key and cache_key_raw) is an excellent approach that:

  • Eliminates redundant database queries
  • Provides flexible data access patterns
  • Integrates well with the cache deletion notification system

The cache population strategy ensures both variants are available after a single database query.

Also applies to: 355-356

🧰 Tools
🪛 GitHub Check: Run PHPCS inspection

[failure] 330-330:
Expected 1 space after ":"; 2 found

@shohag121 shohag121 added Upcoming Release and removed DO NOT MERGE Don't merge this PR labels Jun 3, 2025
@shohan0120 shohan0120 added QA Approved : Shohan and removed Needs: Testing This requires further testing labels Jun 3, 2025
@shohag121 shohag121 merged commit feb5bc0 into develop Jun 3, 2025
1 of 5 checks passed
@shohag121 shohag121 deleted the fix/admin-vendor-reports-data-not-updated-for-updated-orders branch June 3, 2025 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0