Module: SolidusPagy::Admin::VariantsControllerDecorator

Defined in:
app/decorators/controllers/solidus_pagy/admin/variants_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
# File 'app/decorators/controllers/solidus_pagy/admin/variants_controller_decorator.rb', line 6

def self.prepended(base)
  base.class_eval do
    private

    def collection
      base_variant_scope ||= super.with_discarded if params[:deleted] == 'on'
      base_variant_scope ||= super

      search = ::Spree::Config.variant_search_class.new(
        params[:variant_search_term], scope: base_variant_scope
      )

      @result = pagy(
        search.results.includes(variant_includes),
        page: params[:page],
        items: ::Spree::Config[:admin_variants_per_page]
      )

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