-
Notifications
You must be signed in to change notification settings - Fork 206
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 commission upgrader #2463
Fix commission upgrader #2463
Conversation
WalkthroughThe pull request introduces changes to three classes within the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (3)
includes/Commission/Upugrader/Update_Vendor_Commission.php (1)
146-150
: Consider adding data validation before saveWhile the error handling is good, consider adding validation before saving to ensure data integrity:
- Validate that empty string values are acceptable
- Consider logging the before/after values for audit purposes
if ( Flat::SOURCE === $commission_type_old ) { + // Log old values for audit + $this->log_commission_change($vendor_id, 'flat', $percentage, ''); $commission->set_percentage( '' ); $commission->set_flat( $percentage ); } elseif ( Percentage::SOURCE === $commission_type_old ) { $commission->set_percentage( $percentage ); + // Log old values for audit + $this->log_commission_change($vendor_id, 'percentage', $commission->get_flat(), ''); $commission->set_flat( '' ); }includes/Commission/Upugrader/Update_Category_Commission.php (2)
Line range hint
204-207
: Add validation before updating WordPress optionThe direct update of WordPress options without validation is risky:
+// Validate commission values before update +if (!$this->validate_commission_values($category_commission)) { + error_log("Invalid commission values for term_id: $term_id"); + return; +} $dokan_selling['commission_category_based_values'] = $category_commission; -update_option( 'dokan_selling', $dokan_selling ); +$updated = update_option( 'dokan_selling', $dokan_selling ); +if (!$updated) { + error_log("Failed to update dokan_selling option for term_id: $term_id"); +}
Line range hint
1-1
: Consider implementing a shared Commission Value HandlerThe commission value changes are implemented similarly across products, vendors, and categories. Consider creating a shared service to handle commission value conversions:
- Implement consistent validation
- Centralize error handling
- Provide audit logging
- Ensure type safety
Example implementation structure:
namespace WeDevs\Dokan\Commission\Handler; class CommissionValueHandler { public function convertToFixed($oldType, $percentage, $flat) { // Shared conversion logic } public function validate($commission) { // Shared validation } public function log($entity, $oldValues, $newValues) { // Shared logging } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
includes/Commission/Upugrader/Update_Category_Commission.php
(1 hunks)includes/Commission/Upugrader/Update_Product_Commission.php
(1 hunks)includes/Commission/Upugrader/Update_Vendor_Commission.php
(1 hunks)
🔇 Additional comments (1)
includes/Commission/Upugrader/Update_Product_Commission.php (1)
190-198
: Verify data type handling in database and UI layers
The change from numeric 0
to empty string ''
for commission values needs careful consideration:
- Ensure database schema accepts empty strings for these fields
- Verify UI components handle empty string values correctly
- Confirm that downstream calculations handle empty strings appropriately
✅ Verification successful
Let me analyze the results and generate a final response.
The search results show that empty strings are widely used and handled properly throughout the codebase:
-
Database layer: No direct database schema found, but the code shows consistent use of empty strings as valid values in commission settings and calculations.
-
UI components handle empty strings:
CategoryBasedCommission.vue
,VendorCommissionFields.vue
, and other components explicitly handle empty string values- Form validation and formatting functions properly process empty strings
- UI components use proper type coercion and validation
-
Calculations:
- Commission calculation code in
Commission/
directory shows empty strings are valid and handled - Test files demonstrate empty strings are expected values in commission calculations
- Type conversion and validation functions handle empty string cases
- Commission calculation code in
Empty string handling is consistent and safe
The codebase shows that empty strings are the standard way to represent unset commission values, with proper handling across database, UI and calculation layers.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check database schema and related code for commission value handling
echo "Checking database schema..."
rg -A 5 "CREATE TABLE.*dokan.*commission"
echo "Checking value handling in calculations..."
rg -A 5 "(percentage|flat).*=.*''"
echo "Checking UI value handling..."
rg -A 5 "render.*commission.*(percentage|flat)"
Length of output: 112214
$category_commission_item['percentage'] = ''; | ||
$category_commission_item['flat'] = $commission; | ||
} elseif ( Percentage::SOURCE === $commission_type ) { | ||
$category_commission_item['percentage'] = $commission; | ||
$category_commission_item['flat'] = 0; | ||
$category_commission_item['flat'] = ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling and validation for option updates
The current implementation lacks error handling and validation when updating WordPress options:
- Add validation before updating options
- Implement error handling
- Consider adding logging for audit purposes
if ( Flat::SOURCE === $commission_type ) {
+ try {
$category_commission_item['percentage'] = '';
$category_commission_item['flat'] = $commission;
+ } catch (\Exception $e) {
+ error_log("Failed to update category commission for term_id: $term_id. Error: " . $e->getMessage());
+ return;
+ }
} elseif ( Percentage::SOURCE === $commission_type ) {
+ try {
$category_commission_item['percentage'] = $commission;
$category_commission_item['flat'] = '';
+ } catch (\Exception $e) {
+ error_log("Failed to update category commission for term_id: $term_id. Error: " . $e->getMessage());
+ return;
+ }
}
Committable suggestion skipped: line range outside the PR's diff.
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (2)
includes/Upgrade/AdminNotice.php (2)
40-40
: Improve message formatting for better readability.The addition of the database backup warning is crucial, especially given the commission data structure changes. However, consider restructuring the message for better clarity.
Consider this format:
- 'description' => __( 'Updating your Dokan data is required to continue functional operations. Kindly backup your database before running upgrade for safety.', 'dokan-lite' ), + 'description' => __( 'Updating your Dokan data is required to continue functional operations. IMPORTANT: Please backup your database before proceeding with the upgrade process.', 'dokan-lite' ),The revised message:
- Maintains the essential warning
- Uses "IMPORTANT" to draw attention
- Uses more formal language ("Please" instead of "Kindly")
- Clarifies the timing ("before proceeding" instead of "before running")
40-40
: Maintain consistency in backup warning messages.The backup warning appears in both the description and confirmation dialog with slightly different wording. Consider using consistent language to reinforce the importance of the backup step.
If you implement the previous suggestion for the description, consider updating the confirmation message as well:
- 'confirm_message' => __( 'It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?', 'dokan-lite' ), + 'confirm_message' => __( 'IMPORTANT: Please backup your database before proceeding with the upgrade process. Are you sure you wish to run the updater now?', 'dokan-lite' ),Also applies to: 51-51
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
includes/Upgrade/AdminNotice.php
(1 hunks)
🔇 Additional comments (1)
includes/Upgrade/AdminNotice.php (1)
Line range hint 71-91
: LGTM: Robust error handling implementation.
The error handling in the upgrade process is comprehensive, covering:
- Permission validation
- Process state verification
- Upgrade requirement checks
- Proper exception handling with appropriate status codes
* chore: bump version to 3.14.0 * Add geolocation map tests * Update feature map * fix coverage map * Auction tests (getdokan#2452) * Add a test * Update feature map * Fix lint issue * change filename temporary * Revert filename to original * Fix notice test * Fix commission test * Add new tests to featuremap (getdokan#2453) * Add new tests to feature map * Add new tests to featuremap * Skip shipstation tests * Add notice for version compatibility. (getdokan#2450) * Add notice for version compatibility. * Added dokan pro update message. * Added dokan pro update message. * Added dokan pro update message. * fix: plugin version after activation (getdokan#2447) * chore: bump version to 3.14.0 * chore: Released Version 3.14.0 * Fix commission upgrader (getdokan#2463) * Fix commission upgrader * Add database backup message in upgrade. * chore: Released Version 3.14.1 * Fix skipped product tests (getdokan#2457) * Fix and update skipped product tests * Update a variable * Add store list & reviews test (getdokan#2460) * Fix skipped store tests * Add store reviews tests * Update comment * skipped a test * Enhancement: product commission bulk edit (getdokan#2464) * Remove $commission_type variable it was not used * Save fixed as default commission type * Save bulk product commission. * Update bulk edit ui Skip reverse withdrawal and advertisement product id * Update bulk edit ui Skip reverse withdrawal and advertisement product id * Revert alignment * chore: bump version to v3.14.2 * Add Commission tests (getdokan#2471) * add new commission tests * Add commission tests * Add vendor coupon tests (getdokan#2470) * Add vendor coupon tests * Update test tags --------- Co-authored-by: Aunshon <[email protected]> Co-authored-by: Aunshon <[email protected]> Co-authored-by: KAMRUZZAMAN <[email protected]>
* chore: bump version to 3.14.0 * Add dokan tracking tests * Add commission meta box test * Update feature map * Update config file * Update feature map * Add vendor filters test * Add a shortcode test * Fix commission tests * Add geolocation tests * Auction tests (getdokan#2452) * Add a test * Update feature map * Fix lint issue * change filename temporary * Revert filename to original * Fix notice test * Fix commission test * Add new tests to featuremap (getdokan#2453) * Add new tests to feature map * Add new tests to featuremap * Skip shipstation tests * Add notice for version compatibility. (getdokan#2450) * Add notice for version compatibility. * Added dokan pro update message. * Added dokan pro update message. * Added dokan pro update message. * fix: plugin version after activation (getdokan#2447) * chore: bump version to 3.14.0 * chore: Released Version 3.14.0 * Fix commission upgrader (getdokan#2463) * Fix commission upgrader * Add database backup message in upgrade. * chore: Released Version 3.14.1 * Fix skipped product tests (getdokan#2457) * Fix and update skipped product tests * Update a variable * Add store list & reviews test (getdokan#2460) * Fix skipped store tests * Add store reviews tests * Update comment * skipped a test * Enhancement: product commission bulk edit (getdokan#2464) * Remove $commission_type variable it was not used * Save fixed as default commission type * Save bulk product commission. * Update bulk edit ui Skip reverse withdrawal and advertisement product id * Update bulk edit ui Skip reverse withdrawal and advertisement product id * Revert alignment * chore: bump version to v3.14.2 * Add Commission tests (getdokan#2471) * add new commission tests * Add commission tests * Add vendor coupon tests (getdokan#2470) * Add vendor coupon tests * Update test tags --------- Co-authored-by: Aunshon <[email protected]> Co-authored-by: Aunshon <[email protected]> Co-authored-by: KAMRUZZAMAN <[email protected]>
* Add booking product details test * Add booking product tests * Fix mix-max flaky issue * Update product name & id reference * update tags test * chore: bump version to 3.14.0 * Fix failed tests * Fix flaky tests * Fix commission tests * Update commission test logic * Add new tests & update feature map * Auction tests (getdokan#2452) * Add a test * Update feature map * Fix lint issue * change filename temporary * Revert filename to original * Fix notice test * Fix commission test * Add new tests to featuremap (getdokan#2453) * Add new tests to feature map * Add new tests to featuremap * Skip shipstation tests * Add notice for version compatibility. (getdokan#2450) * Add notice for version compatibility. * Added dokan pro update message. * Added dokan pro update message. * Added dokan pro update message. * fix: plugin version after activation (getdokan#2447) * chore: bump version to 3.14.0 * chore: Released Version 3.14.0 * Fix commission upgrader (getdokan#2463) * Fix commission upgrader * Add database backup message in upgrade. * chore: Released Version 3.14.1 * Fix skipped product tests (getdokan#2457) * Fix and update skipped product tests * Update a variable * Add store list & reviews test (getdokan#2460) * Fix skipped store tests * Add store reviews tests * Update comment * skipped a test * Enhancement: product commission bulk edit (getdokan#2464) * Remove $commission_type variable it was not used * Save fixed as default commission type * Save bulk product commission. * Update bulk edit ui Skip reverse withdrawal and advertisement product id * Update bulk edit ui Skip reverse withdrawal and advertisement product id * Revert alignment * chore: bump version to v3.14.2 * Add changes * Add Commission tests (getdokan#2471) * add new commission tests * Add commission tests * Add vendor coupon tests (getdokan#2470) * Add vendor coupon tests * Update test tags --------- Co-authored-by: Aunshon <[email protected]> Co-authored-by: Aunshon <[email protected]> Co-authored-by: KAMRUZZAMAN <[email protected]>
All Submissions:
Closes
How to test the changes in this Pull Request:
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:
FOR PR REVIEWER ONLY:
Summary by CodeRabbit
New Features
Bug Fixes