Sha256: 841a01718f534178eef84e050821e4263c696e974b5ae38af97bf4098939f1e3

Contents?: true

Size: 1.34 KB

Versions: 34

Compression:

Stored size: 1.34 KB

Contents

module Workarea
  module Admin
    class PricingOverridesController < Admin::ApplicationController
      required_permissions :orders

      before_action :find_override
      before_action :find_order

      def edit; end

      def update
        if @override.update(override_params)
          create_comment if params[:comment].present? && !request.xhr?
          update_pricing

          flash[:success] = t('workarea.admin.pricing_overrides.flash_messages.success')
          request.xhr? ? render(:edit) : redirect_to(storefront.cart_path)
        else
          flash[:error] = t('workarea.admin.pricing_overrides.flash_messages.error')
          render :edit
        end
      end

      private

      def find_override
        @override = Pricing::Override.find_or_create_by(id: params[:id])
      end

      def find_order
        @order = Admin::OrderViewModel.new(Order.find(params[:id]))
      end

      def override_params
        PricingOverrideParams.new(
          params[:override].to_unsafe_h,
          current_admin
        ).to_h
      end

      def create_comment
        @order.model.comments.create!(
          body: params[:comment],
          author_id: current_user.id
        )
      end

      def update_pricing
        shippings = Shipping.by_order(params[:id])
        Pricing.perform(@order.model, shippings)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
workarea-admin-3.4.45 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.44 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.43 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.42 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.41 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.40 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.39 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.38 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.37 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.36 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.35 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.34 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.33 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.32 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.31 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.30 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.29 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.28 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.27 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.4.26 app/controllers/workarea/admin/pricing_overrides_controller.rb