Set price slider min to min price. Closes #4183

This commit is contained in:
Mike Jolley 2013-12-03 13:39:02 +00:00
parent 418a8785b0
commit 293c998a1d
3 changed files with 33 additions and 8 deletions

View File

@ -5,8 +5,8 @@ jQuery(document).ready(function($) {
$('.price_slider, .price_label').show();
// Price slider uses jquery ui
var min_price = $('.price_slider_amount #min_price').attr('data-min');
var max_price = $('.price_slider_amount #max_price').attr('data-max');
var min_price = $('.price_slider_amount #min_price').data('min');
var max_price = $('.price_slider_amount #max_price').data('max');
current_min_price = parseInt(min_price);
current_max_price = parseInt(max_price);

View File

@ -1 +1 @@
jQuery(document).ready(function(e){e("input#min_price, input#max_price").hide();e(".price_slider, .price_label").show();var t=e(".price_slider_amount #min_price").attr("data-min"),n=e(".price_slider_amount #max_price").attr("data-max");current_min_price=parseInt(t);current_max_price=parseInt(n);woocommerce_price_slider_params.min_price&&(current_min_price=parseInt(woocommerce_price_slider_params.min_price));woocommerce_price_slider_params.max_price&&(current_max_price=parseInt(woocommerce_price_slider_params.max_price));e("body").bind("price_slider_create price_slider_slide",function(t,n,r){if(woocommerce_price_slider_params.currency_pos=="left"){e(".price_slider_amount span.from").html(woocommerce_price_slider_params.currency_symbol+n);e(".price_slider_amount span.to").html(woocommerce_price_slider_params.currency_symbol+r)}else if(woocommerce_price_slider_params.currency_pos=="left_space"){e(".price_slider_amount span.from").html(woocommerce_price_slider_params.currency_symbol+" "+n);e(".price_slider_amount span.to").html(woocommerce_price_slider_params.currency_symbol+" "+r)}else if(woocommerce_price_slider_params.currency_pos=="right"){e(".price_slider_amount span.from").html(n+woocommerce_price_slider_params.currency_symbol);e(".price_slider_amount span.to").html(r+woocommerce_price_slider_params.currency_symbol)}else if(woocommerce_price_slider_params.currency_pos=="right_space"){e(".price_slider_amount span.from").html(n+" "+woocommerce_price_slider_params.currency_symbol);e(".price_slider_amount span.to").html(r+" "+woocommerce_price_slider_params.currency_symbol)}e("body").trigger("price_slider_updated",n,r)});e(".price_slider").slider({range:!0,animate:!0,min:t,max:n,values:[current_min_price,current_max_price],create:function(t,n){e(".price_slider_amount #min_price").val(current_min_price);e(".price_slider_amount #max_price").val(current_max_price);e("body").trigger("price_slider_create",[current_min_price,current_max_price])},slide:function(t,n){e("input#min_price").val(n.values[0]);e("input#max_price").val(n.values[1]);e("body").trigger("price_slider_slide",[n.values[0],n.values[1]])},change:function(t,n){e("body").trigger("price_slider_change",[n.values[0],n.values[1]])}})});
jQuery(document).ready(function(e){e("input#min_price, input#max_price").hide();e(".price_slider, .price_label").show();var t=e(".price_slider_amount #min_price").data("min"),n=e(".price_slider_amount #max_price").data("max");current_min_price=parseInt(t);current_max_price=parseInt(n);woocommerce_price_slider_params.min_price&&(current_min_price=parseInt(woocommerce_price_slider_params.min_price));woocommerce_price_slider_params.max_price&&(current_max_price=parseInt(woocommerce_price_slider_params.max_price));e("body").bind("price_slider_create price_slider_slide",function(t,n,r){if(woocommerce_price_slider_params.currency_pos=="left"){e(".price_slider_amount span.from").html(woocommerce_price_slider_params.currency_symbol+n);e(".price_slider_amount span.to").html(woocommerce_price_slider_params.currency_symbol+r)}else if(woocommerce_price_slider_params.currency_pos=="left_space"){e(".price_slider_amount span.from").html(woocommerce_price_slider_params.currency_symbol+" "+n);e(".price_slider_amount span.to").html(woocommerce_price_slider_params.currency_symbol+" "+r)}else if(woocommerce_price_slider_params.currency_pos=="right"){e(".price_slider_amount span.from").html(n+woocommerce_price_slider_params.currency_symbol);e(".price_slider_amount span.to").html(r+woocommerce_price_slider_params.currency_symbol)}else if(woocommerce_price_slider_params.currency_pos=="right_space"){e(".price_slider_amount span.from").html(n+" "+woocommerce_price_slider_params.currency_symbol);e(".price_slider_amount span.to").html(r+" "+woocommerce_price_slider_params.currency_symbol)}e("body").trigger("price_slider_updated",n,r)});e(".price_slider").slider({range:!0,animate:!0,min:t,max:n,values:[current_min_price,current_max_price],create:function(t,n){e(".price_slider_amount #min_price").val(current_min_price);e(".price_slider_amount #max_price").val(current_max_price);e("body").trigger("price_slider_create",[current_min_price,current_max_price])},slide:function(t,n){e("input#min_price").val(n.values[0]);e("input#max_price").val(n.values[1]);e("body").trigger("price_slider_slide",[n.values[0],n.values[1]])},change:function(t,n){e("body").trigger("price_slider_change",[n.values[0],n.values[1]])}})});

View File

@ -92,6 +92,15 @@ class WC_Widget_Price_Filter extends WC_Widget {
$post_min = $post_max = '';
if ( sizeof( WC()->query->layered_nav_product_ids ) === 0 ) {
$min = floor( $wpdb->get_var(
$wpdb->prepare('
SELECT min(meta_value + 0)
FROM %1$s
LEFT JOIN %2$s ON %1$s.ID = %2$s.post_id
WHERE ( meta_key = \'%3$s\' OR meta_key = \'%4$s\' )
AND meta_value != ""
', $wpdb->posts, $wpdb->postmeta, '_price', '_min_variation_price' )
) );
$max = ceil( $wpdb->get_var(
$wpdb->prepare('
SELECT max(meta_value + 0)
@ -101,6 +110,22 @@ class WC_Widget_Price_Filter extends WC_Widget {
', $wpdb->posts, $wpdb->postmeta, '_price' )
) );
} else {
$min = floor( $wpdb->get_var(
$wpdb->prepare('
SELECT min(meta_value + 0)
FROM %1$s
LEFT JOIN %2$s ON %1$s.ID = %2$s.post_id
WHERE ( meta_key =\'%3$s\' OR meta_key =\'%4$s\' )
AND meta_value != ""
AND (
%1$s.ID IN (' . implode( ',', array_map( 'absint', WC()->query->layered_nav_product_ids ) ) . ')
OR (
%1$s.post_parent IN (' . implode( ',', array_map( 'absint', WC()->query->layered_nav_product_ids ) ) . ')
AND %1$s.post_parent != 0
)
)
', $wpdb->posts, $wpdb->postmeta, '_price', '_min_variation_price'
) ) );
$max = ceil( $wpdb->get_var(
$wpdb->prepare('
SELECT max(meta_value + 0)
@ -108,13 +133,13 @@ class WC_Widget_Price_Filter extends WC_Widget {
LEFT JOIN %2$s ON %1$s.ID = %2$s.post_id
WHERE meta_key =\'%3$s\'
AND (
%1$s.ID IN (%4$s)
%1$s.ID IN (' . implode( ',', array_map( 'absint', WC()->query->layered_nav_product_ids ) ) . ')
OR (
%1$s.post_parent IN (%4$s)
%1$s.post_parent IN (' . implode( ',', array_map( 'absint', WC()->query->layered_nav_product_ids ) ) . ')
AND %1$s.post_parent != 0
)
)
', $wpdb->posts, $wpdb->postmeta, '_price', implode( ',', WC()->query->layered_nav_product_ids )
', $wpdb->posts, $wpdb->postmeta, '_price'
) ) );
}
@ -132,8 +157,8 @@ class WC_Widget_Price_Filter extends WC_Widget {
<div class="price_slider_wrapper">
<div class="price_slider" style="display:none;"></div>
<div class="price_slider_amount">
<input type="text" id="min_price" name="min_price" value="'.esc_attr( $min_price ).'" data-min="'.esc_attr( $min ).'" placeholder="'.__('Min price', 'woocommerce' ).'" />
<input type="text" id="max_price" name="max_price" value="'.esc_attr( $max_price ).'" data-max="'.esc_attr( $max ).'" placeholder="'.__( 'Max price', 'woocommerce' ).'" />
<input type="text" id="min_price" name="min_price" value="' . esc_attr( $min_price ) . '" data-min="'.esc_attr( $min ).'" placeholder="'.__('Min price', 'woocommerce' ).'" />
<input type="text" id="max_price" name="max_price" value="' . esc_attr( $max_price ) . '" data-max="'.esc_attr( $max ).'" placeholder="'.__( 'Max price', 'woocommerce' ).'" />
<button type="submit" class="button">'.__( 'Filter', 'woocommerce' ).'</button>
<div class="price_label" style="display:none;">
'.__( 'Price:', 'woocommerce' ).' <span class="from"></span> &mdash; <span class="to"></span>