Module: SolidusPagy::Admin::PromotionCodesControllerDecorator

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

def self.prepended(base)
  base.class_eval do
    def index
      @promotion = ::Spree::Promotion.accessible_by(current_ability, :show)
                                     .find(params[:promotion_id])
      @promotion_codes = @promotion.promotion_codes.order(:value)

      respond_to do |format|
        format.html do
          @result = pagy(
            @promotion_codes,
            page: params[:page],
            items: 50
          )
          @pagy = @result.first
          @promotion_codes = @result.second
        end

        format.csv do
          filename = "promotion-code-list-#{@promotion.id}.csv"
          headers["Content-Type"] = "text/csv"
          headers["Content-disposition"] = "attachment; filename=\"#{filename}\""
        end
      end
    end
  end
end