Skip to content

Commit

Permalink
fix: product search select js issues, tag search and placeholder and …
Browse files Browse the repository at this point in the history
…language issues fixed
  • Loading branch information
sabbir1991 committed Sep 15, 2020
1 parent c37e07e commit 71b37be
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 199 deletions.
151 changes: 69 additions & 82 deletions assets/js/dokan.js
Original file line number Diff line number Diff line change
Expand Up @@ -758,17 +758,78 @@ jQuery(function($) {
},

bindProductTagDropdown: function () {
if ( dokan.product_vendors_can_create_tags && 'on' === dokan.product_vendors_can_create_tags ) {
return;
}
$(".product_tag_search").select2({
allowClear: false,
tags: ( dokan.product_vendors_can_create_tags && 'on' === dokan.product_vendors_can_create_tags ),
ajax: {
url: dokan.ajaxurl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term,
action: 'dokan_json_search_products_tags',
security: dokan.search_products_tags_nonce,
page: params.page || 1
};
},
processResults: function( data ) {
var options = [];
if ( data ) {
$.each( data, function( index, text ) {
options.push( { id: text[0], text: text[1] } );
});
}

$( '#product_tag' ).select2( {
return {
results: options,
pagination: {
more: options.length == 0 ? false : true
}
};
},
cache: true
},
language: {
noResults: function () {
return dokan.i18n_no_result_found;
errorLoading: function() {
return dokan.i18n_searching;
},
inputTooLong: function( args ) {
var overChars = args.input.length - args.maximum;

if ( 1 === overChars ) {
return dokan.i18n_input_too_long_1;
}

return dokan.i18n_input_too_long_n.replace( '%qty%', overChars );
},
inputTooShort: function( args ) {
var remainingChars = args.minimum - args.input.length;

if ( 1 === remainingChars ) {
return dokan.i18n_input_too_short_1;
}

return dokan.i18n_input_too_short_n.replace( '%qty%', remainingChars );
},
loadingMore: function() {
return dokan.i18n_load_more;
},
maximumSelected: function( args ) {
if ( args.maximum === 1 ) {
return dokan.i18n_selection_too_long_1;
}

return dokan.i18n_selection_too_long_n.replace( '%qty%', args.maximum );
},
noResults: function() {
return dokan.i18n_no_matches;
},
searching: function() {
return dokan.i18n_searching;
}
}
} );
},
});
},

addProductPopup: function (e) {
Expand Down Expand Up @@ -1499,80 +1560,6 @@ jQuery(function($) {
};
}

// $('body').on( 'keyup', '.dokan-product-sales-price, .dokan-product-regular-price', debounce_delay( function(evt) {
// evt.preventDefault();
// var product_price = $( 'input.dokan-product-regular-price' ).val();
// var sale_price_wrap = $( 'input.dokan-product-sales-price' );
// var sale_price = sale_price_wrap.val();
// var sale_price_input_div = sale_price_wrap.parent( 'div.dokan-input-group' );
// var sale_price_input_msg = "<span class='error'>" + dokan.i18n_sales_price_error + "</span>";
// var sale_price_parent_div = sale_price_input_div.parent( 'div.sale-price' ).find( 'span.error' );

// if ( '' == product_price ) {

// sale_price_parent_div.remove();
// sale_price_input_div.after( sale_price_input_msg );

// sale_price_wrap.val('');
// setTimeout(function(){
// sale_price_parent_div.remove();
// }, 5000);

// } else if( parseFloat( product_price ) <= parseFloat( sale_price ) ) {

// sale_price_parent_div.remove();
// sale_price_input_div.after( sale_price_input_msg );

// sale_price_wrap.val('');
// setTimeout(function(){
// sale_price_parent_div.remove();
// }, 5000);

// } else {

// sale_price_parent_div.remove();

// }

// } ,600 ) );

});

