Skip to content

Commit

Permalink
fix: decimal format in user profile commissions
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbir1991 committed Jul 15, 2020
1 parent fa9b3ec commit 84b0aca
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 17 additions & 3 deletions includes/Admin/UserProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function add_meta_fields( $user ) {

$banner_width = dokan_get_option( 'store_banner_width', 'dokan_appearance', 625 );
$banner_height = dokan_get_option( 'store_banner_height', 'dokan_appearance', 300 );
$admin_commission = ( 'flat' == $admin_commission_type ) ? wc_format_localized_price( $admin_commission ) : wc_format_localized_decimal( $admin_commission );

$country_state = array(
'country' => array(
Expand Down Expand Up @@ -330,7 +331,7 @@ function add_meta_fields( $user ) {
<tr>
<th><?php esc_html_e( 'Admin Commission ', 'dokan-lite' ); ?></th>
<td>
<input type="number" min="0" class="small-text" id="admin-commission" name="dokan_admin_percentage" value="<?php echo esc_attr( $admin_commission ); ?>">
<input type="text" class="wc_input_price small-text" id="admin-commission" name="dokan_admin_percentage" value="<?php echo esc_attr( $admin_commission ); ?>">
<?php do_action( 'dokan_seller_meta_fields_after_admin_commission', $user ); ?>
<p class="combine-commission-description"><?php esc_html_e( 'It will override the default commission admin gets from each sales', 'dokan-lite' ); ?></p>
</td>
Expand Down Expand Up @@ -402,6 +403,8 @@ function add_meta_fields( $user ) {
init: function() {
$('a.dokan-banner-drag').on('click', this.imageUpload);
$('a.dokan-remove-banner-image').on('click', this.removeBanner);
$('#dokan_admin_percentage_type').on('change', this.setPriceClass );
$('#dokan_admin_percentage_type').trigger('change');
},

imageUpload: function(e) {
Expand Down Expand Up @@ -450,6 +453,17 @@ function add_meta_fields( $user ) {
wrap.addClass('dokan-hide');
instruction.removeClass('dokan-hide');
},

setPriceClass: function() {
var self = $(this),
val = self.val();

if ( 'flat' == val ) {
$('input#admin-commission').removeClass( 'wc_input_decimal' ).addClass( 'wc_input_price' );
} else {
$('input#admin-commission').removeClass( 'wc_input_price' ).addClass( 'wc_input_decimal' );
}
}
};

Dokan_Settings.init();
Expand Down Expand Up @@ -535,7 +549,7 @@ function save_meta_fields( $user_id ) {

$selling = sanitize_text_field( $post_data['dokan_enable_selling'] );
$publishing = sanitize_text_field( $post_data['dokan_publish'] );
$percentage = isset( $post_data['dokan_admin_percentage'] ) && $post_data['dokan_admin_percentage'] != '' ? floatval( $post_data['dokan_admin_percentage'] ) : '';
$percentage = isset( $post_data['dokan_admin_percentage'] ) && $post_data['dokan_admin_percentage'] != '' ? $post_data['dokan_admin_percentage'] : '';
$percentage_type = empty( $post_data['dokan_admin_percentage_type'] ) ? 'percentage' : sanitize_text_field( $post_data['dokan_admin_percentage_type'] );
$feature_seller = sanitize_text_field( $post_data['dokan_feature'] );
$store_settings = dokan_get_store_info( $user_id );
Expand Down Expand Up @@ -565,7 +579,7 @@ function save_meta_fields( $user_id ) {
update_user_meta( $user_id, 'dokan_profile_settings', $store_settings );
update_user_meta( $user_id, 'dokan_enable_selling', $selling );
update_user_meta( $user_id, 'dokan_publishing', $publishing );
update_user_meta( $user_id, 'dokan_admin_percentage', $percentage );
update_user_meta( $user_id, 'dokan_admin_percentage', wc_format_decimal( $percentage ) );
update_user_meta( $user_id, 'dokan_admin_percentage_type', $percentage_type );
update_user_meta( $user_id, 'dokan_feature_seller', $feature_seller );
update_user_meta( $user_id, 'dokan_store_name', $store_settings['store_name'] );
Expand Down
1 change: 0 additions & 1 deletion includes/Withdraw/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Manager {
public function is_valid_approval_request( $args ) {
$user_id = $args['user_id'];
$limit = $this->get_withdraw_limit();
var_dump( $limit );
$balance = round( dokan_get_seller_balance( $user_id, false ), 2 );
$amount = wc_format_decimal( $args['amount'] );
$method = $args['method'];
Expand Down

0 comments on commit 84b0aca

Please sign in to comment.