Module: SpreeCmCommissioner::LineItemGuestsConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/spree_cm_commissioner/line_item_guests_concern.rb
Instance Method Summary collapse
- #allowed_extra_adults ⇒ Object
- #allowed_extra_kids ⇒ Object
- #allowed_total_adults ⇒ Object
- #allowed_total_kids ⇒ Object
- #extra_adults ⇒ Object
- #extra_adults? ⇒ Boolean
- #extra_kids ⇒ Object
- #extra_kids? ⇒ Boolean
- #generate_remaining_guests ⇒ Object
- #guest_options ⇒ Object
- #number_of_adults ⇒ Object
- #number_of_guests ⇒ Object
- #number_of_kids ⇒ Object
- #remaining_total_guests ⇒ Object
Instance Method Details
#allowed_extra_adults ⇒ Object
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_kids ⇒ Object
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_adults ⇒ Object
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_kids ⇒ Object
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_adults ⇒ Object
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 ('number_of_adults') return 0 unless extra_adults? ['number_of_adults'].to_i - (variant.number_of_adults * quantity) end |
#extra_adults? ⇒ 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 ('number_of_adults') ['number_of_adults'].to_i > variant.number_of_adults * quantity end |
#extra_kids ⇒ Object
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 ('number_of_kids') return 0 unless extra_kids? ['number_of_kids'].to_i - (variant.number_of_kids * quantity) end |
#extra_kids? ⇒ 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 ('number_of_kids') ['number_of_kids'].to_i > variant.number_of_kids * quantity end |
#generate_remaining_guests ⇒ Object
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_options ⇒ Object
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 ||= { 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_adults ⇒ Object
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_guests ⇒ Object
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_kids ⇒ Object
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_guests ⇒ Object
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 |