1
的變化幅度我想修改的大禮包側欄中的價格區間,因爲默認範圍是不好的。我已經嘗試了很多,但無法這樣做,請幫助。大禮包價格過濾
的變化幅度我想修改的大禮包側欄中的價格區間,因爲默認範圍是不好的。我已經嘗試了很多,但無法這樣做,請幫助。大禮包價格過濾
你可以使用自定義的滑塊這樣。覆蓋_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文件中。
另外裝飾Taxons_controller
和Products_controller
包括價格濾波
@products = @products.price_between(params[:minprice], params[:maxprice]) if params.key?(:minprice) && params.key?(:maxprice)
這將是裏面的文件 - 應用程序/控制器/禮包/ 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
方法執行相同的操作。
感謝尋找到它,但它不工作,得到一個錯誤,每當複製你的代碼到控制器 –
你能後,你包括在該控制器的裝飾方法是什麼? – Sebin
我剛纔在控制器中複製了show action –