Class: Stall::ProductFilters::PropertyFilter

Inherits:
BaseFilter
  • Object
show all
Defined in:
lib/stall/product_filters/property_filter.rb

Instance Attribute Summary collapse

Attributes inherited from BaseFilter

#options, #products

Instance Method Summary collapse

Methods inherited from BaseFilter

#key, #partial_path, #rendering_options

Constructor Details

#initializePropertyFilter

Returns a new instance of PropertyFilter.



6
7
8
9
# File 'lib/stall/product_filters/property_filter.rb', line 6

def initialize(*)
  super
  @property = options[:property]
end

Instance Attribute Details

#propertyObject (readonly)

Returns the value of attribute property.



4
5
6
# File 'lib/stall/product_filters/property_filter.rb', line 4

def property
  @property
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/stall/product_filters/property_filter.rb', line 11

def available?
  @available ||= (options[:force] || collection.count > 1)
end

#collectionObject



27
28
29
30
31
# File 'lib/stall/product_filters/property_filter.rb', line 27

def collection
  @collection ||= property.property_values.joins(variants: :product)
    .where(stall_products: { id: products.select(:id) })
    .distinct
end

#labelObject



19
20
21
# File 'lib/stall/product_filters/property_filter.rb', line 19

def label
  property.name
end

#nameObject



15
16
17
# File 'lib/stall/product_filters/property_filter.rb', line 15

def name
  property.name.parameterize
end

#paramObject



23
24
25
# File 'lib/stall/product_filters/property_filter.rb', line 23

def param
  :variants_property_values_id_in
end

#partial_localsObject



33
34
35
# File 'lib/stall/product_filters/property_filter.rb', line 33

def partial_locals
  { filter: self, property: property }
end