Module: HhPackage::ModelConcerns::DynamicPricingsForPricing
- Extended by:
- ActiveSupport::Concern
- Included in:
- Pricing
- Defined in:
- app/models/concerns/hh_package/model_concerns/dynamic_pricings_for_pricing.rb
Instance Method Summary collapse
-
#decide_max_seat(default_per_person_by_day_max_seat: nil, get_possible_max_seat_for_per_pack: false) ⇒ Object
because there is no input field for max_seat in by_day.
-
#decide_min_seat(default_per_person_by_day_min_seat: nil, get_min_seat_for_per_pack: false) ⇒ Object
because there is no input field for min_seat in by_day.
- #net_price_cents_per_person ⇒ Object
-
#pricing_as_json(keys, for_dynamic_pricing_rules_attribute: false) ⇒ Object
and max_seat to string if true.
- #pricing_type ⇒ Object
Instance Method Details
#decide_max_seat(default_per_person_by_day_max_seat: nil, get_possible_max_seat_for_per_pack: false) ⇒ Object
because there is no input field for max_seat in by_day. if pricing.dynamic_pricing_type is by day and pricing_model is per_person, then use package.min_seat and package.max_seat
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'app/models/concerns/hh_package/model_concerns/dynamic_pricings_for_pricing.rb', line 115 def decide_max_seat(default_per_person_by_day_max_seat: nil, get_possible_max_seat_for_per_pack: false) case pricing_model when 'per_person' case dynamic_pricing_type when 'by_day' default_per_person_by_day_max_seat.presence || package.decide_max_seat when 'by_party_size', 'normal' max_seat else raise NotImplementedError, "You must implement the decide_max_seat method for package #{package_type} - #{package_id}" end when 'per_pack' return HhPackage::Pricing::MAX_SEAT if get_possible_max_seat_for_per_pack nil else max_seat end end |
#decide_min_seat(default_per_person_by_day_min_seat: nil, get_min_seat_for_per_pack: false) ⇒ Object
because there is no input field for min_seat in by_day. if pricing.dynamic_pricing_type is by day and pricing_model is per_person, then use package.min_seat and package.max_seat
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'app/models/concerns/hh_package/model_concerns/dynamic_pricings_for_pricing.rb', line 83 def decide_min_seat(default_per_person_by_day_min_seat: nil, get_min_seat_for_per_pack: false) # for AYCE package, it has min_seat and max_seat column case pricing_model when 'per_person' case dynamic_pricing_type when 'by_day' default_per_person_by_day_min_seat.presence || package.decide_min_seat when 'by_party_size', 'normal' min_seat else raise NotImplementedError, "You must implement the decide_min_seat method for #{package_type} - #{package_id}" end when 'per_pack' if HhPackage::PACKAGE_LIST_TO_SHORT[package_type.split('::').last.to_sym] == 'pp' return package.package_attr.min_seat end return 1 if get_min_seat_for_per_pack nil else min_seat end end |
#net_price_cents_per_person ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/concerns/hh_package/model_concerns/dynamic_pricings_for_pricing.rb', line 48 def net_price_cents_per_person case pricing_model.to_sym when :per_person case dynamic_pricing_type.to_sym # normal, by_party_size and by_day always use price_cents if per_person # https://hungryhubgroup.slack.com/archives/C01C1U5LBFT/p1721387104059669 when :normal, :by_party_size, :by_day price_cents else raise NotImplementedError, 'You must implement the net_price_per_person method' end when :per_pack price_cents / per_pack when :per_set price_cents when :ala_carte price_cents when :per_item price_cents else raise NotImplementedError, 'You must implement the net_price_per_person method' end end |
#pricing_as_json(keys, for_dynamic_pricing_rules_attribute: false) ⇒ Object
and max_seat to string if true. it is required by our client app
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'app/models/concerns/hh_package/model_concerns/dynamic_pricings_for_pricing.rb', line 140 def pricing_as_json(keys, for_dynamic_pricing_rules_attribute: false) price_format = HhMoney.format_rounded(price_cents, price_currency) json = {} keys.each do |key| json[key] = id if key == 'id' if key == 'min_seat' min_seat = decide_min_seat min_seat = if for_dynamic_pricing_rules_attribute min_seat.to_s else min_seat.to_i end json[key] = min_seat end if key == 'max_seat' max_seat = decide_max_seat max_seat = if max_seat == HhPackage::Pricing::MAX_SEAT 'Infinity' elsif for_dynamic_pricing_rules_attribute max_seat.to_s else max_seat.to_i end json[key] = max_seat end json[key] = price_cents if key == 'price_cents' json[key] = price_currency if key == 'price_currency' json[key] = price_format if key == 'price_format' json[key] = pricing_model if ['pricing_type', 'pricing_model'].include?(key) json[key] = dynamic_pricing_type if key == 'dynamic_pricing_type' json[key] = marketing_price if key == 'marketing_price' json[key] = HhMoney.new(marketing_price, price_currency).default_format if key == 'marketing_price_format' json[key] = by_day_category.to_s if key == 'category_name' json[key] = start_date if key == 'start_date' && should_display_start_date? json[key] = end_date if key == 'end_date' && should_display_end_date? if key == 'kids_price' json[key] = (if kids_price_cents.positive? HhMoney.format_rounded(kids_price_cents, price_currency) else '' end) end json[key] = kids_price_cents if key == 'kids_price_cents' json[key] = HhMoney.new(kids_price_cents, price_currency).default_format if key == 'kids_price_format' json[key] = (selected_days.presence || []).map { |day| humanize_selected_day(day) } if key == 'days' json[key] = title if key == 'title' json[key] = net_price_cents_per_person if key == 'net_price_cents_per_person' json[key] = price_description(package, self, price).to_s if key == 'price_description' json[key] = price_format if key == 'price' json[key] = package.reservation_duration_for_display if key == 'duration' json[key] = HhPackage::Package::Base.per_pack_or_set(package, self) if key == 'per_pack' json[key] = 0 if key == 'kids_price_rate' # TODO remove this attribute json[key] = price.amount.to_i if key == 'price_int' json[key] = price.symbol if key == 'currency_symbol' json[key] = package.promotion_text if key == 'promotion_badge_text' json[:require_min_spending] = require_min_spending? json[:has_spending_tier_discount] = has_spending_tier_discount? if require_min_spending? json[:min_spending_type] = min_spending_type json[:min_spending_cents] = min_spending_cents json[:min_spending_currency] = min_spending_currency end if has_spending_tier_discount? json[:spending_tier_unit] = spending_tier_unit json[:spending_tier_discount_type] = spending_tier_discount_type end end json end |
#pricing_type ⇒ Object
72 73 74 |
# File 'app/models/concerns/hh_package/model_concerns/dynamic_pricings_for_pricing.rb', line 72 def pricing_type pricing_model end |