Module: SpreeCmCommissioner::VariantOptionsConcern
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/spree_cm_commissioner/variant_options_concern.rb
Instance Method Summary collapse
- #end_date ⇒ Object
-
#end_date_time ⇒ Object
No need to fallback to event end date to avoid n+1.
- #end_time ⇒ Object
- #find_option_value_name_for(option_type_name: nil) ⇒ Object
- #option_value_name_for(option_type_name: nil) ⇒ Object
- #options ⇒ Object
- #options_in_hash ⇒ Object
- #post_paid? ⇒ Boolean
-
#set_options_to_public_metadata ⇒ Object
save optins to public_metadata so we don’t have to query option types & option values when needed them.
- #set_options_to_public_metadata! ⇒ Object
-
#start_date_time ⇒ Object
No need to fallback to event start date to avoid n+1.
Instance Method Details
#end_date ⇒ Object
74 75 76 77 78 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 74 def end_date return start_date + .total_duration_in_seconds.seconds if start_date.present? && .total_duration_in_seconds.positive? .end_date end |
#end_date_time ⇒ Object
No need to fallback to event end date to avoid n+1. To get end_time duration of event, include event when needed instead.
66 67 68 69 70 71 72 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 66 def end_date_time return nil if end_date.blank? && end_time.blank? return end_date if end_time.blank? return end_time if end_date.blank? end_date.change(hour: end_time.hour, min: end_time.min, sec: end_time.sec) end |
#end_time ⇒ Object
80 81 82 83 84 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 80 def end_time return start_time + .total_duration_in_seconds.seconds if start_time.present? && .total_duration_in_seconds.positive? .end_time end |
#find_option_value_name_for(option_type_name: nil) ⇒ Object
50 51 52 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 50 def find_option_value_name_for(option_type_name: nil) option_values.detect { |o| o.option_type.name.downcase.strip == option_type_name.downcase.strip }.try(:name) end |
#option_value_name_for(option_type_name: nil) ⇒ Object
44 45 46 47 48 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 44 def option_value_name_for(option_type_name: nil) return [option_type_name] if .present? # empty is not considered present? find_option_value_name_for(option_type_name: option_type_name) end |
#options ⇒ Object
36 37 38 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 36 def @options ||= VariantOptions.new(self) end |
#options_in_hash ⇒ Object
40 41 42 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 40 def [:cm_options] end |
#post_paid? ⇒ Boolean
86 87 88 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 86 def post_paid? .payment_option == 'post-paid' end |
#set_options_to_public_metadata ⇒ Object
save optins to public_metadata so we don’t have to query option types & option values when needed them. once variant changed, we update metadata.
92 93 94 95 96 97 98 99 100 101 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 92 def self. ||= {} = option_values.each_with_object({}) do |option_value, hash| option_type_name = option_value.option_type.name hash[option_type_name] = find_option_value_name_for(option_type_name: option_type_name) end self.[:cm_options] = end |
#set_options_to_public_metadata! ⇒ Object
103 104 105 106 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 103 def save! end |
#start_date_time ⇒ Object
No need to fallback to event start date to avoid n+1. To get end_time duration of event, include event when needed instead.
56 57 58 59 60 61 62 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 56 def start_date_time return nil if start_date.blank? && start_time.blank? return start_date if start_time.blank? return start_time if start_date.blank? start_date.change(hour: start_time.hour, min: start_time.min, sec: start_time.sec) end |