2013-11-27 105 views
0

我有一個狂熱的商業導軌應用程序,我想在前端添加一些用戶控制的產品排序,在產品範圍內有一些簡單的範圍已經定義,但我不確定如何顯示它們在我的看法。Spree Commerce產品分類

只需簡單的鏈接就可以了,現在我可以擴展。

下面是我可以使用的範圍,道歉的鏈接,但它太複製和粘貼。

https://github.com/spree/spree/blob/2-0-stable/core/app/models/spree/product/scopes.rb

回答

0

應用程序/模型/大禮包/ product_sorting_decorator.rb

module Spree 
    Product.class_eval do 

      attr_accessible :variable_1, :variable_2, 
          :variable_3, :variable_4, :as => [:default, :user] 

      def put_your_sorting_method_here 
       #your logic goes here 
      end 
    end 

end 

讓我們覆蓋控制器: 應用程序/控制器/大禮包/ products_controller.rb

Spree::ProductsController.class_eval do 

     def sorting_action 
     #your logic goes here and get the sorted list of product @product 
     # by accessing the method defined in model file 
     end 

end 

在瀏覽網頁(products/index.html.erb):

這裏只是通過標記行來調用控制器操作:remote => true並使用@product作爲排序後的產品列表。