$(document).ready(function () {
// Ajax search products tags
$(".product_tag_search").select2({
allowClear: false,
tags: true,
ajax: {
url: dokan.ajaxurl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term,
action: 'dokan_json_search_products_tags',
security: dokan.search_products_tags_nonce,
page: params.page || 1
};
},
processResults: function( data ) {
var options = [];
if ( data ) {
$.each( data, function( index, text ) {
options.push( { id: text[0], text: text[1] } );
});
}

return {
results: options,
pagination: {
more: options.length == 0 ? false : true
}
};
},
cache: true
}
});
});

})(jQuery);
Expand Down
151 changes: 69 additions & 82 deletions assets/src/js/product-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,78 @@
},

bindProductTagDropdown: function () {
if ( dokan.product_vendors_can_create_tags && 'on' === dokan.product_vendors_can_create_tags ) {
return;
}
$(".product_tag_search").select2({
allowClear: false,
tags: ( dokan.product_vendors_can_create_tags && 'on' === dokan.product_vendors_can_create_tags ),
ajax: {
url: dokan.ajaxurl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term,
action: 'dokan_json_search_products_tags',
security: dokan.search_products_tags_nonce,
page: params.page || 1
};
},
processResults: function( data ) {
var options = [];
if ( data ) {
$.each( data, function( index, text ) {
options.push( { id: text[0], text: text[1] } );
});
}

$( '#product_tag' ).select2( {
return {
results: options,
pagination: {
more: options.length == 0 ? false : true
}
};
},
cache: true
},
language: {
noResults: function () {
return dokan.i18n_no_result_found;
errorLoading: function() {
return dokan.i18n_searching;
},
inputTooLong: function( args ) {
var overChars = args.input.length - args.maximum;

if ( 1 === overChars ) {
return dokan.i18n_input_too_long_1;
}

return dokan.i18n_input_too_long_n.replace( '%qty%', overChars );
},
inputTooShort: function( args ) {
var remainingChars = args.minimum - args.input.length;

if ( 1 === remainingChars ) {
return dokan.i18n_input_too_short_1;
}

return dokan.i18n_input_too_short_n.replace( '%qty%', remainingChars );
},
loadingMore: function() {
return dokan.i18n_load_more;
},
maximumSelected: function( args ) {
if ( args.maximum === 1 ) {
return dokan.i18n_selection_too_long_1;
}

return dokan.i18n_selection_too_long_n.replace( '%qty%', args.maximum );
},
noResults: function() {
return dokan.i18n_no_matches;
},
searching: function() {
return dokan.i18n_searching;
}
}
} );
},
});
},

addProductPopup: function (e) {
Expand Down Expand Up @@ -896,80 +957,6 @@
};
}

// $('body').on( 'keyup', '.dokan-product-sales-price, .dokan-product-regular-price', debounce_delay( function(evt) {
// evt.preventDefault();
// var product_price = $( 'input.dokan-product-regular-price' ).val();
// var sale_price_wrap = $( 'input.dokan-product-sales-price' );
// var sale_price = sale_price_wrap.val();
// var sale_price_input_div = sale_price_wrap.parent( 'div.dokan-input-group' );
// var sale_price_input_msg = "<span class='error'>" + dokan.i18n_sales_price_error + "</span>";
// var sale_price_parent_div = sale_price_input_div.parent( 'div.sale-price' ).find( 'span.error' );

// if ( '' == product_price ) {

// sale_price_parent_div.remove();
// sale_price_input_div.after( sale_price_input_msg );

// sale_price_wrap.val('');
// setTimeout(function(){
// sale_price_parent_div.remove();
// }, 5000);

// } else if( parseFloat( product_price ) <= parseFloat( sale_price ) ) {

// sale_price_parent_div.remove();
// sale_price_input_div.after( sale_price_input_msg );

// sale_price_wrap.val('');
// setTimeout(function(){
// sale_price_parent_div.remove();
// }, 5000);

// } else {

// sale_price_parent_div.remove();

// }

// } ,600 ) );

});

