-
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
Added commission settings sub-categories reset toggle. #2543
base: develop
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -111,7 +111,7 @@ public function enqueue_scripts() { | |||||
wp_enqueue_script( | ||||||
'dokan-setup-wizard-commission', | ||||||
DOKAN_PLUGIN_ASSEST . '/js/dokan-setup-wizard-commission.js', | ||||||
array( 'jquery', 'dokan-vue-bootstrap', 'dokan-accounting' ), | ||||||
array( 'jquery', 'dokan-vue-bootstrap', 'dokan-accounting', 'dokan-sweetalert2' ), | ||||||
DOKAN_PLUGIN_VERSION, | ||||||
[ 'in_footer' => true ] | ||||||
); | ||||||
|
@@ -517,6 +517,8 @@ public function dokan_setup_commission() { | |||||
$additional_fee = isset( $options['additional_fee'] ) ? $options['additional_fee'] : 0; | ||||||
$commission_category_based_values = isset( $options['commission_category_based_values'] ) ? $options['commission_category_based_values'] : new stdClass(); | ||||||
$commission_type = ! empty( $options['commission_type'] ) ? $options['commission_type'] : 'fixed'; | ||||||
$reset_sub_category_when_edit_all_category = ! empty( $options['reset_sub_category_when_edit_all_category'] ) ? $options['reset_sub_category_when_edit_all_category'] : 'on'; | ||||||
$reset_sub_category = ! ( $reset_sub_category_when_edit_all_category === 'off' ); | ||||||
|
||||||
$args = apply_filters( | ||||||
'dokan_admin_setup_wizard_step_setup_selling_template_args', [ | ||||||
|
@@ -525,6 +527,7 @@ public function dokan_setup_commission() { | |||||
'additional_fee' => $additional_fee, | ||||||
'commission_category_based_values' => $commission_category_based_values, | ||||||
'dokanCommission' => dokan_commission_types(), | ||||||
'reset_sub_category' => $reset_sub_category, | ||||||
'setup_wizard' => $this, | ||||||
] | ||||||
); | ||||||
|
@@ -565,11 +568,12 @@ public function dokan_setup_commission_save() { | |||||
$dokan_commission_percentage = 0; | ||||||
} | ||||||
|
||||||
$options = get_option( 'dokan_selling', [] ); | ||||||
$options['commission_type'] = isset( $_POST['dokan_commission_type'] ) ? sanitize_text_field( wp_unslash( $_POST['dokan_commission_type'] ) ) : 'fixed'; | ||||||
$options['admin_percentage'] = $dokan_commission_percentage; | ||||||
$options['additional_fee'] = isset( $_POST['dokan_commission_flat'] ) ? sanitize_text_field( wp_unslash( $_POST['dokan_commission_flat'] ) ) : 0; | ||||||
$options['commission_category_based_values'] = isset( $_POST['dokan_commission_category_based'] ) ? wc_clean( json_decode( sanitize_text_field( wp_unslash( $_POST['dokan_commission_category_based'] ) ), true ) ) : []; | ||||||
$options = get_option( 'dokan_selling', [] ); | ||||||
$options['commission_type'] = isset( $_POST['dokan_commission_type'] ) ? sanitize_text_field( wp_unslash( $_POST['dokan_commission_type'] ) ) : 'fixed'; | ||||||
$options['admin_percentage'] = $dokan_commission_percentage; | ||||||
$options['additional_fee'] = isset( $_POST['dokan_commission_flat'] ) ? sanitize_text_field( wp_unslash( $_POST['dokan_commission_flat'] ) ) : 0; | ||||||
$options['commission_category_based_values'] = isset( $_POST['dokan_commission_category_based'] ) ? wc_clean( json_decode( sanitize_text_field( wp_unslash( $_POST['dokan_commission_category_based'] ) ), true ) ) : []; | ||||||
$options['reset_sub_category_when_edit_all_category'] = isset( $_POST['reset_sub_category'] ) && false === dokan_string_to_bool( $_POST['reset_sub_category'] ) ? 'off' : 'on'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sanitize POST data before use. The - $options['reset_sub_category_when_edit_all_category'] = isset( $_POST['reset_sub_category'] ) && false === dokan_string_to_bool( $_POST['reset_sub_category'] ) ? 'off' : 'on';
+ $options['reset_sub_category_when_edit_all_category'] = isset( $_POST['reset_sub_category'] ) && false === dokan_string_to_bool( sanitize_text_field( wp_unslash( $_POST['reset_sub_category'] ) ) ) ? 'off' : 'on'; 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: Inspections[error] 576-576: Security issue: $_POST['reset_sub_category'] not unslashed and not sanitized before use |
||||||
|
||||||
update_option( 'dokan_selling', $options ); | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,16 @@ | |
<span class="description !mt-[6px] block">{{__( 'Set the commission type that admin will get', 'dokan-lite' )}}</span> | ||
</div> | ||
</div> | ||
<div v-if="'category_based' === selectedCommission" class="flex justify-between mb-4"> | ||
<label class="!p-0 m-0 !mb-[6px] block" for="_subscription_product_admin_commission_type"> | ||
{{__( 'Apply Parent Category Commission to All Subcategories ', 'dokan-lite' )}} | ||
|
||
<span class="dokan-tooltips-help tips" v-tooltip :title="__( 'When enabled, changing a parent category\'s commission rate will automatically update all its subscription. Disable this option to maintain independent commission rates for subcategories', 'dokan-lite' )"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. subscription might be typo? |
||
<i class="fas fa-question-circle"></i> | ||
</span> | ||
</label> | ||
<Switches @input="handleResetToggle" :enabled="resetSubCategory"/> | ||
</div> | ||
<div v-if="'category_based' === selectedCommission"> | ||
<label class="!p-0 m-0 !mb-[6px] block" for="_subscription_product_admin_commission_type"> | ||
{{__( 'Admin Commission', 'dokan-lite' )}} | ||
|
@@ -26,6 +36,7 @@ | |
<category-based-commission | ||
:value="categoryCommission" | ||
@change="onCategoryUpdate" | ||
:resetSubCategory="resetSubCategory" | ||
/> | ||
</div> | ||
<div v-else-if="'fixed' === selectedCommission"> | ||
|
@@ -50,11 +61,12 @@ | |
|
||
import CombineInput from "admin/components/CombineInput.vue"; | ||
import CategoryBasedCommission from "admin/components/Commission/CategoryBasedCommission.vue"; | ||
import Switches from "./Switches.vue"; | ||
|
||
export default { | ||
name: "VendorCommissionFields", | ||
|
||
components: { CategoryBasedCommission, CombineInput }, | ||
components: { Switches, CategoryBasedCommission, CombineInput }, | ||
|
||
props: { | ||
vendorInfo: { | ||
|
@@ -68,6 +80,7 @@ export default { | |
categoryCommission: {}, | ||
commissionTypes: {}, | ||
fixedCommission: {}, | ||
resetSubCategory: true | ||
}; | ||
}, | ||
|
||
|
@@ -94,10 +107,36 @@ export default { | |
this.categoryCommission = this.vendorInfo.admin_category_commission; | ||
} | ||
|
||
|
||
if ( this.vendorInfo.hasOwnProperty( 'reset_sub_category' ) ) { | ||
this.resetSubCategory = this.vendorInfo.reset_sub_category !== false; | ||
} | ||
|
||
this.fixedCommission = fixedCommission; | ||
}, | ||
|
||
methods: { | ||
handleResetToggle(value) { | ||
const confirmTitle = value ? this.__("Enable Commission Inheritance Setting?", "dokan-lite") : this.__("Disable Commission Inheritance Setting?", "dokan-lite"); | ||
const htmlText = value ? this.__("Parent category commission changes will automatically update all subcategories. Existing rates will remain unchanged until parent category is modified.", "dokan-lite") : this.__("Subcategories will maintain their independent commission rates when parent category rates are changed.", "dokan-lite"); | ||
const confirmBtnText = value ? this.__("Enable", "dokan-lite") : this.__("Disable", "dokan-lite"); | ||
const updatableValue = !value; | ||
const self = this; | ||
|
||
Swal.fire({ | ||
icon: "warning", | ||
html: htmlText, | ||
title: confirmTitle, | ||
showCancelButton: true, | ||
cancelButtonText: this.__("Cancel", "dokan-lite"), | ||
confirmButtonText: confirmBtnText | ||
}).then((response) => { | ||
const status = response.isConfirmed ? value : updatableValue; | ||
self.resetSubCategory = status; | ||
|
||
self.vendorInfo.reset_sub_category = status; | ||
}); | ||
}, | ||
fixedCOmmissionhandler(data) { | ||
if (isNaN( data.fixed )) { | ||
data.fixed = this.fixedCommission.fixed ?? ''; | ||
|
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.
💡 Codebase verification
vendorInfo
is undefined and needs proper declarationAfter thorough verification,
vendorInfo
is not defined in the component's:This confirms the original review comment. The use of an undefined
vendorInfo
in a callback could lead to runtime errors.Recommendations:
vendorInfo
in the component's data() if it's local state🔗 Analysis chain
Verify vendorInfo reference.
The
vendorInfo
object is referenced but not defined in the component's data or props. This could lead to runtime errors.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 190
Script:
Length of output: 1485
Script:
Length of output: 481