spree_cm_commissioner 2.15.6 → 2.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/app/controllers/spree/admin/taxon_sections_controller.rb +202 -0
  4. data/app/controllers/spree/admin/taxons_controller_decorator.rb +2 -0
  5. data/app/controllers/spree/api/v2/platform/homepage_section_relatable_options_controller.rb +15 -16
  6. data/app/controllers/spree/api/v2/storefront/homepage_sections_controller.rb +3 -0
  7. data/app/helpers/spree_cm_commissioner/admin/taxon_setting_defaults_helper.rb +13 -0
  8. data/app/models/concerns/spree_cm_commissioner/line_item_seat_selection.rb +2 -1
  9. data/app/models/concerns/spree_cm_commissioner/order_pricing_channel.rb +19 -0
  10. data/app/{services → models}/spree_cm_commissioner/channel_pricing/calculator.rb +10 -3
  11. data/app/models/spree_cm_commissioner/oauth_application_decorator.rb +1 -1
  12. data/app/models/spree_cm_commissioner/order_decorator.rb +1 -1
  13. data/app/models/spree_cm_commissioner/pricing_channel.rb +32 -0
  14. data/app/models/spree_cm_commissioner/taxon_decorator.rb +2 -1
  15. data/app/models/spree_cm_commissioner/taxon_vendor.rb +1 -1
  16. data/app/overrides/spree/admin/oauth_applications/_form/pricing_channel_field.html.erb.deface +1 -1
  17. data/app/overrides/spree/admin/taxons/_form/advanced_settings.html.erb.deface +64 -0
  18. data/app/overrides/spree/admin/taxons/_form/check_in_and_operator.html.erb.deface +33 -0
  19. data/app/overrides/spree/admin/taxons/_form/live_stock.html.erb.deface +30 -0
  20. data/app/queries/spree_cm_commissioner/settlement_summary_query.rb +2 -2
  21. data/app/services/spree_cm_commissioner/agencies/onboard.rb +76 -0
  22. data/app/services/spree_cm_commissioner/channel_pricing/{find_or_create_policy.rb → find_or_create_buy_policy.rb} +1 -1
  23. data/app/services/spree_cm_commissioner/channel_pricing/list_trip_prices.rb +49 -0
  24. data/app/services/spree_cm_commissioner/channel_pricing/preview_rule.rb +88 -0
  25. data/app/services/spree_cm_commissioner/channel_pricing/price_trip_results.rb +1 -1
  26. data/app/services/spree_cm_commissioner/channel_pricing/resolve.rb +1 -1
  27. data/app/services/spree_cm_commissioner/seats/assign_guest.rb +124 -0
  28. data/app/services/spree_cm_commissioner/seats/auto_assign.rb +13 -11
  29. data/app/services/spree_cm_commissioner/settlements/generate_entries_batch.rb +1 -1
  30. data/app/views/spree/admin/shared/_taxon_tabs.html.erb +8 -24
  31. data/app/views/spree/admin/taxon_sections/_add_modal.html.erb +38 -0
  32. data/app/views/spree/admin/taxon_sections/_columns.html.erb +12 -0
  33. data/app/views/spree/admin/taxon_sections/_delete_link.html.erb +10 -0
  34. data/app/views/spree/admin/taxon_sections/_hotel_picker.html.erb +26 -0
  35. data/app/views/spree/admin/taxon_sections/_hotels_table.html.erb +81 -0
  36. data/app/views/spree/admin/taxon_sections/_new_section_modal.html.erb +36 -0
  37. data/app/views/spree/admin/taxon_sections/_product_picker.html.erb +27 -0
  38. data/app/views/spree/admin/taxon_sections/_products_table.html.erb +80 -0
  39. data/app/views/spree/admin/taxon_sections/_section.html.erb +78 -0
  40. data/app/views/spree/admin/taxon_sections/index.html.erb +103 -0
  41. data/config/locales/en.yml +59 -0
  42. data/config/locales/km.yml +59 -0
  43. data/config/routes.rb +16 -7
  44. data/lib/spree_cm_commissioner/version.rb +1 -1
  45. metadata +25 -25
  46. data/app/controllers/spree/admin/classifications_controller.rb +0 -49
  47. data/app/controllers/spree/admin/taxon_childrens_controller.rb +0 -20
  48. data/app/controllers/spree/admin/taxon_vendors_controller.rb +0 -35
  49. data/app/models/concerns/spree_cm_commissioner/order_pricing_channel_resolver.rb +0 -67
  50. data/app/overrides/spree/admin/taxons/_form/background_color_and_foreground_color.html.erb.deface +0 -35
  51. data/app/overrides/spree/admin/taxons/_form/check_in_flows.html.erb.deface +0 -36
  52. data/app/overrides/spree/admin/taxons/_form/custom_redirect_url.html.erb.deface +0 -8
  53. data/app/overrides/spree/admin/taxons/_form/enforce_waiting_room_session.html.erb.deface +0 -10
  54. data/app/overrides/spree/admin/taxons/_form/hide_video_banner.html.erb.deface +0 -9
  55. data/app/overrides/spree/admin/taxons/_form/live_stock_window_form_date.html.erb.deface +0 -41
  56. data/app/overrides/spree/admin/taxons/_form/preview_checkbox.html.erb.deface +0 -11
  57. data/app/overrides/spree/admin/taxons/_form/show_badge_status.html.erb.deface +0 -13
  58. data/app/views/spree/admin/classifications/edit.html.erb +0 -58
  59. data/app/views/spree/admin/classifications/index.html.erb +0 -24
  60. data/app/views/spree/admin/classifications/new.html.erb +0 -47
  61. data/app/views/spree/admin/shared/_products.html.erb +0 -71
  62. data/app/views/spree/admin/taxon_childrens/index.html.erb +0 -34
  63. data/app/views/spree/admin/taxon_vendors/_form.html.erb +0 -10
  64. data/app/views/spree/admin/taxon_vendors/edit.html.erb +0 -24
  65. data/app/views/spree/admin/taxon_vendors/index.html.erb +0 -55
  66. data/app/views/spree/admin/taxon_vendors/new.html.erb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18baf61b5e27108afda29c3c227bf1c6d5b116791872a8d585c9765c37732035
