2016-04-29 6 views
1

スプールのサイドバーで価格の範囲を修正したい、デフォルトの範囲が良くないため。私はたくさん試しましたが、できないので、助けてください。スプーン価格の範囲の変更

答えて

2

このようなカスタムスライダを使用できます。 _custom_sidebar.html.erbをオーバーライドし、次の行

<span for="amount" class="filter-hd">Price range</span> 
<hr class="myhr2"> 
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;"> 
<div id="slider-range"></div> 

を追加jQueryのUIのスライダーを含めると、下記のようスライダーを開始します。

<script> 
    $(function() { 
     $("#slider-range").slider({ 
      range: true, 
      min: 0, 
      max: 5000, 
      /* jshint ignore:start */ 
      values: [ <%= params.key?(:minprice) ? params[:minprice].to_i : 0 %>, <%= params.key?(:maxprice) ? params[:maxprice].to_i : 1000 %> ], 
      slide: function(event, ui) { 
       $("#amount").val("<%= current_currency %>" + ui.values[ 0 ] + " - <%= current_currency %>" + ui.values[ 1 ]); 
      }, 
      /* jshint ignore:end */ 
      change: function(event, ui) { 
       url = window.location.href; 
       newmin = ui.values[ 0 ]; 
       newmax = ui.values[ 1 ]; 
       url = updateURLParameter(url, 'minprice', newmin); 
       url = updateURLParameter(url, 'maxprice', newmax); 
       window.location.href = url; 
      } 
     }); 
     $("#amount").val("<%= current_currency %>" + $("#slider-range").slider("values", 0) + 
    " - <%= current_currency %>" + $("#slider-range").slider("values", 1)); 
    }); 
</script> 

ここはjavascript function updateURLParameter which is used in the above js snippetです。 jsファイルに追加することができます。

またこれは、ファイル内になる価格フィルタリング

@products = @products.price_between(params[:minprice], params[:maxprice]) if params.key?(:minprice) && params.key?(:maxprice) 

を含めることTaxons_controllerProducts_controllerを飾る - アプリ/コントローラ/酒宴/ products_controller_decorator.rbアプリ/コントローラ/酒宴/ taxons_controller_decorator.rbを

products_controller_decorator.rb -

# Custom methods for products related stuff 
module Spree 
    ProductsController.class_eval do 
    alias_method :old_index, :index 

    def index 
    old_index # Like calling super: http://stackoverflow.com/a/13806783/73673 
    @products = @products.price_between(params[:minprice], params[:maxprice]) if params.key?(:minprice) && params.key?(:maxprice) 
    @products = @products.in_name_or_description(params[:query]) if params.key?(:query) 
    end 
end 

taxons_controller_decorator.rbでは、メソッドshowについても同じことができます。

+0

それを見ていただきありがとうございますが、動作していないため、コントローラにコードをコピーするたびにエラーが発生します –

+0

これを含む場所にコントローラデコレータメソッドを投稿できますか? – Sebin

+0

私はちょうど表示アクションでコントローラにコピーしました –

関連する問題