From 9a9c0fe0a1e9e65bffcf49f8c08d87c28f7d0858 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 27 Jan 2025 12:31:22 +0600 Subject: [PATCH 1/4] added commission sub-categories reset toggle. --- includes/Admin/Settings.php | 8 +++++ .../Commission/CategoryBasedCommission.vue | 18 ++++++++-- src/admin/components/Fields.vue | 1 + .../components/VendorCommissionFields.vue | 33 ++++++++++++++++++- src/admin/pages/Settings.vue | 21 ++++++++++++ 5 files changed, 78 insertions(+), 3 deletions(-) diff --git a/includes/Admin/Settings.php b/includes/Admin/Settings.php index c60ec94825..37a022eb10 100644 --- a/includes/Admin/Settings.php +++ b/includes/Admin/Settings.php @@ -556,6 +556,14 @@ public function get_settings_fields() { ], ], ], + 'reset_sub_category_when_edit_all_category' => [ + 'name' => 'reset_sub_category_when_edit_all_category', + 'label' => __( 'Apply Parent Category Commission to All Subcategories', 'dokan-lite' ), + 'desc' => __( 'Important: \'All Categories\' commission serves as your marketplace\'s default rate and cannot be empty. If 0 is given in value, then the marketplace will deduct no commission from vendors', 'dokan-lite' ), + 'type' => 'switcher', + 'default' => 'on', + 'tooltip' => __( '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' ), + ], 'commission_category_based_values' => [ 'name' => 'commission_category_based_values', 'type' => 'category_based_commission', diff --git a/src/admin/components/Commission/CategoryBasedCommission.vue b/src/admin/components/Commission/CategoryBasedCommission.vue index c380948270..2345af997d 100644 --- a/src/admin/components/Commission/CategoryBasedCommission.vue +++ b/src/admin/components/Commission/CategoryBasedCommission.vue @@ -122,6 +122,10 @@ }, items:{} } + }, + resetSubCategory: { + type: Boolean, + default: true } }, computed: { @@ -266,7 +270,10 @@ let commissions = JSON.parse( JSON.stringify( this.commission.items ) ); - let data = JSON.parse( JSON.stringify( this.commission.all ) ); + let data = this.resetSubCategory ? JSON.parse( JSON.stringify( this.commission.all ) ) : { + flat: '', + percentage: '' + }; if ( commissions.hasOwnProperty( term_id ) ) { data = commissions[term_id]; @@ -293,7 +300,10 @@ value = this.unFormatValue( value ); } this.$set( this.commission.all, commission_type, value ); - this.$set(this.commission, 'items', {}); + + let items = JSON.parse( JSON.stringify( this.commission.items ?? {} ) ); + items = this.resetSubCategory ? {} : items; + this.$set(this.commission, 'items', items); this.emitComponentChange( JSON.parse( JSON.stringify( this.commission ) ) ) }, 700 ), @@ -356,6 +366,10 @@ }, updateChildCommissionValues(parent_cat_id, commission_data) { + if ( ! this.resetSubCategory ) { + return; + } + let all_nested_children_ids = this.getChildren( parent_cat_id ); let children = JSON.parse( JSON.stringify( this.commission.items ) ); diff --git a/src/admin/components/Fields.vue b/src/admin/components/Fields.vue index bb9a9ec9ef..2916cf3526 100644 --- a/src/admin/components/Fields.vue +++ b/src/admin/components/Fields.vue @@ -105,6 +105,7 @@ diff --git a/src/admin/components/VendorCommissionFields.vue b/src/admin/components/VendorCommissionFields.vue index 03539e2bd0..8f63706f87 100644 --- a/src/admin/components/VendorCommissionFields.vue +++ b/src/admin/components/VendorCommissionFields.vue @@ -15,6 +15,16 @@ {{__( 'Set the commission type that admin will get', 'dokan-lite' )}} +
+ + +
@@ -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 }; }, @@ -98,6 +111,24 @@ export default { }, 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) => { + self.resetSubCategory = response.isConfirmed ? value : updatableValue; + }); + }, fixedCOmmissionhandler(data) { if (isNaN( data.fixed )) { data.fixed = this.fixedCommission.fixed ?? ''; diff --git a/src/admin/pages/Settings.vue b/src/admin/pages/Settings.vue index d84e30336f..93fdf723ec 100644 --- a/src/admin/pages/Settings.vue +++ b/src/admin/pages/Settings.vue @@ -741,6 +741,27 @@ } }); } + + if ( ( 'dokan_selling' in this.settingValues ) && 'reset_sub_category_when_edit_all_category' === fieldName ) { + const confirmTitle = 'on' === value ? this.__( 'Enable Commission Inheritance Setting?', 'dokan-lite' ) : this.__( 'Disable Commission Inheritance Setting?', 'dokan-lite' ); + const htmlText = 'on' === 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 = 'on' === value ? this.__( 'Enable', 'dokan-lite' ) : this.__( 'Disable', 'dokan-lite' ); + const updatableValue = 'on' === value ? 'off' : 'on'; + + Swal.fire({ + icon : 'warning', + html : htmlText, + title : confirmTitle, + showCancelButton : true, + cancelButtonText : this.__( 'Cancel', 'dokan-lite' ), + confirmButtonText : confirmBtnText, + }).then( ( response ) => { + if ( response.dismiss ) { + this.settingValues.dokan_selling.reset_sub_category_when_edit_all_category = updatableValue; + this.$emit( 'switcHandler', 'reset_sub_category_when_edit_all_category', this.settingValues.dokan_selling.reset_sub_category_when_edit_all_category ); + } + }); + } }); // Scroll into specific setting field. From 38072be0fc25701e0a88512fb86b64481d469db2 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:48:09 +0600 Subject: [PATCH 2/4] added save functionality for reset category setting --- includes/Vendor/Manager.php | 6 ++++++ includes/Vendor/Vendor.php | 10 ++++++++++ src/admin/components/VendorCommissionFields.vue | 10 +++++++++- src/admin/pages/VendorSingle.vue | 2 -- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/includes/Vendor/Manager.php b/includes/Vendor/Manager.php index 95346741d6..f7b4bc5a75 100644 --- a/includes/Vendor/Manager.php +++ b/includes/Vendor/Manager.php @@ -318,6 +318,12 @@ public function update( $vendor_id, $data = [] ) { $vendor->update_meta( 'dokan_publishing', 'no' ); } + if ( isset( $data['reset_sub_category'] ) && dokan_validate_boolean( $data['reset_sub_category'] ) ) { + $vendor->update_meta( 'reset_sub_category', 'yes' ); + } else { + $vendor->update_meta( 'reset_sub_category', 'no' ); + } + if ( ! empty( $data['admin_commission_type'] ) ) { $vendor->update_meta( 'dokan_admin_percentage_type', $data['admin_commission_type'] ); } diff --git a/includes/Vendor/Vendor.php b/includes/Vendor/Vendor.php index ae6ee2063d..cf612b2850 100644 --- a/includes/Vendor/Vendor.php +++ b/includes/Vendor/Vendor.php @@ -157,6 +157,7 @@ public function to_array() { 'registered' => $this->get_register_date(), 'payment' => $this->get_payment_profiles(), 'trusted' => $this->is_trusted(), + 'reset_sub_category' => $this->get_reset_sub_category(), 'store_open_close' => [ 'enabled' => $this->is_store_time_enabled(), 'time' => $this->get_store_time(), @@ -215,6 +216,15 @@ public function is_featured() { return 'yes' == get_user_meta( $this->id, 'dokan_feature_seller', true ); } + /** + * If reset sub category is enabled + * + * @return boolean + */ + public function get_reset_sub_category() { + return 'no' !== get_user_meta( $this->id, 'reset_sub_category', true ); + } + /** * Populate store info * diff --git a/src/admin/components/VendorCommissionFields.vue b/src/admin/components/VendorCommissionFields.vue index 8f63706f87..3bc0407beb 100644 --- a/src/admin/components/VendorCommissionFields.vue +++ b/src/admin/components/VendorCommissionFields.vue @@ -107,6 +107,11 @@ 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; }, @@ -126,7 +131,10 @@ export default { cancelButtonText: this.__("Cancel", "dokan-lite"), confirmButtonText: confirmBtnText }).then((response) => { - self.resetSubCategory = response.isConfirmed ? value : updatableValue; + const status = response.isConfirmed ? value : updatableValue; + self.resetSubCategory = status; + + self.vendorInfo.reset_sub_category = status; }); }, fixedCOmmissionhandler(data) { diff --git a/src/admin/pages/VendorSingle.vue b/src/admin/pages/VendorSingle.vue index 44081306c0..f5fe8a6509 100644 --- a/src/admin/pages/VendorSingle.vue +++ b/src/admin/pages/VendorSingle.vue @@ -681,8 +681,6 @@ export default { self.isUpdating = true; - self.store.aunshon = {}; - dokan.api.put( `/stores/${self.store.id}`, self.store ) .done( ( response ) => { self.editMode = false; From 695bf307c0518de5bd6c1ecd5a0f098a807e14f6 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Thu, 30 Jan 2025 12:17:20 +0600 Subject: [PATCH 3/4] Commission setting frontend and backend done. --- .../commission/AdminCommission.vue | 49 ++++++++++++++++--- includes/Admin/SetupWizard.php | 16 +++--- .../Commission/CategoryBasedCommission.vue | 2 +- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/assets/src/js/setup-wizard/commission/AdminCommission.vue b/assets/src/js/setup-wizard/commission/AdminCommission.vue index 1f0ee0c389..d70dc3942f 100644 --- a/assets/src/js/setup-wizard/commission/AdminCommission.vue +++ b/assets/src/js/setup-wizard/commission/AdminCommission.vue @@ -9,11 +9,20 @@
-

{{__( 'Admin Commission', 'dokan-lite' )}}

- +
+ + +
+
+

{{__( 'Admin Commission', 'dokan-lite' )}}

+ +

{{__( 'Admin Commission', 'dokan-lite' )}}

@@ -27,17 +36,19 @@ +