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
- #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
76 77 78 79 80 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 76 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.
68 69 70 71 72 73 74 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 68 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
82 83 84 85 86 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 82 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
52 53 54 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 52 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
46 47 48 49 50 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 46 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
38 39 40 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 38 def @options ||= VariantOptions.new(self) end |
#options_in_hash ⇒ Object
42 43 44 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 42 def [:cm_options] end |
#post_paid? ⇒ Boolean
88 89 90 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 88 def post_paid? .payment_option == 'post-paid' end |
#set_options_to_public_metadata ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 92 def self. ||= {} # Cache option values as a hash to avoid N+1 queries when accessing options. # Stores {option_type_name => option_value_name} pairs that can be retrieved # without loading option_types and option_values associations. # Example: "Red, 256GB" - formatted options for quick display self.[:cm_options] = 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 # Cache formatted options text for quick retrieval via #options_text. # Precomputes the human-readable format (e.g., "Red, 256GB") to avoid # repeated formatting and association queries. # Example: {"color" => "red", "storage" => "256GB"} - option_type_name => option_value_name pairs self.[:preload_options_text] = Spree::Variants::VisibleOptionsPresenter.new(self).to_sentence end |
#set_options_to_public_metadata! ⇒ Object
111 112 113 114 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 111 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.
58 59 60 61 62 63 64 |
# File 'app/models/concerns/spree_cm_commissioner/variant_options_concern.rb', line 58 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 |