Sha256: 85c9b8ee5addd54abf43e636a591ae844350ab5f2ea3f19af5dc89ec25cf0c29

Contents?: true

Size: 1.65 KB

Versions: 62

Compression:

Stored size: 1.65 KB

Contents

module Workarea
  module Admin
    class CreatePricingDiscountsController < Admin::ApplicationController
      required_permissions :marketing

      before_action :find_discount

      def index
        render :setup
      end

      def create
        @discount.attributes = params[:discount] unless @discount.new_record?

        if @discount.save
          flash[:success] = t('workarea.admin.create_pricing_discounts.flash_messages.saved')
          redirect_to publish_create_pricing_discount_path(@discount, type: params[:type])
        else
          render :rules, status: :unprocessable_entity
        end
      end

      def edit
        render :setup
      end

      def details
      end

      def rules
      end

      def publish
      end

      def save_publish
        publish = SavePublishing.new(@discount, params)

        if publish.perform
          flash[:success] = t('workarea.admin.create_pricing_discounts.flash_messages.created')
          redirect_to pricing_discount_path(@discount)
        else
          flash[:error] = publish.errors.full_messages
          render :publish
        end
      end

      def destroy
        @discount.destroy
        redirect_to create_pricing_discounts_path
      end

      private

      def find_discount
        model = if params[:id].present?
                  Pricing::Discount.find(params[:id])
                elsif params[:type].present?
                  NewDiscount.new_discount(params[:type], params[:discount])
                else
                  Pricing::Discount.new(params[:discount])
                end

        @discount = DiscountViewModel.wrap(model, view_model_options)
      end
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.45 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.44 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.43 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.42 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.41 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.40 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.39 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.38 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/create_pricing_discounts_controller.rb
workarea-admin-3.4.37 app/controllers/workarea/admin/create_pricing_discounts_controller.rb