4
- data.tar.gz: 7bb047f010adfc61bbafa85b5184e7c073de6676d25671a171af5456cb723b48
3
+ metadata.gz: 145c298c8cdcc6b7e3a64b850cb6e650d90c8fcafdf58bcb11099d0be5d215c7
4
+ data.tar.gz: 22ad6c3b360b5358cd1ca79a95969d1df8a3d38c23085a164236709c280356f1
5
5
  SHA512:
6
- metadata.gz: a4b15c47dc6b18009690f51862643530e71a2da8f5f70489cc1e53f26924c1e2c50308afb7fc59821929cbfdfc17f883520f0e4337e7a8cd0bff57b1ace34626
7
- data.tar.gz: f3763beb763530dea3b5008c8e80db75715fedd16bd5c13216c0ea954d0f5bb206c7255536e35a42f596c8d62dc9b34805dc59363d1e30f46586dd5cb4ea9954
6
+ metadata.gz: 071ee4cd9043870638f01e1cf4451531bc65c6a57920f12b6cee9f9db6e7aefa76753038db7ffb80bd8af8efb59cf2601d13e36210050ed165b5aecb6bbdaa7a
7
+ data.tar.gz: 4b5a02148da36568d0498a50633f56bd836f49ec6e27bac9606ab6d11460261e4266b04df83ebc4a3d992699ec5067bf3d2b7d7b234e846f21645c6d18553930
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GIT
34
34
  PATH
35
35
  remote: .
36
36
  specs:
37
- spree_cm_commissioner (2.15.6)
37
+ spree_cm_commissioner (2.16.0)
38
38
  activerecord-multi-tenant
39
39
  activerecord_json_validator (~> 2.1, >= 2.1.3)
40
40
  aws-sdk-cloudfront
