Sha256: 1030e5ac2db00cb5368d04cbefa1a5b9e77ecbc0c6504cfc4b5835a267c73635

Contents?: true

Size: 832 Bytes

Versions: 27

Compression:

Stored size: 832 Bytes

Contents

module Spree
  module AdjustmentSource
    extend ActiveSupport::Concern

    included do
      def deals_with_adjustments_for_deleted_source
        adjustment_scope = self.adjustments.includes(:order).references(:spree_orders)

        # For incomplete orders, remove the adjustment completely.
        adjustment_scope.where("spree_orders.completed_at IS NULL").destroy_all

        # For complete orders, the source will be invalid.
        # Therefore we nullify the source_id, leaving the adjustment in place.
        # This would mean that the order's total is not altered at all.
        adjustment_scope.where("spree_orders.completed_at IS NOT NULL").each do |adjustment|
          adjustment.update_columns(
            source_id: nil,
            updated_at: Time.now,
          )
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
solidus_core-1.0.7 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.6 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.5 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.4 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.3 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.2 app/models/concerns/spree/adjustment_source.rb
spree_core-2.4.10 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.1 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.0 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.0.rc2 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.0.rc1 app/models/concerns/spree/adjustment_source.rb
spree_core-2.4.9 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.0.pre3 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.0.pre2 app/models/concerns/spree/adjustment_source.rb
spree_core-2.4.8 app/models/concerns/spree/adjustment_source.rb
solidus_core-1.0.0.pre app/models/concerns/spree/adjustment_source.rb
spree_core-2.4.7 app/models/concerns/spree/adjustment_source.rb
spree_core-2.4.6 app/models/concerns/spree/adjustment_source.rb
spree_core-2.4.5 app/models/concerns/spree/adjustment_source.rb
spree_core-2.4.4 app/models/concerns/spree/adjustment_source.rb