0

I have a spree commerce rails app and I want to add some user controlled product sorting in the front end, within the product scope there are some simple scopes already defined but i'm unsure how to display them in my view.

Just simple links would suffice for now and then I can extend.

Here are the scopes I can use out of the box, apologies for the link but it was too much to copy and paste.

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

Dan Mitchell
  • 844
  • 2
  • 15
  • 34

1 Answers1

0

app/models/spree/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

Let's override the controller : app/controllers/spree/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

in View page (products/index.html.erb) :

here just call the controller action by marking the line :remote => true and use @product for the sorted list of products.

Ajay
  • 4,199
  • 4
  • 27
  • 47