@@ -0,0 +1,202 @@
1
+ module Spree
2
+ module Admin
3
+ # One page per top-level taxon (an event or activity) for its sections and what each holds: products,
4
+ # which the app shows as ticket cards, and accommodation vendors, shown as hotel cards. Every change
5
+ # redirects back here anchored at the section, and every lookup is scoped to this taxon's sections, so
6
+ # a crafted id can't touch another event's rows.
7
+ class TaxonSectionsController < Spree::Admin::BaseController
8
+ before_action :load_taxonomy_and_taxon
9
+ before_action :load_section, except: %i[index create recalculate_conversions]
10
+
11
+ helper_method :event_tenant_id
12
+
13
+ def index
14
+ sections = @taxon.descendants.order(:lft).to_a
15
+ section_ids = sections.map(&:id)
16
+
17
+ # Loaded up front so the recursive section partial doesn't query per section.
18
+ @sections_by_parent_id = sections.group_by(&:parent_id)
19
+ @classifications_by_section_id = Spree::Classification.where(taxon_id: section_ids)
20
+ .includes(product: { master: %i[images prices] })
21
+ .order(:position)
22
+ .group_by(&:taxon_id)
23
+ @taxon_vendors_by_section_id = SpreeCmCommissioner::TaxonVendor.where(taxon_id: section_ids)
24
+ .includes(vendor: %i[logo default_state])
25
+ .order(:position, :id)
26
+ .group_by(&:taxon_id)
27
+ end
28
+
29
+ # A new section is appended under @taxon (awesome_nested_set adds it as the last child); details like
30
+ # description are filled in from its edit page afterwards.
31
+ def create
32
+ section = @taxonomy.taxons.create(name: params.require(:section)[:name], parent_id: @taxon.id)
33
+
34
+ if section.persisted?
35
+ flash[:success] = flash_message_for(section, :successfully_created)
36
+ redirect_to spree.admin_taxonomy_taxon_taxon_sections_path(@taxonomy.id, @taxon.id, anchor: "section_#{section.id}"), status: :see_other
37
+ else
38
+ flash[:error] = section.errors.full_messages.to_sentence
39
+ redirect_to spree.admin_taxonomy_taxon_taxon_sections_path(@taxonomy.id, @taxon.id), status: :see_other
40
+ end
41
+ end
42
+
43
+ # Also removes nested sections (Taxon#children is dependent: :destroy) and their product/hotel links.
44
+ def destroy
45
+ if @section.destroy
46
+ flash[:success] = flash_message_for(@section, :successfully_removed)
47
+ else
48
+ flash[:error] = @section.errors.full_messages.to_sentence
49
+ end
50
+
51
+ redirect_to spree.admin_taxonomy_taxon_taxon_sections_path(@taxonomy.id, @taxon.id), status: :see_other
52
+ end
53
+
54
+ def add_products
55
+ product_ids = new_ids(:product_ids, @section.classifications.pluck(:product_id))
56
+ rejections = Spree::Product.where(id: product_ids).to_a.filter_map { |product| other_tenant_rejection(product) || add_product(product) }
57
+
58
+ flash_added(product_ids.size - rejections.size, 'section_products')
59
+ flash[:error] = rejections.join(' ') if rejections.any?
60
+ redirect_to_section
61
+ end
62
+
63
+ # Takes the target value rather than toggling, so a double click can't flip it back.
64
+ def update_product_visibility
65
+ @section.classifications.find(params[:classification_id]).update!(visible: params[:visible] == 'true')
66
+
67
+ flash[:success] = Spree.t(:successfully_updated, resource: Spree.t(:product))
68
+ redirect_to_section
69
+ end
70
+
71
+ def remove_product
72
+ @section.classifications.find(params[:classification_id]).destroy!
73
+
74
+ flash[:success] = Spree.t('section_products.removed')
75
+ redirect_to_section
76
+ end
77
+
78
+ def reorder_products
79
+ reorder(@section.classifications)
80
+ end
81
+
82
+ def add_hotels
83
+ vendor_ids = new_ids(:vendor_ids, @section.taxon_vendors.pluck(:vendor_id))
84
+ rejections = []
85
+ added = Spree::Vendor.where(id: vendor_ids).to_a.count do |vendor|
86
+ rejection = other_tenant_rejection(vendor)
87
+ rejections << rejection if rejection
88
+ rejection.nil? && @section.taxon_vendors.create(vendor: vendor).persisted?
89
+ end
90
+
91
+ flash_added(added, 'section_hotels')
92
+ flash[:error] = rejections.join(' ') if rejections.any?
93
+ redirect_to_section
94
+ end
95
+
96
+ def remove_hotel
97
+ @section.taxon_vendors.find(params[:taxon_vendor_id]).destroy!
98
+
99
+ flash[:success] = Spree.t('section_hotels.removed')
100
+ redirect_to_section
101
+ end
102
+
103
+ def reorder_hotels
104
+ reorder(@section.taxon_vendors)
105
+ end
106
+
107
+ def recalculate_conversions
108
+ if @taxon.event?
109
+ SpreeCmCommissioner::MaintenanceTasks::Event.pending.create_or_find_by(
110
+ maintainable_type: 'Spree::Taxon',
111
+ maintainable_id: @taxon.id
112
+ ) do |task|
113
+ task.manually_triggered = true
114
+ end.async_execute
115
+
116
+ flash[:success] = flash_message_for(@taxon, :successfully_updated)
117
+ else
118
+ flash[:error] = 'Conversion recalculation can only be performed for events.' # rubocop:disable Rails/I18nLocaleTexts
119
+ end
120
+
121
+ redirect_to spree.admin_taxonomy_taxon_taxon_sections_path(@taxonomy.id, @taxon.id), status: :see_other
122
+ end
123
+
124
+ private
125
+
126
+ def model_class
127
+ Spree::Taxon
128
+ end
129
+
130
+ def load_taxonomy_and_taxon
131
+ @taxonomy = Spree::Taxonomy.find(params[:taxonomy_id])
132
+ @taxon = @taxonomy.taxons.find(params[:taxon_id])
133
+ end
134
+
135
+ def load_section
136
+ @section = @taxon.descendants.find(params[:id])
137
+ end
138
+
139
+ # Ids already in the section are dropped so one duplicate doesn't fail the uniqueness validation for the batch.
140
+ def new_ids(key, existing_ids)
141
+ Array(params[key]).compact_blank.map(&:to_i) - existing_ids
142
+ end
143
+
144
+ # An event has no tenant of its own: it's its vendor's, the same way Product#set_tenant copies a product's
145
+ # from its vendor. nil means a tenant-less (BookMe+) event, which only takes tenant-less products/hotels.
146
+ def event_tenant_id
147
+ return @event_tenant_id if defined?(@event_tenant_id)
148
+
149
+ @event_tenant_id = @taxon.vendor&.tenant_id
150
+ end
151
+
152
+ # Checked here as well as in the pickers' search, so a hand-crafted request can't mix tenants.
153
+ def other_tenant_rejection(record)
154
+ return if record.tenant_id == event_tenant_id
155
+
156
+ "#{record.name}: #{Spree.t('section_products.other_tenant_hint')}"
157
+ end
158
+
159
+ # Returns nil when added, or why the product was rejected. For an event this also does what the
160
+ # product form does on save: Product#set_event_id fills event_id (only ever on save), and the
161
+ # product's event validations (one event per product, event has dates) run. A rejected product
162
+ # isn't left half-added to the section.
163
+ def add_product(product)
164
+ ActiveRecord::Base.transaction do
165
+ @section.classifications.create!(product: product)
166
+ next unless @taxon.event?
167
+
168
+ product.event_id ||= @taxon.id
169
+ product.save!
170
+ end
171
+
172
+ nil
173
+ rescue ActiveRecord::RecordInvalid => e
174
+ "#{product.name}: #{e.record.errors.full_messages.to_sentence}."
175
+ end
176
+
177
+ def flash_added(added_count, i18n_scope)
178
+ if added_count.positive?
179
+ flash[:success] = Spree.t("#{i18n_scope}.added", count: added_count, section: @section.name)
180
+ else
181
+ flash[:error] = Spree.t("#{i18n_scope}.none_added")
182
+ end
183
+ end
184
+
185
+ # positions: { "<row id>" => 1-based index }, posted by the Sortable on the page. Ids outside this section are ignored.
186
+ def reorder(scope)
187
+ positions = params.require(:positions).to_unsafe_h
188
+ records = scope.where(id: positions.keys).index_by { |record| record.id.to_s }
189
+
190
+ ApplicationRecord.transaction do
191
+ positions.each { |id, index| records[id]&.set_list_position(index.to_i) }
192
+ end
193
+
194
+ head :ok
195
+ end
196
+
197
+ def redirect_to_section
198
+ redirect_to spree.admin_taxonomy_taxon_taxon_sections_path(@taxonomy.id, @taxon.id, anchor: "section_#{@section.id}"), status: :see_other
199
+ end
200
+ end
201
+ end
202
+ end
@@ -2,6 +2,8 @@ module Spree
2
2
  module Admin
