Skip to content

Commit

Permalink
Reorder private methods
Browse files Browse the repository at this point in the history
This puts all the update and recalculate methods together.

Co-Authored-By: Adam Mueller <[email protected]>
Co-Authored-By: Benjamin Willems <[email protected]>
Co-Authored-By: Andrew Stewart <[email protected]>
Co-Authored-By: Harmony Bouvier <[email protected]>
Co-Authored-By: Jared Norman <[email protected]>
Co-Authored-By: Kendra Riga <[email protected]>
Co-Authored-By: Sofia Besenski <[email protected]>
Co-Authored-By: Chris Todorov <[email protected]>
Co-Authored-By: Tom Van Manen <[email protected]>
Co-Authored-By: Noah Silvera <[email protected]>
  • Loading branch information
11 people committed Dec 19, 2024
1 parent 9385968 commit 0b8e26d
Showing 1 changed file with 46 additions and 46 deletions.
92 changes: 46 additions & 46 deletions core/app/models/spree/in_memory_order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,24 +140,6 @@ def update_shipment_amounts(persist:)
shipments.each { _1.update_amounts(persist:) }
end

# give each of the shipments a chance to update themselves
def update_shipments
shipments.each(&:update_state)
end

def recalculate_payment_total
order.payment_total = payments.completed.includes(:refunds).sum { |payment| payment.amount - payment.refunds.sum(:amount) }
end

def recalculate_shipment_total
order.shipment_total = shipments.to_a.sum(&:cost)
recalculate_order_total
end

def recalculate_order_total
order.total = order.item_total + order.shipment_total + order.adjustment_total
end

def update_adjustment_total(persist:)
update_adjustments(persist:)

Expand All @@ -171,34 +153,6 @@ def update_adjustment_total(persist:)
recalculate_order_total
end

def recalculate_item_count
order.item_count = line_items.to_a.sum(&:quantity)
end

def recalculate_item_total
order.item_total = line_items.to_a.sum(&:amount)
recalculate_order_total
end

def persist_totals
order.save!
end

def log_state_change(name)
state = "#{name}_state"
old_state = order.public_send(state)
yield
new_state = order.public_send(state)
if old_state != new_state
order.state_changes.new(
previous_state: old_state,
next_state: new_state,
name: name,
user_id: order.user_id
)
end
end

def update_promotions
Spree::Config.promotions.order_adjuster_class.new(order).call
end
Expand Down Expand Up @@ -243,5 +197,51 @@ def update_item_totals(persist:)
end
end
end

# give each of the shipments a chance to update themselves
def update_shipments
shipments.each(&:update_state)
end

def recalculate_payment_total
order.payment_total = payments.completed.includes(:refunds).sum { |payment| payment.amount - payment.refunds.sum(:amount) }
end

def recalculate_shipment_total
order.shipment_total = shipments.to_a.sum(&:cost)
recalculate_order_total
end

def recalculate_order_total
order.total = order.item_total + order.shipment_total + order.adjustment_total
end

def recalculate_item_count
order.item_count = line_items.to_a.sum(&:quantity)
end

def recalculate_item_total
order.item_total = line_items.to_a.sum(&:amount)
recalculate_order_total
end

def persist_totals
order.save!
end

def log_state_change(name)
state = "#{name}_state"
old_state = order.public_send(state)
yield
new_state = order.public_send(state)
if old_state != new_state
order.state_changes.new(
previous_state: old_state,
next_state: new_state,
name: name,
user_id: order.user_id
)
end
end
end
end

0 comments on commit 0b8e26d

Please sign in to comment.