Skip to content

enhance: Add admin earning calculations based on order type checks.#3112

Open
MdAsifHossainNadim wants to merge 6 commits intoenhance/add-order-types-for-dokan-order-stats-and-apply-upgraderfrom
enhance/update-admin-earnings-data-based-on-order-type
Open

enhance: Add admin earning calculations based on order type checks.#3112
MdAsifHossainNadim wants to merge 6 commits intoenhance/add-order-types-for-dokan-order-stats-and-apply-upgraderfrom
enhance/update-admin-earnings-data-based-on-order-type

Conversation

@MdAsifHossainNadim
Copy link
Contributor

@MdAsifHossainNadim MdAsifHossainNadim commented Feb 25, 2026

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)

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?

@MdAsifHossainNadim MdAsifHossainNadim self-assigned this Feb 25, 2026
@MdAsifHossainNadim MdAsifHossainNadim changed the title enhance: Add admin earning calculations based on order type checks in commission and analytics. enhance: Add admin earning calculations based on order type checks. Feb 25, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 25, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 790ec398-baf2-401d-8c0d-598859ae01c0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enhance/update-admin-earnings-data-based-on-order-type

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Member

@mrabbani mrabbani left a comment

Choose a reason for hiding this comment

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

Code Review

CRITICAL: Double-counting get_total_admin_fees() in get_admin_total_earning()

Location: includes/Commission/OrderCommission.php:501

get_admin_commission() already returns get_admin_net_commission() + get_total_admin_fees(). The new implementation adds get_total_admin_fees() again:

// Current get_admin_commission():
return $this->get_admin_net_commission() + $this->get_total_admin_fees();

// New get_admin_total_earning():
return $this->get_admin_net_earning() + $this->get_admin_commission() + $this->get_total_admin_fees();
// Expands to: admin_net_earning + (admin_net_commission + total_admin_fees) + total_admin_fees  ← DOUBLE

Should likely be:

return $this->get_admin_net_earning() + $this->get_admin_commission();

Also, this method is marked @deprecated 4.0.0 but is now being given new behavior. The @deprecated tag should be removed if this is the correct method going forward.


ERROR: Copy-paste docblocks on Commission model

Location: includes/Commission/Model/Commission.php

Both $admin_net_commission and $admin_net_earning have the same docblock: "Vendor Earning without subsidy." — these should describe admin properties:

  • $admin_net_commission → "Admin's net commission amount."
  • $admin_net_earning → "Admin's net earning from admin-type orders (subscriptions, advertisements, etc.)."

ERROR: CommissionInterface not updated

Location: includes/Commission/Contracts/CommissionInterface.php

The Commission model now has get_admin_net_earning() / set_admin_net_earning(), but CommissionInterface was not updated. Add get_admin_net_earning(): float to the interface contract.


WARNING: @since DOKAN_SINCE placeholder

Location: includes/Analytics/Reports/OrderType.php

Both new methods (get_admin_earning_order_types, is_admin_order_type) use @since DOKAN_SINCE — replace with the actual version before merge.


WARNING: Missing @since tags on new Commission model methods

set_admin_net_earning() and get_admin_net_earning() in includes/Commission/Model/Commission.php are missing @since annotations.


PR Template

  • "Changes proposed" section is empty
  • "How to test" has no actual steps
  • "Changelog entry" is placeholder text
  • "Closes #" is empty

@MdAsifHossainNadim
Copy link
Contributor Author

Code Review

Base: enhance/add-order-types-for-dokan-order-stats-and-apply-upgrader
Commits reviewed: 88a6324 (enhance), 4f9c4b6 (fix)


CRITICAL: get_admin_total_earning() drops fees — regression in commit 4f9c4b6

Location: includes/Commission/OrderCommission.php:496

The second commit changed the formula based on the first reviewer's suggestion, but that suggestion was based on an incorrect premise.

Base branch (before this PR):

return $this->get_admin_commission() + $this->get_total_admin_fees();
// get_admin_commission() resolves to Commission model: max(admin_net_commission, 0)
// Result: max(net_commission, 0) + fees

Commit 1 88a6324 (correct):

return $this->get_admin_net_earning() + $this->get_admin_commission() + $this->get_total_admin_fees();
// = admin_net_earning + max(net_commission, 0) + fees  ✅

Commit 2 4f9c4b6 (regression):

return $this->get_admin_net_earning() + $this->get_admin_commission();
// = admin_net_earning + max(net_commission, 0)  ← fees GONE ❌