3
3
  module TaxonsControllerDecorator
4
4
  def self.prepended(base)
5
+ base.helper SpreeCmCommissioner::Admin::TaxonSettingDefaultsHelper
6
+
5
7
  base.before_action :build_assets, only: %i[create update]
6
8
  base.before_action :normalize_sti_taxon_params, only: %i[create update]
7
9
  end
@@ -16,32 +16,31 @@ module Spree
16
16
  ::SpreeCmCommissioner::Api::V2::Platform::HomepageSectionRelatableOptionsSerializer
17
17
  end
18
18
 
19
- # Opt-in only (params[:taxon_scope] == 'events'/params[:tenant_id]), so existing callers
19
+ # Opt-in only (params[:taxon_scope] == 'events'/params[:primary_product_type]), so existing callers
20
20
  # that search across all taxons/vendors (e.g. ticket transfer rules, homepage sections)
21
- # are unaffected.
21
+ # are unaffected. ?tenant_id= is applied by Platform::ResourceControllerDecorator (see scope_by_tenant).
22
22
  def scope
23
23
  result = super
24
24
  result = result.merge(Spree::Taxon.events) if model_class == Spree::Taxon && params[:taxon_scope] == 'events'
25
- result = scoped_to_tenant(result) if params[:tenant_id].present?
25
+ result = scoped_to_primary_product_type(result) if model_class == Spree::Vendor && params[:primary_product_type].present?
26
26
 
27
27
  result
28
28
  end
29
29
 
30
30
  private
31
31
 
32
- # Product has its own tenant_id (set from its vendor — see
33
- # SpreeCmCommissioner::ProductDecorator#set_tenant). Taxon (Event) has no tenant_id
34
- # column of its own, so it's derived through the products that reference it as their
35
- # event.
36
- def scoped_to_tenant(result)
37
- case model_class.name
38
- when 'Spree::Vendor', 'Spree::Product'
39
- result.where(tenant_id: params[:tenant_id])
40
- when 'Spree::Taxon'
41
- result.where(id: Spree::Product.where(tenant_id: params[:tenant_id]).select(:event_id))
42
- else
43
- result
44
- end
32
+ # e.g. the Sections page hotel picker asks for accommodation vendors only.
33
+ def scoped_to_primary_product_type(result)
34
+ result.where(primary_product_type: params[:primary_product_type])
35
+ end
36
+
37
+ # override Platform::ResourceControllerDecorator#scope_by_tenant: Vendor and Product own a tenant_id and use
38
+ # the default ("0" = tenant-less). Taxon (Event) has no tenant_id column, so it's derived through the products
39
+ # that reference it as their event (Product#set_tenant copies the product's from its vendor).
40
+ def scope_by_tenant(scope, tenant_id)
41
+ return super unless model_class == Spree::Taxon
42
+
43
+ scope.where(id: Spree::Product.where(tenant_id: tenant_id.to_s == '0' ? nil : tenant_id).select(:event_id))
45
44
  end
