Sha256: 2e48a814fee509c831d109b92497085531d66ec6f4fb9022285fee188e6fcd84

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module SolidusPagy
  module Admin
    module PromotionCodesControllerDecorator
      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

      ::Spree::Admin::PromotionCodesController.prepend(self)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_pagy-1.0.0 app/decorators/controllers/solidus_pagy/admin/promotion_codes_controller_decorator.rb