Module: SolidusPagy::Admin::StockItemsControllerDecorator

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

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

    def load_stock_management_data
      @stock_locations = ::Spree::StockLocation.accessible_by(current_ability)
      @stock_item_stock_locations = if params[:stock_location_id].present?
                                      @stock_locations.where(id: params[:stock_location_id])
                                    else
                                      @stock_locations
                                    end
      @variant_display_attributes = self.class.variant_display_attributes
      @variants = ::Spree::Config.variant_search_class.new(
        params[:variant_search_term], scope: variant_scope
      ).results
      @variants = @variants.includes(
        :images,
        stock_items: :stock_location,
        product: :variant_images
      )
      @variants = @variants.includes(option_values: :option_type)

      @result = pagy(
        @variants.order(id: :desc),
        page: params[:page],
        items: params[:per_page] || ::SolidusPagy.config.orders_per_page
      )
      @pagy = @result.first
      @variants = @result.second
    end
  end
end