$(document).ready(function () {
// Ajax search products tags
$(".product_tag_search").select2({
allowClear: false,
tags: true,
ajax: {
url: dokan.ajaxurl,
dataType: 'json',
delay: 250,
data: function (params) {
return {
q: params.term,
action: 'dokan_json_search_products_tags',
security: dokan.search_products_tags_nonce,
page: params.page || 1
};
},
processResults: function( data ) {
var options = [];
if ( data ) {
$.each( data, function( index, text ) {
options.push( { id: text[0], text: text[1] } );
});
}

return {
results: options,
pagination: {
more: options.length == 0 ? false : true
}
};
},
cache: true
}
});
});

})(jQuery);
7 changes: 3 additions & 4 deletions includes/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,15 +636,14 @@ public function crop_store_banner() {
public function json_search_product() {
check_ajax_referer( 'search-products', 'security' );

$term = ! empty( $_GET['term'] ) ? sanitize_text_field( wp_unslash( $_GET['term'] ) ) : '';
$include_variations = ! empty( $_GET['include_variations'] ) ? true : false;
$user_ids = ! empty( $_GET['user_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['user_ids'] ) ) : false;
$term = ! empty( $_GET['term'] ) ? sanitize_text_field( wp_unslash( $_GET['term'] ) ) : '';
$user_ids = ! empty( $_GET['user_ids'] ) ? sanitize_text_field( wp_unslash( $_GET['user_ids'] ) ) : false;

if ( empty( $term ) ) {
wp_die();
}

$ids = dokan_search_seller_products( $term, $user_ids, '', (bool) $include_variations );
$ids = dokan_search_seller_products( $term, $user_ids, '', true );

if ( ! empty( $_GET['exclude'] ) ) {
$ids = array_diff( $ids, (array) sanitize_text_field( wp_unslash( $_GET['exclude'] ) ) );
Expand Down
2 changes: 1 addition & 1 deletion templates/products/new-product-single.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class="vendor-earning simple-product"
'hide_empty' => 0,
);
?>
<select multiple="multiple" name="product_tag[]" id="product_tag_search" class="product_tag_search product_tags dokan-form-control dokan-select2">
<select multiple="multiple" name="product_tag[]" id="product_tag_search" class="product_tag_search product_tags dokan-form-control dokan-select2" data-placeholder="<?php esc_attr_e( 'Select tags', 'dokan-lite' ); ?>">
<?php if ( ! empty( $terms ) ) : ?>
<?php foreach ( $terms as $tax_term ) : ?>
<option value="<?php echo esc_attr( $tax_term->term_id ); ?>" selected="selected" ><?php echo esc_html( $tax_term->name ); ?></option>
Expand Down
12 changes: 1 addition & 11 deletions templates/products/new-product.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,7 @@

<div class="dokan-form-group">
<label for="product_tag" class="form-label"><?php esc_html_e( 'Tags', 'dokan-lite' ); ?></label>
<?php
require_once DOKAN_LIB_DIR.'/class.taxonomy-walker.php';

$drop_down_tags = array(
'hide_empty' => 0,
);

$my_tax_terms = get_terms( 'product_tag', $drop_down_tags );
?>
<select multiple="multiple" placeholder="<?php esc_attr_e( 'Select product tags', 'dokan-lite' ); ?>" name="product_tag[]" id="product_tag_search" class="product_tags dokan-form-control dokan-select2">
</select>
<select multiple="multiple" placeholder="<?php esc_attr_e( 'Select product tags', 'dokan-lite' ); ?>" name="product_tag[]" id="product_tag_search" class="product_tag_search product_tags dokan-form-control dokan-select2" data-placeholder="<?php esc_attr_e( 'Select tags', 'dokan-lite' ); ?>"></select>
</div>

<?php do_action( 'dokan_new_product_after_product_tags' ); ?>
Expand Down
Loading

0 comments on commit 71b37be

Please sign in to comment.