class Dugway::Drops::ProductsDrop

Public Instance Methods

all() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 6
def all
  sort_and_paginate source
end
current() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 10
def current
  sort_and_paginate begin
    if artist.present?
      dropify store.artist_products(artist)
    elsif category.present?
      dropify store.category_products(category)
    elsif search_terms.present?
      dropify store.search_products(search_terms)
    else
      source
    end
  end
end
on_sale() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 24
def on_sale
  sort_and_paginate source.select { |p| p['on_sale'] }
end

Private Instance Methods

artist() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 61
def artist
  @context.registers[:artist]['permalink'] rescue @context.registers[:params]['artist']
end
category() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 65
def category
  @context.registers[:category]['permalink'] rescue @context.registers[:params]['category']
end
dropify(products) click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 93
def dropify(products)
  products.map { |p| ProductDrop.new(p) }
end
order() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 30
def order
  if @context['internal']
    case @context['internal']['order']
    when 'newest', 'date'
      'date'
    # We don't pass these in the API, so fake it
    when 'sales', 'sells', 'views'
      'shuffle'
    else
      'position'
    end
  else
    'position'
  end
end
page() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 73
def page
  if @context['internal'].present? && @context['internal'].has_key?('page') # has_key? here because 'page' will be nil for get blocks
    @context['internal']['page']
  else
    @context.registers[:params][:page] if @context.registers[:params]
  end
end
per_page() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 81
def per_page
  per_page = if @context['internal'] and @context['internal']['per_page'].present?
    @context['internal']['per_page']
  elsif theme.settings['products_per_page']
    theme.settings['products_per_page']
  else
    100
  end

  per_page.to_i
end
search_terms() click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 69
def search_terms
  params[:search]
end
sort_and_paginate(array) click to toggle source
# File lib/dugway/liquid/drops/products_drop.rb, line 46
def sort_and_paginate(array)
  if order == 'shuffle'
    array.shuffle!
  elsif order == 'date'
    array.sort! { |a,b| b['id'] <=> a['id'] }
  else
    array.sort_by! { |p| p[order] }
  end

 array.paginate({
   :page => (page || 1),
   :per_page => per_page
 })
end