46
45
  end
47
46
  end
@@ -24,6 +24,9 @@ module Spree
24
24
  .for_feed(params[:homepage_id] || :general, params[:mini_app])
25
25
  .order(position: :asc)
26
26
  .includes(:app_background, :web_background)
27
+ # The serializer reads each relatable (and a taxon's `vendor_ids`) per row;
28
+ # without this, every vendor relatable costs its own spree_vendors query.
29
+ .preload(homepage_section_relatables: { relatable: :vendors })
27
30
  end
28
31
  end
29
32
  end
@@ -0,0 +1,13 @@
1
+ module SpreeCmCommissioner
2
+ module Admin
3
+ module TaxonSettingDefaultsHelper
4
+ # Taxon counterpart of ProductSettingDefaultsHelper. Several event flags default to on (most
5
+ # check-in/operator ones live in store_public_metadata), so a fresh taxon is the only reliable source.
6
+ def taxon_setting_default_label(attribute)
7
+ key = Spree::Taxon.new.public_send(attribute) ? :default_on : :default_off
8
+
9
+ content_tag(:small, Spree.t(key), class: 'ml-1 text-muted')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,10 +9,11 @@ module SpreeCmCommissioner
9
9
  #
10
10
  # pending — paid, waiting for Seats::AutoAssignJob (set by OrderSeatAutoAssignable)
11
11
  # together / split / unseated — the job's outcome (Seats::AutoAssign)
12
+ # manual — an organizer seated the rest of an `unseated` party by hand (Seats::AssignGuest)
12
13
  #
13
14
  # A column so parties can be queried by it (e.g. split ones for the organizer). The app reads it
14
15
  # only for a guest without a seat_number yet: after a resume, one party can hold both.
15
- enum seat_assignment_status: { pending: 0, together: 1, split: 2, unseated: 3 }, _prefix: :seat_assignment
16
+ enum seat_assignment_status: { pending: 0, together: 1, split: 2, unseated: 3, manual: 4 }, _prefix: :seat_assignment
16
17
  end
17
18
 
18
19
  # Caches the required_seat_selection flag from the trip in private_metadata.
@@ -0,0 +1,19 @@
1
+ module SpreeCmCommissioner
2
+ # Splits the order's `pricing_channel` into the channel_type + platform that ChannelPricing::Resolve and settlement
3
+ # use to pick the order's price policy. Unknown or blank sources return nil (base price).
4
+ #
5
+ # order.pricing_channel = 'vendor_agency_web_dashboard'
6
+ # order.resolved_channel_type # => :channel_vendor_agency
7
+ # order.resolved_platform # => :web_dashboard
8
+ module OrderPricingChannel
9
+ extend ActiveSupport::Concern
10
+
11
+ def resolved_channel_type
12
+ PricingChannel::SOURCES[pricing_channel]&.fetch(:channel_type)
13
+ end
14
+
15
+ def resolved_platform
16
+ PricingChannel::SOURCES[pricing_channel]&.fetch(:platform)
17
+ end
18
+ end
19
+ end
@@ -43,7 +43,7 @@ module SpreeCmCommissioner
43
43
  # The buy-list calculator a storefront request on `pricing_channel` is priced with, or nil for base price.
44
44
  # Agency channels are nil: their price needs the signed-in agency, which a storefront request has not.
45
45
  def self.for_channel(pricing_channel:, vendor_id:, currency:, oauth_application: nil)
46
- mapping = OrderPricingChannelResolver::SOURCE_TO_CHANNEL_MAPPING[pricing_channel]
46
+ mapping = PricingChannel::SOURCES[pricing_channel]
47
47
  return nil if mapping.nil? || mapping[:channel_type].to_s.include?('agency')
48
48
 
