Sha256: 116cfc5839ba4a06d384609769bdb5b864d98740fc407218f21753de8161960a

Contents?: true

Size: 1.27 KB

Versions: 7

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module SolidusAdmin
  class PromotionsController < SolidusAdmin::BaseController
    include SolidusAdmin::ControllerHelpers::Search

    search_scope(:active, default: true, &:active)
    search_scope(:draft) { _1.where.not(id: _1.has_actions.select(:id)) }
    search_scope(:future) { _1.has_actions.where(starts_at: Time.current..) }
    search_scope(:expired) { _1.has_actions.where(expires_at: ..Time.current) }
    search_scope(:all)

    def index
      promotions = apply_search_to(
        Spree::Promotion.order(id: :desc),
        param: :q,
      )

      set_page_and_extract_portion_from(promotions)

      respond_to do |format|
        format.html { render component('promotions/index').new(page: @page) }
      end
    end

    def destroy
      @promotions = Spree::Promotion.where(id: params[:id])

      Spree::Promotion.transaction { @promotions.destroy_all }

      flash[:notice] = t('.success')
      redirect_back_or_to promotions_path, status: :see_other
    end

    private

    def load_promotion
      @promotion = Spree::Promotion.find_by!(number: params[:id])
      authorize! action_name, @promotion
    end

    def promotion_params
      params.require(:promotion).permit(:user_id, permitted_promotion_attributes)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
solidus_legacy_promotions-4.5.1 lib/controllers/admin/solidus_admin/promotions_controller.rb
solidus_legacy_promotions-4.5.0 lib/controllers/admin/solidus_admin/promotions_controller.rb
solidus_legacy_promotions-4.4.2 lib/controllers/admin/solidus_admin/promotions_controller.rb
solidus_legacy_promotions-4.4.1 lib/controllers/admin/solidus_admin/promotions_controller.rb
solidus_legacy_promotions-4.4.0 lib/controllers/admin/solidus_admin/promotions_controller.rb
solidus_admin-0.2.0 app/controllers/solidus_admin/promotions_controller.rb
solidus_admin-0.1.0 app/controllers/solidus_admin/promotions_controller.rb