Class: C80Yax::AjaxController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/c80_yax/ajax_controller.rb

Instance Method Summary collapse

Instance Method Details

#fetch_itemsObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/c80_yax/ajax_controller.rb', line 4

def fetch_items

  @params = _make_params
  # params: {
  # type:'hit',
  # ajax_items: '.div_hot_items .ajax_items',
  # page: 1,
  # per_page: 4
  # slug: ...

  case @params[:type]
    when 'hit'
      @itms = Item.where(is_hit: true)
                 .includes(item_props: {prop_name: [:uom, :related]})
                 .includes(:iphotos)
                 .includes(:strsubcat)
                 .paginate(page: @params[:page], per_page: @params[:per_page])
    when 'offer'
      @itms = Item.joins(:offers)
                 .includes(item_props: {prop_name: [:uom, :related]})
                 .includes(:iphotos)
                 .includes(:strsubcat)
                 .paginate(page: @params[:page], per_page: @params[:per_page])
    when 'cat'
      @itms = C80Yax::Item.includes(item_props: {prop_name: [:uom, :related]})
                  .includes(:iphotos)
                  .includes(strsubcat: :cats)
                  .where(c80_yax_cats: {slug: params[:slug] })
                  .paginate(page: @params[:page], per_page: @params[:per_page])
    when 'strsubcat'
      @itms = C80Yax::Item.includes(item_props: {prop_name: [:uom, :related]})
                  .includes(:iphotos)
                  .includes(:strsubcat)
                  .where(c80_yax_strsubcats: {slug: params[:slug] })
                  .paginate(page: @params[:page], per_page: @params[:per_page])
  end

  @items = ItemDecorator.decorate_collection(@itms)

end