49
49
  policy = FindBuyPolicy.call(
@@ -54,8 +54,11 @@ module SpreeCmCommissioner
54
54
  policy && new(policy)
55
55
  end
56
56
 
57
- def initialize(channel_price_policy)
57
+ # rules: preloaded subset of the policy's rules, for screens that price one trip against many policies
58
+ # and must not load every rule of each.
59
+ def initialize(channel_price_policy, rules: nil)
58
60
  @channel_price_policy = channel_price_policy
61
+ @rules = index_rules(rules) if rules
59
62
  end
60
63
 
61
64
  # Rounded to the currency's minor unit at every call, so an agency's retail price is computed
@@ -103,7 +106,11 @@ module SpreeCmCommissioner
103
106
  private
104
107
 
105
108
  def rules
106
- @rules ||= channel_price_policy.channel_price_rules.index_by { |r| [r.scopable_type, r.scopable_id] }
109
+ @rules ||= index_rules(channel_price_policy.channel_price_rules)
110
+ end
111
+
112
+ def index_rules(rules)
113
+ rules.index_by { |r| [r.scopable_type, r.scopable_id] }
107
114
  end
108
115
  end
109
116
  end
@@ -7,7 +7,7 @@ module SpreeCmCommissioner
7
7
  # What every order made through this application is priced as. Blank leaves it on base price.
8
8
  # Read from the token, never from the request, so a client cannot pick a cheaper channel.
9
9
  base.validates :pricing_channel,
10
- inclusion: { in: -> (_application) { SpreeCmCommissioner::OrderPricingChannelResolver::SOURCE_TO_CHANNEL_MAPPING.keys } },
10
+ inclusion: { in: -> (_application) { SpreeCmCommissioner::PricingChannel::SOURCES.keys } },
11
11
  allow_blank: true
12
12
  # A bank's price comes from its DistributionAgreement, which Resolve only reads on this channel.
13
13
  base.validates :pricing_channel, inclusion: { in: ['platform_mini_app'] }, if: -> { provider.present? && pricing_channel.present? }
@@ -15,7 +15,7 @@ module SpreeCmCommissioner
15
15
  base.include SpreeCmCommissioner::OrderQrCodeable
16
16
  base.include SpreeCmCommissioner::OrderPrepaidPayment
17
17
  base.include SpreeCmCommissioner::Integrations::IntegrationMappable
18
- base.include SpreeCmCommissioner::OrderPricingChannelResolver
18
+ base.include SpreeCmCommissioner::OrderPricingChannel
19
19
 
20
20
  base.before_create :link_by_phone_number
21
21
  base.before_create :associate_customer
@@ -0,0 +1,32 @@
1
+ module SpreeCmCommissioner
2
+ # The `pricing_channel` sources an order, an OAuth application or a dashboard sale can carry. Each one encodes who
3
+ # sells (direct vendor, BookMe+ platform, or an agency) and through which surface, and maps to the
4
+ # channel_type + platform that pick a ChannelPricePolicy (ChannelPricing::Resolve, FindBuyPolicy).
5
+ #
6
+ # spree_orders.pricing_channel | channel_type | platform
7
+ # tenant_app | channel_direct | app
8
+ # platform_app | channel_platform | app
9
+ # platform_agency_web_dashboard | channel_platform_agency | web_dashboard
10
+ # direct_walk_in | channel_direct | walk_in
11
+ # vendor_agency_web_dashboard | channel_vendor_agency | web_dashboard
12
+ module PricingChannel
13
+ SOURCES = {
14
+ # Direct channel — the vendor sells by itself: its tenant's own app/web, or staff at the counter (dashboard)
15
+ 'tenant_app' => { channel_type: :channel_direct, platform: :app },
16
+ 'tenant_web' => { channel_type: :channel_direct, platform: :web },
17
+ 'direct_walk_in' => { channel_type: :channel_direct, platform: :walk_in },
18
+
19
+ # Platform channel — BookMe+ marketplace sells on behalf of the vendor
20
+ 'platform_app' => { channel_type: :channel_platform, platform: :app },
21
+ 'platform_web' => { channel_type: :channel_platform, platform: :web },
22
+ 'platform_mini_app' => { channel_type: :channel_platform, platform: :mini_app },
23
+ 'platform_telegram' => { channel_type: :channel_platform, platform: :telegram },
24
+
25
+ # Vendor agency — vendor-contracted agency; agency knows vendor's base price
26
+ 'vendor_agency_web_dashboard' => { channel_type: :channel_vendor_agency, platform: :web_dashboard },
27
+
28
+ # Platform agency — platform-contracted agency; agency only sees wholesale, not vendor's base
29
+ 'platform_agency_web_dashboard' => { channel_type: :channel_platform_agency, platform: :web_dashboard }
30
+ }.freeze
31
+ end
32
+ end
@@ -8,7 +8,8 @@ module SpreeCmCommissioner
8
8
  base.include SpreeCmCommissioner::Integrations::IntegrationMappable
9
9
  base.include SpreeCmCommissioner::HomepageSectionRelatableConcern
10
10
 
11
- base.has_many :taxon_vendors, class_name: 'SpreeCmCommissioner::TaxonVendor'
11
+ # Ordered so a section's hotels reach the app in the order admins drag them to on the Sections page.
12
+ base.has_many :taxon_vendors, -> { order(:position, :id) }, class_name: 'SpreeCmCommissioner::TaxonVendor'
12
13
  base.has_many :vendors, through: :taxon_vendors
13
14
 
14
15
  base.has_many :guest_card_classes, class_name: 'SpreeCmCommissioner::GuestCardClass'
@@ -3,7 +3,7 @@ module SpreeCmCommissioner
3
3
  belongs_to :taxon, class_name: 'Spree::Taxon', optional: true
4
4
  belongs_to :vendor, class_name: 'Spree::Vendor', optional: true
5
5
 
6
- acts_as_list scope: :vendor
6
+ acts_as_list scope: :taxon
7
7
 
8
8
  validates :taxon_id, presence: true
9
9
  validates :vendor_id, presence: true, uniqueness: { scope: :taxon_id }
@@ -3,7 +3,7 @@
3
3
  <%= f.field_container :pricing_channel, 'data-hook' => "oauth_application_pricing_channel" do %>
4
4
  <%= f.label :pricing_channel, 'Pricing channel (optional)' %>
5
5
  <%= f.select :pricing_channel,
6
- SpreeCmCommissioner::OrderPricingChannelResolver::SOURCE_TO_CHANNEL_MAPPING.keys.map { |key| [key.humanize, key] },
6
+ SpreeCmCommissioner::PricingChannel::SOURCES.keys.map { |key| [key.humanize, key] },
7
7
  { include_blank: 'Base price (no channel pricing)' }, { class: 'form-control' } %>
8
8
  <%= f.error_message_on :pricing_channel %>
9
9
  <% end %>
@@ -0,0 +1,64 @@
1
+ <!-- insert_bottom "[data-hook='admin_inside_taxon_form']" sequence 200 -->
2
+
3
+ <%# sequence 200 keeps this card below the other cards (default 100). %>
4
+ <% if @taxon.depth == 1 %>
5
+ <div data-hook="admin_taxon_form_advanced_settings" class="card bg-light mb-3">
6
+ <div class="card-body pb-0">
7
+ <h5 class="card-title"><%= Spree.t('advanced_settings.title') %></h5>
8
+ <h6 class="card-subtitle text-muted mb-3"><%= Spree.t('advanced_settings.hint') %></h6>
9
+
10
+ <div class="row">
11
+ <% { preview: 'Preview (internal team only)', hide_video_banner: Spree.t(:hide_video_banner), show_badge_status: Spree.t('show_badge_status') }.each do |attribute, label| %>
12
+ <div class="col-12 col-md-6">
13
+ <%= f.field_container attribute, class: ['custom-control', 'custom-checkbox', 'mb-3'] do %>
14
+ <%= f.check_box attribute, class: 'custom-control-input' %>
15
+ <%= f.label attribute, label, class: 'custom-control-label' %>
16
+ <%= taxon_setting_default_label(attribute) %>
17
+ <%= f.error_message_on attribute %>
18
+ <% end %>
19
+ </div>
20
+ <% end %>
21
+
22
+ <% if @taxon.event? %>
23
+ <div class="col-12">
24
+ <%= f.field_container :enforce_waiting_room_session, class: ['custom-control', 'custom-checkbox', 'mb-3'] do %>
25
+ <%= f.check_box :enforce_waiting_room_session, class: 'custom-control-input' %>
26
+ <%= f.label :enforce_waiting_room_session, Spree.t(:enforce_waiting_room_session), class: 'custom-control-label' %>
27
+ <%= taxon_setting_default_label(:enforce_waiting_room_session) %>
28
+ <%= f.error_message_on :enforce_waiting_room_session %>
29
+ <small class="form-text text-muted"><%= Spree.t(:enforce_waiting_room_session_hint) %></small>
30
+ <% end %>
31
+ </div>
32
+ <% end %>
33
+
34
+ <div class="col-12">
35
+ <%= f.field_container :custom_redirect_url do %>
36
+ <%= f.label :custom_redirect_url, Spree.t(:custom_redirect_url) %>
37
+ <%= f.text_field :custom_redirect_url, class: 'form-control' %>
38
+ <%= f.error_message_on :custom_redirect_url %>
39
+ <% end %>
40
+ </div>
41
+
42
+ <% %i[background_color foreground_color].each do |attribute| %>
43
+ <div class="col-12 col-md-6 form-group">
44
+ <%= f.label attribute, Spree.t(attribute) %>
45
+ <div class="d-flex align-items-center">
46
+ <%= f.text_field attribute, class: 'form-control taxon-color-picker', placeholder: '#FFFFFF', value: @taxon.public_send(attribute) %>
47
+ <span class="taxon-color-swatch ml-2 border rounded flex-shrink-0" style="width: 38px; height: 38px; background-color: <%= @taxon.public_send(attribute) %>"></span>
48
+ </div>
49
+ </div>
50
+ <% end %>
51
+ </div>
52
+ </div>
53
+ </div>
54
+
55
+ <script>
56
+ document.addEventListener('spree:load', function() {
57
+ document.querySelectorAll('.taxon-color-picker').forEach(function(picker) {
58
+ var swatch = picker.parentElement.querySelector('.taxon-color-swatch');
59
+
60
+ picker.addEventListener('input', function() { swatch.style.backgroundColor = picker.value; });
61
+ });
62
+ });
63
+ </script>
64
+ <% end %>
@@ -0,0 +1,33 @@
1
+ <!-- insert_bottom "[data-hook='admin_inside_taxon_form']" -->
2
+
3
+ <% if @taxon.event? && @taxon.depth == 1 %>
4
+ <div data-hook="admin_taxon_form_check_in_and_operator" class="card bg-light mb-3">
5
+ <div class="card-body pb-0">
6
+ <h5 class="card-title"><%= Spree.t('taxon_check_in_and_operator.title') %></h5>
7
+ <h6 class="card-subtitle text-muted mb-3"><%= Spree.t('taxon_check_in_and_operator.hint') %></h6>
8
+
9
+ <div class="row">
10
+ <div class="col-12 col-md-6">
11
+ <%= f.field_container :group_check_in_enabled, class: ['custom-control', 'custom-checkbox', 'mb-3'] do %>
12
+ <%= f.check_box :group_check_in_enabled, class: 'custom-control-input' %>
13
+ <%= f.label :group_check_in_enabled, Spree.t(:enable_group_check_in), class: 'custom-control-label' %>
14
+ <%= taxon_setting_default_label(:group_check_in_enabled) %>
15
+ <%= f.error_message_on :group_check_in_enabled %>
16
+ <small class="form-text text-muted"><%= Spree.t('taxon_check_in_and_operator.group_check_in_hint') %></small>
17
+ <% end %>
18
+ </div>
19
+
20
+ <% %i[individual_check_in_enabled allow_manual_search_for_operator allow_event_overview_for_operator allow_event_chart_for_operator].each do |attribute| %>
21
+ <div class="col-12 col-md-6">
22
+ <%= f.field_container attribute, class: ['custom-control', 'custom-checkbox', 'mb-3'] do %>
23
+ <%= f.check_box attribute, class: 'custom-control-input' %>
24
+ <%= f.label attribute, Spree.t(attribute == :individual_check_in_enabled ? :enable_individual_check_in : attribute), class: 'custom-control-label' %>
25
+ <%= taxon_setting_default_label(attribute) %>
26
+ <%= f.error_message_on attribute %>
27
+ <% end %>
28
+ </div>
29
+ <% end %>
30
+ </div>
31
+ </div>
32
+ </div>
33
+ <% end %>
@@ -0,0 +1,30 @@
1
+ <!-- insert_bottom "[data-hook='admin_inside_taxon_form']" sequence 150 -->
2
+
3
+ <%# sequence 150 keeps this card between the check-in card (default 100) and Advanced (200). %>
4
+ <% if @taxon.event? && @taxon.depth == 1 %>
5
+ <div data-hook="admin_taxon_form_live_stock" class="card bg-light mb-3">
6
+ <div class="card-body pb-0">
7
+ <h5 class="card-title"><%= Spree.t('taxon_live_stock.title') %></h5>
8
+ <%# See Spree::Taxon.live_stock_active: StockStatusConsolidationJob only publishes to Firestore inside this window. %>
9
+ <h6 class="card-subtitle text-muted mb-3"><%= Spree.t('taxon_live_stock.hint') %></h6>
10
+
11
+ <div class="row">
12
+ <div class="col-12 col-md-6 form-group">
13
+ <%= label_tag nil, Spree.t(:live_stock_starts_at, default: 'Live Stock On') %>
14
+ <div class="input-group datePickerFrom" data-wrap="true" data-alt-input="true" data-max-date="<%= @taxon.live_stock_ends_at %>" data-enable-time="true">
15
+ <%= f.text_field :live_stock_starts_at, value: @taxon.live_stock_starts_at, placeholder: Spree.t(:select_a_date), class: 'form-control shadow-none', 'data-input': '' %>
16
+ <%= render partial: 'spree/admin/shared/cal_close' %>
17
+ </div>
18
+ </div>
19
+
20
+ <div class="col-12 col-md-6 form-group">
21
+ <%= label_tag nil, Spree.t(:live_stock_ends_at, default: 'Live Stock Off') %>
22
+ <div class="input-group datePickerTo" data-wrap="true" data-alt-input="true" data-min-date="<%= @taxon.live_stock_starts_at %>" data-enable-time="true">
23
+ <%= f.text_field :live_stock_ends_at, value: @taxon.live_stock_ends_at, placeholder: Spree.t(:select_a_date), class: 'form-control shadow-none', 'data-input': '' %>
24
+ <%= render partial: 'spree/admin/shared/cal_close' %>
25
+ </div>
26
+ </div>
27
+ </div>
28
+ </div>
29
+ </div>
30
+ <% end %>
@@ -25,7 +25,7 @@ module SpreeCmCommissioner
25
25
  agency: %i[sell_total buy_total agency_net]
26
26
  }.freeze
27
27
 
28
- VENDOR_AGENCY_CHANNELS = OrderPricingChannelResolver::SOURCE_TO_CHANNEL_MAPPING
28
+ VENDOR_AGENCY_CHANNELS = PricingChannel::SOURCES
29
29
  .select { |_source, mapping| mapping[:channel_type] == :channel_vendor_agency }.keys.freeze
30
30
 
31
31
  CHANNEL_TYPES = %w[channel_direct channel_platform channel_vendor_agency channel_platform_agency].freeze
@@ -75,7 +75,7 @@ module SpreeCmCommissioner
75
75
  end
76
76
 
77
77
  def channel_sources
78
- OrderPricingChannelResolver::SOURCE_TO_CHANNEL_MAPPING.select { |_source, mapping| mapping[:channel_type].to_s == channel_type }.keys
78
+ PricingChannel::SOURCES.select { |_source, mapping| mapping[:channel_type].to_s == channel_type }.keys
79
79
  end
80
80
 
81
81
  def search_sql