Module: SpreeCmCommissioner::LineItemGuestsConcern

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb

Instance Method Summary collapse

Instance Method Details

#allowed_extra_adultsObject



21
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 21

def allowed_extra_adults = variant.allowed_extra_adults * quantity

#allowed_extra_kidsObject



22
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 22

def allowed_extra_kids = variant.allowed_extra_kids * quantity

#allowed_total_adultsObject



24
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 24

def allowed_total_adults = (variant.number_of_adults * quantity) + allowed_extra_adults

#allowed_total_kidsObject



25
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 25

def allowed_total_kids = (variant.number_of_kids * quantity) + allowed_extra_kids

#extra_adultsObject



37
38
39
40
41
42
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 37

def extra_adults
  return 0 unless valid_integer_metadata?('number_of_adults')
  return 0 unless extra_adults?

  ['number_of_adults'].to_i - (variant.number_of_adults * quantity)
end

#extra_adults?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 66

def extra_adults?
  return false unless valid_integer_metadata?('number_of_adults')

  ['number_of_adults'].to_i > variant.number_of_adults * quantity
end

#extra_kidsObject



44
45
46
47
48
49
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 44

def extra_kids
  return 0 unless valid_integer_metadata?('number_of_kids')
  return 0 unless extra_kids?

  ['number_of_kids'].to_i - (variant.number_of_kids * quantity)
end

#extra_kids?Boolean

Returns:

  • (Boolean)


72
73
74
75
76
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 72

def extra_kids?
  return false unless valid_integer_metadata?('number_of_kids')

  ['number_of_kids'].to_i > variant.number_of_kids * quantity
end

#generate_remaining_guestsObject



29
30
31
32
33
34
35
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 29

def generate_remaining_guests
  return if remaining_total_guests.zero?

  remaining_total_guests.times do
    guests.create!
  end
end

#guest_optionsObject



51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 51

def guest_options
  @guest_options ||= {
    remaining_total_guests: remaining_total_guests,
    number_of_guests: number_of_guests,
    allowed_extra_adults: allowed_extra_adults,
    allowed_extra_kids: allowed_extra_kids,
    allowed_total_adults: allowed_total_adults,
    allowed_total_kids: allowed_total_kids,
    number_of_adults: number_of_adults,
    number_of_kids: number_of_kids,
    extra_adults: extra_adults,
    extra_kids: extra_kids
  }
end

#number_of_adultsObject



17
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 17

def number_of_adults = ['number_of_adults']&.to_i || (variant.number_of_adults * quantity)

#number_of_guestsObject



19
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 19

def number_of_guests = number_of_adults + number_of_kids

#number_of_kidsObject



18
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 18

def number_of_kids = ['number_of_kids']&.to_i || (variant.number_of_kids * quantity)

#remaining_total_guestsObject



27
# File 'app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb', line 27

def remaining_total_guests = [number_of_guests - guests.size, 0].max