How do you selectively target a filter at a specific taxon?

65 views
Skip to first unread message

Greg Murray

unread,
Jul 18, 2012, 8:53:46 PM7/18/12
to spree...@googlegroups.com
I have created various filters based on new properties I have set up.  I only want to display certain filters under a specific taxon.  What is the cleanest spree way to do this?  For example I would like the material filter only to be shown when the taxon is clothing.  Below is part of the code I have copied over into my directory (models/spree/taxon.rb).



    # indicate which filters should be used for a taxon
    # this method should be customized to your own site
 
   def applicable_filters
      fs = []
      # fs << ProductFilters.taxons_below(self)
      ## unless it's a root taxon? left open for demo purposes

      fs << ProductFilters.price_filter if ProductFilters.respond_to?(:price_filter)
      fs << ProductFilters.color_filter if ProductFilters.respond_to?(:color_filter)
      fs << ProductFilters.material_filter if ProductFilters.respond_to?(:material_filter)
      fs << ProductFilters.pattern_filter if ProductFilters.respond_to?(:pattern_filter)
      fs << ProductFilters.brand_filter if ProductFilters.respond_to?(:brand_filter)
    end

Thank you in advance for your help!

Ryan Bigg

unread,
Jul 20, 2012, 2:29:28 AM7/20/12
to spree...@googlegroups.com
Couldn't you just throw an if statement in there to check the Taxon's name? Given that the method is available on the instance of Taxon objects, I would imagine it would be that simple.

Unless I'm missing something?

Also: you should be using a decorator to alter this method rather than copying it over into models/spree/taxon.rb. Those are covered in the Logic Customization guide here: http://guides.spreecommerce.com/logic_customization.html
--
You received this message because you are subscribed to the Google Groups "Spree" group.
To view this discussion on the web visit https://groups.google.com/d/msg/spree-user/-/Kc2IJN1q6IkJ.
To post to this group, send email to spree...@googlegroups.com.
To unsubscribe from this group, send email to spree-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/spree-user?hl=en.

Reply all
Reply to author
Forward
0 new messages