Sha256: eca8a1e5825ba82bb23c820f5d0aa42421c48af4feeffb4cceadf73d2b2b6602

Contents?: true

Size: 1.24 KB

Versions: 36

Compression:

Stored size: 1.24 KB

Contents

module Spree
  module Admin
    class AdjustmentsController < ResourceController
      belongs_to 'spree/order', find_by: :number

      create.after :update_totals
      destroy.after :update_totals
      update.after :update_totals

      skip_before_action :load_resource, only: [:toggle_state, :edit, :update, :destroy]

      before_action :find_adjustment, only: [:destroy, :edit, :update]

      after_action :delete_promotion_from_order, only: [:destroy], if: -> { @adjustment.destroyed? && @adjustment.promotion? }

      def index
        @adjustments = @order.all_adjustments.eligible.order(created_at: :asc)
      end

      private

      def find_adjustment
        # Need to assign to @object here to keep ResourceController happy
        @adjustment = @object = parent.all_adjustments.find(params[:id])
      end

      def update_totals
        @order.reload.update_with_updater!
      end

      # Override method used to create a new instance to correctly
      # associate adjustment with order
      def build_resource
        parent.adjustments.build(order: parent)
      end

      def delete_promotion_from_order
        return if @adjustment.source.nil?

        @order.promotions.delete(@adjustment.source.promotion)
      end
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
spree_backend-4.8.3 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.8.2 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.8.1 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.2.7 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.3.3 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.7.2 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.6.2 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.7.1 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.7.0 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.6.1 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.6.0 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.5.1 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.5.0 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.2.6 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.3.2 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.4.1 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.4.0 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.4.0.rc2 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.3.1 app/controllers/spree/admin/adjustments_controller.rb
spree_backend-4.4.0.rc1 app/controllers/spree/admin/adjustments_controller.rb