Fix product search inputs

This commit is contained in:
Mike Jolley 2016-12-21 13:23:26 +00:00
parent 56fef5b4f6
commit 96877dbb25
9 changed files with 75 additions and 159 deletions

File diff suppressed because one or more lines are too long

View File

@ -1078,32 +1078,6 @@ ul.wc_coupon_list_block {
} }
} }
.wc-order-add-item {
background: #fff;
vertical-align: top;
border-top: none;
.add_item_id,
.select2-container {
vertical-align: top;
.search-field input {
min-width: 100px;
}
}
.select2-container {
width: 400px !important;
text-align: left;
}
.cancel-action,
.save-action,
.calculate-action {
float: left;
margin-right: 2px;
}
}
.wc-used-coupons { .wc-used-coupons {
float: left; float: left;
width: 50%; width: 50%;
@ -2567,11 +2541,6 @@ table.wc_shipping {
} }
} }
} }
.select2-container-active {
.select2-choices {
border-color: #777;
}
}
} }
.wc-shipping-zone-postcodes-toggle { .wc-shipping-zone-postcodes-toggle {
margin: 0; margin: 0;
@ -5317,6 +5286,10 @@ table.bar_chart {
min-width: 500px; min-width: 500px;
} }
} }
.select2-container {
width: 100% !important;
}
} }
.wc-backbone-modal-backdrop { .wc-backbone-modal-backdrop {
@ -5434,7 +5407,8 @@ table.bar_chart {
/** /**
* Select2 elements. * Select2 elements.
*/ */
.select2-drop { .select2-drop,
.select2-dropdown {
z-index: 999999 !important; z-index: 999999 !important;
} }
.select2-results { .select2-results {
@ -5457,6 +5431,9 @@ table.bar_chart {
.select2-selection { .select2-selection {
border-color: #ddd; border-color: #ddd;
} }
.select2-search__field {
min-width: 150px;
}
.select2-selection--single { .select2-selection--single {
height: 32px; height: 32px;
.select2-selection__rendered { .select2-selection__rendered {
@ -5468,10 +5445,10 @@ table.bar_chart {
height: 30px; height: 30px;
} }
} }
}
.select2-container--default {
.select2-selection--multiple { .select2-selection--multiple {
min-height: 28px; min-height: 28px;
border-radius: 0;
line-height: 1.5;
li { li {
margin: 0; margin: 0;
} }

View File

@ -90,9 +90,9 @@ jQuery( function( $ ) {
url: wc_enhanced_select_params.ajax_url, url: wc_enhanced_select_params.ajax_url,
dataType: 'json', dataType: 'json',
quietMillis: 250, quietMillis: 250,
data: function( term ) { data: function( params ) {
return { return {
term: term, term: params.term,
action: $( this ).data( 'action' ) || 'woocommerce_json_search_products_and_variations', action: $( this ).data( 'action' ) || 'woocommerce_json_search_products_and_variations',
security: wc_enhanced_select_params.search_products_nonce, security: wc_enhanced_select_params.search_products_nonce,
exclude: $( this ).data( 'exclude' ), exclude: $( this ).data( 'exclude' ),
@ -100,7 +100,8 @@ jQuery( function( $ ) {
limit: $( this ).data( 'limit' ) limit: $( this ).data( 'limit' )
}; };
}, },
results: function( data ) { processResults: function( data ) {
window.console.log(data);
var terms = []; var terms = [];
if ( data ) { if ( data ) {
$.each( data, function( id, text ) { $.each( data, function( id, text ) {
@ -115,34 +116,6 @@ jQuery( function( $ ) {
} }
}; };
if ( $( this ).data( 'multiple' ) === true ) {
select2_args.multiple = true;
select2_args.initSelection = function( element, callback ) {
var data = $.parseJSON( element.attr( 'data-selected' ) );
var selected = [];
$( element.val().split( ',' ) ).each( function( i, val ) {
selected.push({
id: val,
text: data[ val ]
});
});
return callback( selected );
};
select2_args.formatSelection = function( data ) {
return '<div class="selected-option" data-id="' + data.id + '">' + data.text + '</div>';
};
} else {
select2_args.multiple = false;
select2_args.initSelection = function( element, callback ) {
var data = {
id: element.val(),
text: element.attr( 'data-selected' )
};
return callback( data );
};
}
select2_args = $.extend( select2_args, getEnhancedSelectFormatString() ); select2_args = $.extend( select2_args, getEnhancedSelectFormatString() );
$( this ).select2( select2_args ).addClass( 'enhanced' ); $( this ).select2( select2_args ).addClass( 'enhanced' );
@ -157,8 +130,6 @@ jQuery( function( $ ) {
}); });
// Ajax customer search boxes // Ajax customer search boxes
$( ':input.wc-customer-search' ).filter( ':not(.enhanced)' ).each( function() { $( ':input.wc-customer-search' ).filter( ':not(.enhanced)' ).each( function() {
var select2_args = { var select2_args = {
@ -195,33 +166,6 @@ jQuery( function( $ ) {
cache: true cache: true
} }
}; };
if ( $( this ).data( 'multiple' ) === true ) {
select2_args.multiple = true;
select2_args.initSelection = function( element, callback ) {
var data = $.parseJSON( element.attr( 'data-selected' ) );
var selected = [];
$( element.val().split( ',' ) ).each( function( i, val ) {
selected.push({
id: val,
text: data[ val ]
});
});
return callback( selected );
};
select2_args.formatSelection = function( data ) {
return '<div class="selected-option" data-id="' + data.id + '">' + data.text + '</div>';
};
} else {
select2_args.multiple = false;
select2_args.initSelection = function( element, callback ) {
var data = {
id: element.val(),
text: element.attr( 'data-selected' )
};
return callback( data );
};
}
select2_args = $.extend( select2_args, getEnhancedSelectFormatString() ); select2_args = $.extend( select2_args, getEnhancedSelectFormatString() );

View File

@ -102,37 +102,35 @@ class WC_Meta_Box_Coupon_Data {
// Product ids // Product ids
?> ?>
<p class="form-field"><label><?php _e( 'Products', 'woocommerce' ); ?></label> <p class="form-field"><label><?php _e( 'Products', 'woocommerce' ); ?></label>
<input type="hidden" class="wc-product-search" data-multiple="true" style="width: 50%;" name="product_ids" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-selected="<?php <select class="wc-product-search" multiple="multiple" style="width: 50%;" name="product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
$product_ids = $coupon->get_product_ids(); <?php
$json_ids = array(); $product_ids = $coupon->get_product_ids();
foreach ( $product_ids as $product_id ) { foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id ); $product = wc_get_product( $product_id );
if ( is_object( $product ) ) { if ( is_object( $product ) ) {
$json_ids[ $product_id ] = wp_kses_post( $product->get_formatted_name() ); echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
} }
} ?>
</select> <?php echo wc_help_tip( __( 'Products which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woocommerce' ) ); ?></p>
echo esc_attr( json_encode( $json_ids ) );
?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" /> <?php echo wc_help_tip( __( 'Products which need to be in the cart to use this coupon or, for "Product Discounts", which products are discounted.', 'woocommerce' ) ); ?></p>
<?php <?php
// Exclude Product ids // Exclude Product ids
?> ?>
<p class="form-field"><label><?php _e( 'Exclude products', 'woocommerce' ); ?></label> <p class="form-field"><label><?php _e( 'Exclude products', 'woocommerce' ); ?></label>
<input type="hidden" class="wc-product-search" data-multiple="true" style="width: 50%;" name="exclude_product_ids" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-selected="<?php <select class="wc-product-search" multiple="multiple" style="width: 50%;" name="exclude_product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations">
$product_ids = $coupon->get_excluded_product_ids(); <?php
$json_ids = array(); $product_ids = $coupon->get_excluded_product_ids();
foreach ( $product_ids as $product_id ) { foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id ); $product = wc_get_product( $product_id );
if ( is_object( $product ) ) { if ( is_object( $product ) ) {
$json_ids[ $product_id ] = wp_kses_post( $product->get_formatted_name() ); echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
} }
} ?>
</select> <?php echo wc_help_tip( __( 'Products which must not be in the cart to use this coupon or, for "Product Discounts", which products are not discounted.', 'woocommerce' ) ); ?></p>
echo esc_attr( json_encode( $json_ids ) );
?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" /> <?php echo wc_help_tip( __( 'Products which must not be in the cart to use this coupon or, for "Product Discounts", which products are not discounted.', 'woocommerce' ) ); ?></p>
<?php <?php
echo '</div><div class="options_group">'; echo '</div><div class="options_group">';
@ -279,8 +277,8 @@ class WC_Meta_Box_Coupon_Data {
'amount' => wc_format_decimal( $_POST['coupon_amount'] ), 'amount' => wc_format_decimal( $_POST['coupon_amount'] ),
'date_expires' => wc_clean( $_POST['expiry_date'] ), 'date_expires' => wc_clean( $_POST['expiry_date'] ),
'individual_use' => isset( $_POST['individual_use'] ), 'individual_use' => isset( $_POST['individual_use'] ),
'product_ids' => array_filter( array_map( 'intval', explode( ',', $_POST['product_ids'] ) ) ), 'product_ids' => array_filter( array_map( 'intval', (array) $_POST['product_ids'] ) ),
'excluded_product_ids' => array_filter( array_map( 'intval', explode( ',', $_POST['exclude_product_ids'] ) ) ), 'excluded_product_ids' => array_filter( array_map( 'intval', (array) $_POST['exclude_product_ids'] ) ),
'usage_limit' => absint( $_POST['usage_limit'] ), 'usage_limit' => absint( $_POST['usage_limit'] ),
'usage_limit_per_user' => absint( $_POST['usage_limit_per_user'] ), 'usage_limit_per_user' => absint( $_POST['usage_limit_per_user'] ),
'limit_usage_to_x_items' => absint( $_POST['limit_usage_to_x_items'] ), 'limit_usage_to_x_items' => absint( $_POST['limit_usage_to_x_items'] ),

View File

@ -64,7 +64,7 @@ class WC_Meta_Box_Order_Downloads {
<div class="toolbar"> <div class="toolbar">
<p class="buttons"> <p class="buttons">
<input type="hidden" id="grant_access_id" name="grant_access_id" data-multiple="true" class="wc-product-search" style="width: 400px;" data-placeholder="<?php esc_attr_e( 'Search for a downloadable product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_downloadable_products_and_variations" /> <select id="grant_access_id" class="wc-product-search" name="grant_access_id[]" multiple="multiple" style="width: 400px;" data-placeholder="<?php esc_attr_e( 'Search for a downloadable product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_downloadable_products_and_variations"></select>
<button type="button" class="button grant_access"><?php _e( 'Grant access', 'woocommerce' ); ?></button> <button type="button" class="button grant_access"><?php _e( 'Grant access', 'woocommerce' ); ?></button>
</p> </p>
<div class="clear"></div> <div class="clear"></div>

View File

@ -166,7 +166,7 @@ class WC_Meta_Box_Product_Data {
* @return array * @return array
*/ */
private static function prepare_children() { private static function prepare_children() {
return isset( $_POST['grouped_products'] ) ? array_filter( array_map( 'intval', explode( ',', $_POST['grouped_products'] ) ) ) : array(); return isset( $_POST['grouped_products'] ) ? array_filter( array_map( 'intval', (array) $_POST['grouped_products'] ) ) : array();
} }
/** /**
@ -277,8 +277,8 @@ class WC_Meta_Box_Product_Data {
'height' => wc_clean( $_POST['_height'] ), 'height' => wc_clean( $_POST['_height'] ),
'shipping_class_id' => absint( $_POST['product_shipping_class'] ), 'shipping_class_id' => absint( $_POST['product_shipping_class'] ),
'sold_individually' => ! empty( $_POST['_sold_individually'] ), 'sold_individually' => ! empty( $_POST['_sold_individually'] ),
'upsell_ids' => array_map( 'intval', explode( ',', $_POST['upsell_ids'] ) ), 'upsell_ids' => array_map( 'intval', (array) $_POST['upsell_ids'] ),
'cross_sell_ids' => array_map( 'intval', explode( ',', $_POST['crosssell_ids'] ) ), 'cross_sell_ids' => array_map( 'intval', (array) $_POST['crosssell_ids'] ),
'regular_price' => wc_clean( $_POST['_regular_price'] ), 'regular_price' => wc_clean( $_POST['_regular_price'] ),
'sale_price' => wc_clean( $_POST['_sale_price'] ), 'sale_price' => wc_clean( $_POST['_sale_price'] ),
'date_on_sale_from' => wc_clean( $_POST['_sale_price_dates_from'] ), 'date_on_sale_from' => wc_clean( $_POST['_sale_price_dates_from'] ),

View File

@ -283,7 +283,7 @@ if ( wc_tax_enabled() ) {
</header> </header>
<article> <article>
<form action="" method="post"> <form action="" method="post">
<input type="hidden" id="add_item_id" name="add_order_items" class="wc-product-search" style="width: 100%;" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-multiple="true" /> <select class="wc-product-search" multiple="multiple" style="width: 50%;" id="add_item_id" name="add_order_items" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>"></select>
</form> </form>
</article> </article>
<footer> <footer>

View File

@ -3,53 +3,50 @@
<div class="options_group"> <div class="options_group">
<p class="form-field"> <p class="form-field">
<label for="upsell_ids"><?php _e( 'Up-sells', 'woocommerce' ); ?></label> <label for="upsell_ids"><?php _e( 'Up-sells', 'woocommerce' ); ?></label>
<input type="hidden" class="wc-product-search" style="width: 50%;" id="upsell_ids" name="upsell_ids" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-multiple="true" data-exclude="<?php echo intval( $post->ID ); ?>" data-selected="<?php <select class="wc-product-search" multiple="multiple" style="width: 50%;" id="upsell_ids" name="upsell_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-exclude="<?php echo intval( $post->ID ); ?>">
$product_ids = $product_object->get_upsell_ids( 'edit' ); <?php
$json_ids = array(); $product_ids = $product_object->get_upsell_ids( 'edit' );
foreach ( $product_ids as $product_id ) { foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id ); $product = wc_get_product( $product_id );
if ( is_object( $product ) ) { if ( is_object( $product ) ) {
$json_ids[ $product_id ] = wp_kses_post( html_entity_decode( $product->get_formatted_name(), ENT_QUOTES, get_bloginfo( 'charset' ) ) ); echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
} }
} ?>
</select> <?php echo wc_help_tip( __( 'Up-sells are products which you recommend instead of the currently viewed product, for example, products that are more profitable or better quality or more expensive.', 'woocommerce' ) ); ?>
echo esc_attr( json_encode( $json_ids ) );
?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" /> <?php echo wc_help_tip( __( 'Up-sells are products which you recommend instead of the currently viewed product, for example, products that are more profitable or better quality or more expensive.', 'woocommerce' ) ); ?>
</p> </p>
<p class="form-field"> <p class="form-field">
<label for="crosssell_ids"><?php _e( 'Cross-sells', 'woocommerce' ); ?></label> <label for="crosssell_ids"><?php _e( 'Cross-sells', 'woocommerce' ); ?></label>
<input type="hidden" class="wc-product-search" style="width: 50%;" id="crosssell_ids" name="crosssell_ids" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-multiple="true" data-exclude="<?php echo intval( $post->ID ); ?>" data-selected="<?php <select class="wc-product-search" multiple="multiple" style="width: 50%;" id="crosssell_ids" name="crosssell_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" data-exclude="<?php echo intval( $post->ID ); ?>">
$product_ids = $product_object->get_cross_sell_ids( 'edit' ); <?php
$json_ids = array(); $product_ids = $product_object->get_cross_sell_ids( 'edit' );
foreach ( $product_ids as $product_id ) { foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id ); $product = wc_get_product( $product_id );
if ( is_object( $product ) ) { if ( is_object( $product ) ) {
$json_ids[ $product_id ] = wp_kses_post( html_entity_decode( $product->get_formatted_name(), ENT_QUOTES, get_bloginfo( 'charset' ) ) ); echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
}
} }
} ?>
</select> <?php echo wc_help_tip( __( 'Cross-sells are products which you promote in the cart, based on the current product.', 'woocommerce' ) ); ?>
echo esc_attr( json_encode( $json_ids ) );
?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" /> <?php echo wc_help_tip( __( 'Cross-sells are products which you promote in the cart, based on the current product.', 'woocommerce' ) ); ?>
</p> </p>
<p class="form-field show_if_grouped"> <p class="form-field show_if_grouped">
<label for="grouped_products"><?php _e( 'Grouped products', 'woocommerce' ); ?></label> <label for="grouped_products"><?php _e( 'Grouped products', 'woocommerce' ); ?></label>
<input type="hidden" class="wc-product-search" style="width: 50%;" id="grouped_products" name="grouped_products" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products" data-multiple="true" data-exclude="<?php echo intval( $post->ID ); ?>" data-selected="<?php <select class="wc-product-search" multiple="multiple" style="width: 50%;" id="grouped_products" name="grouped_products[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products" data-exclude="<?php echo intval( $post->ID ); ?>">
$product_ids = $product_object->get_children( 'edit' ); <?php
$json_ids = array(); $product_ids = $product_object->get_children( 'edit' );
foreach ( $product_ids as $product_id ) { foreach ( $product_ids as $product_id ) {
$product = wc_get_product( $product_id ); $product = wc_get_product( $product_id );
if ( is_object( $product ) ) { if ( is_object( $product ) ) {
$json_ids[ $product_id ] = wp_kses_post( html_entity_decode( $product->get_formatted_name(), ENT_QUOTES, get_bloginfo( 'charset' ) ) ); echo '<option value="' . esc_attr( $product_id ) . '"' . selected( true, true, false ) . '>' . wp_kses_post( $product->get_formatted_name() ) . '</option>';
} }
} }
?>
echo esc_attr( json_encode( $json_ids ) ); </select> <?php echo wc_help_tip( __( 'This lets you choose which products are part of this group.', 'woocommerce' ) ); ?>
?>" value="<?php echo implode( ',', array_keys( $json_ids ) ); ?>" /> <?php echo wc_help_tip( __( 'This lets you choose which products are part of this group.', 'woocommerce' ) ); ?>
</p> </p>
</div> </div>

View File

@ -201,7 +201,7 @@ class WC_Report_Sales_By_Product extends WC_Admin_Report {
<div class="section"> <div class="section">
<form method="GET"> <form method="GET">
<div> <div>
<input type="hidden" class="wc-product-search" style="width:203px;" name="product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations" /> <select class="wc-product-search" style="width:203px;" multiple="multiple" id="product_ids" name="product_ids[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>" data-action="woocommerce_json_search_products_and_variations"></select>
<input type="submit" class="submit button" value="<?php esc_attr_e( 'Show', 'woocommerce' ); ?>" /> <input type="submit" class="submit button" value="<?php esc_attr_e( 'Show', 'woocommerce' ); ?>" />
<input type="hidden" name="range" value="<?php if ( ! empty( $_GET['range'] ) ) echo esc_attr( $_GET['range'] ) ?>" /> <input type="hidden" name="range" value="<?php if ( ! empty( $_GET['range'] ) ) echo esc_attr( $_GET['range'] ) ?>" />
<input type="hidden" name="start_date" value="<?php if ( ! empty( $_GET['start_date'] ) ) echo esc_attr( $_GET['start_date'] ) ?>" /> <input type="hidden" name="start_date" value="<?php if ( ! empty( $_GET['start_date'] ) ) echo esc_attr( $_GET['start_date'] ) ?>" />