Class: SpreeCmCommissioner::EventLineItemsDateSyncer

Inherits:
BaseInteractor show all
Defined in:
app/interactors/spree_cm_commissioner/event_line_items_date_syncer.rb

Instance Method Summary collapse

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/interactors/spree_cm_commissioner/event_line_items_date_syncer.rb', line 5

def call
  return unless event.event?
  return unless event.depth == 1

  event.event_line_items.includes(:variant).find_each do |line_item|
    new_from = line_item.variant.start_date_time || event.from_date
    new_to = line_item.variant.end_date_time || event.to_date

    # Update could be failed here if case line item does not allowed to change or no longer available.
    # We can ignore this line item in this case.
    line_item.update(from_date: new_from, to_date: new_to) if line_item.from_date != new_from || line_item.to_date != new_to
  end
end