Class: HhPackage::PricingMenu
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HhPackage::PricingMenu
- Includes:
- IdentityCache
- Defined in:
- app/models/hh_package/pricing_menu.rb
Overview
Schema Information
Table name: hh_package_pricing_menus
id :bigint not null, primary key
name :string(191)
original_price_cents :integer
original_price_currency :string(191) default("THB")
package_type :string(191) not null
priority :integer
section_type :string(191)
selling_price_cents :integer
selling_price_currency :string(191) default("THB")
created_at :datetime not null
updated_at :datetime not null
menu_group_section_id :bigint
menu_section_id :bigint
package_id :bigint not null
Indexes
index_pricing_menus_on_package_id_type (package_id,package_type)
Instance Method Summary collapse
- #menu_group_section_id ⇒ Object
-
#menu_section_id ⇒ Object
Explicitly define attribute readers to prevent Globalize from interfering when locale is 'id' (Indonesian), which would conflict with the _id suffix See: github.com/globalize/globalize/issues/XXX.
-
#pricing_as_json(keys) ⇒ Hash
Converts pricing menu data to JSON format with structured price objects.
-
#send_pricing_menu_update_events ⇒ void
Sends update events to all restaurants associated with this pricing menu's package when pricing menu data changes.
-
#send_update_pricing_event(restaurant_id, changed_attributes) ⇒ void
Sends update pricing event to the event-driven system for a specific restaurant.
Methods inherited from ApplicationRecord
Instance Method Details
#menu_group_section_id ⇒ Object
52 53 54 |
# File 'app/models/hh_package/pricing_menu.rb', line 52 def read_attribute(:menu_group_section_id) end |
#menu_section_id ⇒ Object
Explicitly define attribute readers to prevent Globalize from interfering when locale is 'id' (Indonesian), which would conflict with the _id suffix See: github.com/globalize/globalize/issues/XXX
48 49 50 |
# File 'app/models/hh_package/pricing_menu.rb', line 48 def read_attribute(:menu_section_id) end |
#pricing_as_json(keys) ⇒ Hash
Price values are returned in cents for precision
Formatted price strings include currency symbols and proper formatting
This method provides backward compatibility while offering improved structure
Converts pricing menu data to JSON format with structured price objects
This method transforms pricing menu attributes into a JSON-friendly format, grouping price-related fields into structured objects for better API consistency. Price information is returned as nested objects containing price, currency, and formatted display values.
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 |
# File 'app/models/hh_package/pricing_menu.rb', line 163 def pricing_as_json(keys) original_price_format = HhMoney.format_rounded(original_price_cents, original_price_currency) selling_price_format = HhMoney.format_rounded(selling_price_cents, selling_price_currency) json = {} keys.each do |key| case key when 'id' json[key] = id when 'name' json[key] = name when 'original_price' # Direct request for original_price object json['original_price'] = { 'price' => original_price_cents, 'currency' => original_price_currency, 'format' => original_price_format, } when 'selling_price' # Direct request for selling_price object json['selling_price'] = { 'price' => selling_price_cents, 'currency' => selling_price_currency, 'format' => selling_price_format, } else # Handle any other keys that might be added in the future json[key] = send(key) if respond_to?(key) end end json end |
#send_pricing_menu_update_events ⇒ void
This method returns an undefined value.
Sends update events to all restaurants associated with this pricing menu's package when pricing menu data changes. This ensures search indexes and dependent services are notified of pricing changes that may affect restaurant display and filtering.
The method iterates through all restaurant packages associated with the polymorphic package and sends update events for each active restaurant with pricing menu changes.
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/hh_package/pricing_menu.rb', line 86 def return unless package&.restaurant_packages&.exists? package.restaurant_packages.active_scope.includes(:restaurant).find_each do |restaurant_package| restaurant = restaurant_package.restaurant # Only send event for bookable and not expired restaurant next unless restaurant&.bookable_and_not_expired? changed_attributes = { price_per_person: {}, price_per_pack: {} } send_update_pricing_event(restaurant.id, changed_attributes) end end |
#send_update_pricing_event(restaurant_id, changed_attributes) ⇒ void
This method returns an undefined value.
Sends update pricing event to the event-driven system for a specific restaurant
105 106 107 108 109 110 111 112 113 |
# File 'app/models/hh_package/pricing_menu.rb', line 105 def send_update_pricing_event(restaurant_id, changed_attributes) EventDrivenWorkers::HhSearch::ProducerWorker.perform_async( EventDrivenClient::Constants::RESTAURANTS_TOPIC, EventDrivenClient::Constants::UPDATE_EVENT, restaurant_id, changed_attributes, { source: 'HhPackage::PricingMenu#send_update_pricing_event' }, ) end |