Sha256: bcfe1a15cc090f758637db2e2ddb1efe233e3c7ce0eec97ddb7cb925cd198aca

Contents?: true

Size: 1.35 KB

Versions: 28

Compression:

Stored size: 1.35 KB

Contents

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

      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

28 entries across 28 versions & 1 rubygems

Version Path
workarea-admin-3.5.27 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.26 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.25 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.23 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.22 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.21 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.20 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.19 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.18 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.17 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.16 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.15 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.14 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.13 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.12 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.11 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.10 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.9 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.8 app/controllers/workarea/admin/pricing_overrides_controller.rb
workarea-admin-3.5.7 app/controllers/workarea/admin/pricing_overrides_controller.rb