Introduce Spree::ItemAdjustments class

This commit is contained in:
Matt-Yorkley
2021-02-07 13:07:33 +00:00
parent 45f0082321
commit ac9ecdfcbc

View File

@@ -0,0 +1,28 @@
# frozen_string_literal: true
module Spree
# Manage (recalculate) item (LineItem or Shipment) adjustments
class ItemAdjustments
attr_reader :item
delegate :adjustments, :order, to: :item
def initialize(item)
@item = item
end
def update
update_adjustments if item.persisted?
item
end
def update_adjustments
adjustment_total = adjustments.map(&:update!).compact.sum
item.update_columns(
adjustment_total: adjustment_total,
updated_at: Time.zone.now
)
end
end
end