Class: GetProductsByTaxon

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
app/liquid/tags/spree_tags.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ GetProductsByTaxon

Returns a new instance of GetProductsByTaxon.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/liquid/tags/spree_tags.rb', line 119

def initialize(tag_name, markup, tokens)
  unless markup.empty?
    if markup =~ /per_page:(\d+)/
      @per_page = $1.to_i
    end

    if markup =~ /taxon:([\/-_a-z0-9]+)/
      @taxon_name = $1
    end

    if markup =~ /type:([_a-z0-9]+)/
      @type = $1
    end
  end

  @per_page ||= 5

  super
end

Instance Method Details

#render(context) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'app/liquid/tags/spree_tags.rb', line 139

def render(context)
  @taxon = Spree::Taxon.find_by_permalink!(@taxon_name)
  return unless @taxon

  context[@taxon_name] = @taxon

  @searcher = Spree::Config.searcher_class.new(context.registers[:controller].params.merge(:taxon => @taxon.id))
  @searcher.current_user = context.registers[:controller].spree_current_user
  @searcher.current_currency = Spree::Config[:currency]
  @products = @searcher.retrieve_products

  if @type == 'latest'

  end

  if context['capture_variable']
    context[context['capture_variable']] = @products.per(@per_page)
  else
    context['products'] = @products.per(@per_page)
  end

  ''
end