Sha256: 17ea8a5cfcbfceb769e0dab44b6fbc594cca28b8a255ed8ac43e7930868d9044

Contents?: true

Size: 1.57 KB

Versions: 69

Compression:

Stored size: 1.57 KB

Contents

module Spree
  module Admin
    class PromotionsController < ResourceController
      before_action :load_data, except: :clone

      helper 'spree/admin/promotion_rules'

      def clone
        promotion = Spree::Promotion.find(params[:id])
        duplicator = Spree::PromotionHandler::PromotionDuplicator.new(promotion)

        @new_promo = duplicator.duplicate

        if @new_promo.errors.empty?
          flash[:success] = Spree.t('promotion_cloned')
          redirect_to edit_admin_promotion_url(@new_promo)
        else
          flash[:error] = Spree.t('promotion_not_cloned', error: @new_promo.errors.full_messages.to_sentence)
          redirect_to admin_promotions_url(@new_promo)
        end
      end

      protected

      def location_after_save
        spree.edit_admin_promotion_url(@promotion)
      end

      def load_data
        @calculators = Rails.application.config.spree.calculators.promotion_actions_create_adjustments
        @promotion_categories = Spree::PromotionCategory.order(:name)
      end

      def collection
        return @collection if defined?(@collection)

        params[:q] ||= HashWithIndifferentAccess.new
        params[:q][:s] ||= 'id desc'

        @collection = super
        @search = @collection.ransack(params[:q])
        @collection = @search.result(distinct: true).
                      includes(promotion_includes).
                      page(params[:page]).
                      per(params[:per_page] || Spree::Config[:admin_promotions_per_page])
      end

      def promotion_includes
        [:promotion_actions]
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
spree_backend-4.0.9 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.1.15 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.7 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.6 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.5 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.1.14 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.0.8 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.4 app/controllers/spree/admin/promotions_controller.rb
spree_backend-3.7.14.1 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.3.1 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.1.13.1 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.0.7.1 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.3 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.2 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.1 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.0.7 app/controllers/spree/admin/promotions_controller.rb
spree_backend-3.7.14 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.0 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.0.rc5 app/controllers/spree/admin/promotions_controller.rb
spree_backend-4.2.0.rc4 app/controllers/spree/admin/promotions_controller.rb