Module: SolidusPagy::Admin::UsersControllerDecorator

Defined in:
app/decorators/controllers/solidus_pagy/admin/users_controller_decorator.rb

Class Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/decorators/controllers/solidus_pagy/admin/users_controller_decorator.rb', line 6

def self.prepended(base)
  base.class_eval do
    def orders
      params[:q] ||= {}

      @search = ::Spree::Order.reverse_chronological.ransack(
        params[:q].merge(user_id_eq: @user.id)
      )

      @result = pagy(
        @search.result,
        page: params[:page],
        items: ::SolidusPagy.config.admin_products_per_page
      )

      @pagy = @result.first
      @orders = @result.second
    end

    def items
      params[:q] ||= {}

      @search = Spree::Order.includes(
        line_items: {
          variant: [:product, { option_values: :option_type }]
        }
      ).ransack(params[:q].merge(user_id_eq: @user.id))

      @result = pagy(
        @search.result,
        page: params[:page],
        items: ::SolidusPagy.config.admin_products_per_page
      )

      @pagy = @result.first
      @orders = @result.second
    end

    private

    def collection
      return @collection if @collection

      @search = super.ransack(params[:q])
      @collection = @search.result.includes(:spree_roles)
      @collection = @collection.includes(:spree_orders)

      @result = pagy(
        @collection,
        page: params[:page],
        items: params[:per_page]
      )

      @pagy = @result.first
      @users = @result.second
    end
  end
end