The first reviewer assumed get_admin_commission() returns admin_net_commission + total_admin_fees (as it does on develop). But on this base branch, the OrderCommission::get_admin_commission() override was already removed (in PR #3099). It now resolves to Commission::get_admin_commission() = max(admin_net_commission, 0)no fees.

Result: Admin total earning silently excludes shipping, tax, gateway fees, and order fees. This directly impacts includes/Commission.php:241 where admin earnings are calculated for orders.

Fix: Revert to commit 1's formula:

return $this->get_admin_net_earning() + $this->get_admin_commission() + $this->get_total_admin_fees();

ERROR: calculate_for_refund() doesn't handle admin-type orders

Location: includes/Commission/OrderCommission.php:142-155

The calculate() method now branches on is_admin_earning_order_type — routing subscription/advertisement line items into admin_net_earning. But calculate_for_refund() was not updated with matching logic:

$refund_commission->set_admin_net_commission(
    $refund_commission->get_admin_net_commission() + $item_refund_commission->get_admin_net_commission()
);
$refund_commission->set_vendor_net_earning(
    $refund_commission->get_vendor_net_earning() + $item_refund_commission->get_vendor_net_earning()
);

For admin-type orders (subscriptions, advertisements), refund amounts should route to admin_net_earning instead — matching the branching logic in calculate(). Without this, refunds on subscription/advertisement orders won't reduce the admin's net earning.


ERROR: Direct instantiation instead of DI container

Location: includes/Commission/OrderCommission.php:78

$is_admin_earning_order_type = ( new OrderType() )->is_admin_order_type( $this->order );

Per Dokan conventions, services should be resolved via the DI container (dokan_get_container()->get(OrderType::class)), not instantiated directly with new. This makes testing and extension harder.


WARNING: get_data() doesn't expose admin_net_earning

Location: includes/Commission/OrderCommission.php:411-422

The get_data() array returns admin_commission, admin_net_commission, vendor_earning, etc., but doesn't include the new admin_net_earning field. Any consumer relying on this array for debugging, data export, or downstream processing won't see the new value.

Fix: Add 'admin_net_earning' => $this->get_admin_net_earning() to the returned array.


WARNING: @since DOKAN_SINCE placeholders

Replace with actual version before merge:

File Location
includes/Analytics/Reports/OrderType.php get_admin_earning_order_types(), is_admin_order_type()
includes/Commission/Contracts/CommissionInterface.php get_admin_net_earning()
includes/Commission/Model/Commission.php set_admin_net_earning(), get_admin_net_earning()

WARNING: is_admin_order_type() param type mismatch

Location: includes/Analytics/Reports/OrderType.php:280

public function is_admin_order_type( $order ): bool {

Docblock says @param \WC_Order $order but the parameter has no type hint and get_type() accepts \WC_Abstract_Order. Should be type-hinted as \WC_Abstract_Order for consistency and safety.


PR Checklist

Item Status
@since placeholders ❌ Need real version numbers
Test instructions ❌ "How to test" section is empty
Changelog entry ❌ Placeholder text
Closes # ❌ Empty
Changes proposed ❌ Empty

- Restore get_total_admin_fees() in get_admin_total_earning() formula
  to prevent silent exclusion of shipping, tax, gateway and order fees
- Fix calculate_for_refund() to route refund amounts to admin_net_earning
  for admin-type orders (subscriptions, advertisements), matching the
  branching logic in calculate()
- Replace direct `new OrderType()` with DI container resolution
- Add admin_net_earning to get_data() return array
- Add \WC_Abstract_Order type hint to is_admin_order_type() parameter

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MdAsifHossainNadim MdAsifHossainNadim force-pushed the enhance/update-admin-earnings-data-based-on-order-type branch from 3641c8c to 98a9483 Compare March 4, 2026 06:48
@MdAsifHossainNadim
Copy link
Contributor Author

✅ Dev Review Done

All previously reported issues have been addressed in commit 98a9483:

Issue Status
get_admin_total_earning() drops fees (regression) ✅ Fixed — formula restored to admin_net_earning + admin_commission + total_admin_fees
calculate_for_refund() ignores admin-type orders ✅ Fixed — branches to admin_net_earning for subscription/advertisement refunds
Direct new OrderType() instead of DI container ✅ Fixed — uses dokan_get_container()->get( OrderType::class )
get_data() missing admin_net_earning ✅ Fixed — exposed in return array
is_admin_order_type() untyped parameter ✅ Fixed — \WC_Abstract_Order type hint added

Remaining before merge:

  • Replace @since DOKAN_SINCE placeholders with actual version
  • Fill in PR template (changes proposed, test steps, changelog, linked issue)

Good to go ✅

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.

2 participants