spree_cm_commissioner 2.1.5.pre.pre1 → 2.1.5.pre.pre4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d85338c01f8051cd2aff1de565907e13f401f0044b766cca7738056f1089a7d1
4
- data.tar.gz: 32b15e97d40db31db7749ee684bb02f3b01bfaa44afc32bc79d1a259960fae50
3
+ metadata.gz: d8486b28317774d671766e586870afa3396fc006efd21ea825bdc6769985e4be
4
+ data.tar.gz: 60df005650d9f053548a82bb7aa3818dd36e3b6aec8773a5fe05c3c5bf7d5d5a
5
5
  SHA512:
6
- metadata.gz: 3a2d72ee902e1a625713777268aa727d2c92e25cea7a912bd799dd999d4e99f0c7ec5eeb2e5cce49575205d4e01606cf0aa4776e5844074348728ce00eaa4efd
7
- data.tar.gz: 5dc5ad4f7c7ff9121503d09fa49e67903b15cc86e21cbd468494fa2119ca758712410c3bb3896a1fa6013bb7e9429b793e6dac1856a676c67caf928950a8b271
6
+ metadata.gz: 16f526c38a5084769158d1a1cf643c77458f9a031adb21911f6b6699b2cd9421cb865d2de8d200bb7d4649aa30f79ef98273283aebf51a09ce25b45eeb1ae0c4
7
+ data.tar.gz: 894f3c5cb26b1506042a35a3fc36ac7d09b40828ee242715a47d83dc4141dcfb9ddcde3603e6a233b92df6aefab59ad0873778fa9f1ee286041ba262e6f95e9c
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GIT
34
34
  PATH
35
35
  remote: .
36
36
  specs:
37
- spree_cm_commissioner (2.1.5.pre.pre1)
37
+ spree_cm_commissioner (2.1.5.pre.pre4)
38
38
  activerecord-multi-tenant
39
39
  activerecord_json_validator (~> 2.1, >= 2.1.3)
40
40
  aws-sdk-cloudfront
@@ -4,8 +4,6 @@ module Spree
4
4
  module Tenant
5
5
  class BaseController < ::Spree::Api::V2::ResourceController
6
6
  include Spree::Api::V2::CollectionOptionsHelpers
7
- rescue_from ActiveRecord::RecordInvalid, with: :handle_record_invalid
8
- rescue_from ActiveRecord::RecordNotFound, with: :handle_record_not_found
9
7
 
10
8
  set_current_tenant_through_filter
11
9
  before_action :require_tenant
@@ -26,16 +24,6 @@ module Spree
26
24
  def scope
27
25
  raise 'scope should be implemented in a sub-class'
28
26
  end
29
-
30
- private
31
-
32
- def handle_record_invalid(exception)
33
- render_error_payload(exception.record.errors, 422)
34
- end
35
-
36
- def handle_record_not_found(exception)
37
- render_error_payload({ base: [exception.message] }, 404)
38
- end
39
27
  end
40
28
  end
41
29
  end
@@ -9,6 +9,9 @@ module Spree
9
9
  # raise 404 when no order
10
10
  before_action :ensure_order
11
11
 
12
+ rescue_from ActiveRecord::RecordInvalid, with: :handle_record_invalid
13
+ rescue_from ActiveRecord::RecordNotFound, with: :handle_record_not_found
14
+
12
15
  # override
13
16
  def model_class
14
17
  SpreeCmCommissioner::Guest
@@ -100,6 +103,14 @@ module Spree
100
103
  dynamic_fields_attributes: guest_params[:guest_dynamic_fields_attributes]
101
104
  )
102
105
  end
106
+
107
+ def handle_record_invalid(exception)
108
+ render_error_payload(exception.record.errors, 422)
109
+ end
110
+
111
+ def handle_record_not_found(exception)
112
+ render_error_payload({ base: [exception.message] }, 404)
113
+ end
103
114
  end
104
115
  end
105
116
  end
@@ -39,8 +39,7 @@ module SpreeCmCommissioner
39
39
  login = login.downcase
40
40
  parser = PhoneNumberParser.call(phone_number: login)
41
41
 
42
- scope = Spree.user_class.all
43
- scope = scope.where(tenant_id: tenant_id) if tenant_id.present?
42
+ scope = tenant_id.present? ? Spree.user_class.by_tenant(tenant_id) : Spree.user_class.by_non_tenant
44
43
 
45
44
  if parser.intel_phone_number.present?
46
45
  scope.find_by(intel_phone_number: parser.intel_phone_number)
@@ -51,7 +51,8 @@ module SpreeCmCommissioner
51
51
  preference :telegram_user_verified_at, :string
52
52
 
53
53
  before_validation :set_event_id
54
- before_validation :assign_seat_number, if: -> { bib_number.present? }
54
+ before_validation :assign_seat_number_with_bib, if: -> { bib_number.present? }
55
+ before_validation :assign_seat_number_with_block, if: -> { will_save_change_to_block_id? }
55
56
 
56
57
  before_create :generate_bib, if: -> { line_item.reload && variant.bib_pre_generation_on_create? }
57
58
 
@@ -147,13 +148,17 @@ module SpreeCmCommissioner
147
148
  self.event_id ||= line_item&.event_id
148
149
  end
149
150
 
150
- def assign_seat_number
151
+ def assign_seat_number_with_block
152
+ self.seat_number = block.present? ? block.label : nil
153
+ end
154
+
155
+ def assign_seat_number_with_bib
151
156
  return if seat_number.present? # avoid reassign seat to guest
152
157
 
153
- assign_seat_number!
158
+ assign_seat_number_with_bib!
154
159
  end
155
160
 
156
- def assign_seat_number!
161
+ def assign_seat_number_with_bib!
157
162
  index = bib_number - 1
158
163
  positions = line_item.variant.seat_number_positions || []
159
164
 
@@ -29,6 +29,7 @@ module SpreeCmCommissioner
29
29
  base.before_create :add_due_date, if: :subscription?
30
30
 
31
31
  base.validate :ensure_not_exceed_max_quantity_per_order, if: -> { variant&.max_quantity_per_order.present? }
32
+ base.validate :ensure_all_guests_have_blocks, if: -> { variant&.blocks&.any? }
32
33
 
33
34
  base.whitelisted_ransackable_associations |= %w[guests order]
34
35
  base.whitelisted_ransackable_attributes |= %w[number to_date from_date vendor_id]
@@ -217,7 +218,13 @@ module SpreeCmCommissioner
217
218
  private
218
219
 
219
220
  def ensure_not_exceed_max_quantity_per_order
220
- errors.add(:quantity, 'exceeded_max_quantity_per_order') if quantity > variant.max_quantity_per_order
221
+ errors.add(:quantity, I18n.t('line_item.validation.exceeded_max_quantity_per_order')) if quantity > variant.max_quantity_per_order
222
+ end
223
+
224
+ def ensure_all_guests_have_blocks
225
+ return if number_of_guests == guests.map(&:block_id).compact.uniq.size
226
+
227
+ errors.add(:base, I18n.t('line_item.validation.seats_are_required'))
221
228
  end
222
229
 
223
230
  def update_vendor_id
@@ -155,10 +155,6 @@ module SpreeCmCommissioner
155
155
  ::SpreeCmCommissioner::EventLineItemsDateSyncerJob.perform_later(id)
156
156
  end
157
157
 
158
- def seat_layout
159
- nil
160
- end
161
-
162
158
  private
163
159
 
164
160
  def normalize_custom_redirect_url
@@ -1,6 +1,5 @@
1
1
  module SpreeCmCommissioner
2
2
  class Trip < Base
3
- include ::Spree::Metadata
4
3
  include SpreeCmCommissioner::RouteType
5
4
 
6
5
  attr_accessor :hours, :minutes, :seconds
@@ -32,6 +32,7 @@ module SpreeCmCommissioner
32
32
  base.has_secure_password :confirm_pin_code, validations: false
33
33
 
34
34
  base.multi_tenant :tenant, class_name: 'SpreeCmCommissioner::Tenant'
35
+
35
36
  base.scope :by_tenant, -> (tenant_id) { where(tenant_id: tenant_id) }
36
37
  base.scope :by_non_tenant, -> { where(tenant_id: nil) }
37
38
  base.scope :vendor_users, -> (vendor_id) { joins(:role_users => :role).where(spree_roles: { vendor_id: vendor_id }).distinct }
@@ -1,6 +1,5 @@
1
1
  module SpreeCmCommissioner
2
2
  class Vehicle < Base
3
- include ::Spree::Metadata
4
3
  include SpreeCmCommissioner::VehicleType
5
4
 
6
5
  # seat_layout_id:
@@ -13,7 +13,6 @@ module Spree
13
13
 
14
14
  belongs_to :occupation, serializer: Spree::V2::Tenant::TaxonSerializer
15
15
  belongs_to :nationality, serializer: Spree::V2::Tenant::TaxonSerializer
16
- belongs_to :line_item, serializer: Spree::V2::Tenant::LineItemSerializer
17
16
  has_one :id_card, serializer: Spree::V2::Tenant::IdCardSerializer
18
17
  has_many :guest_dynamic_fields, serializer: Spree::V2::Tenant::GuestDynamicFieldSerializer
19
18
 
@@ -2,11 +2,13 @@ module Spree
2
2
  module PermittedAttributes
3
3
  @@vendor_attributes << :logo
4
4
 
5
+ # Permitted all guest attributes for now as permitting only some guest attributes is not working by design
6
+ # of spree add_item service, if we want to only permit some guest attributes,
7
+ # we need to override most part of add_item service.
5
8
  @@line_item_attributes += %i[
6
9
  from_date
7
10
  to_date
8
- line_item_seats_attributes
9
- date
11
+ guests_attributes
10
12
  ]
11
13
 
12
14
  @@user_attributes += %i[
@@ -49,16 +49,16 @@ en:
49
49
  empty_info: "No vendor information available."
50
50
 
51
51
  telegram_bot:
52
- empty_info: "No <b>Telegram Bot</b> found"
52
+ empty_info: "No <b>Telegram Bot</b> found"
53
53
 
54
54
  guest_card_classes:
55
55
  empty_info: "No guest card classes information available."
56
56
  background_image: "Background Image"
57
57
  guest_dynamic_field:
58
- errors:
59
- pre_registration_required: "is required before ticket issuance"
60
- post_registration_required: "must be completed after purchase"
61
- during_check_in_required: "is required during check-in"
58
+ errors:
59
+ pre_registration_required: "is required before ticket issuance"
60
+ post_registration_required: "must be completed after purchase"
61
+ during_check_in_required: "is required during check-in"
62
62
  google_wallet:
63
63
  note: "Click <b>Create</b> or <b> Update</b> to connect to Google Wallet after filled all information "
64
64
  google_wallet_class_created: "Google Wallet class created successfully."
@@ -105,6 +105,12 @@ en:
105
105
  out_of_stock: "%{variant_name} is out of stock"
106
106
  product_kind_option_types:
107
107
  empty_info: "<b>Note:</b> Set service option types to service first. To edit, go to <b>Details</b> tab > <b>Option Types</b>"
108
+
109
+ line_item:
110
+ validation:
111
+ exceeded_max_quantity_per_order: "Exceeded maximum quantity per order"
112
+ seats_are_required: "Seats are required for all guests"
113
+
108
114
  vectors:
109
115
  icons:
110
116
  info_rules: 'Only allow <b>%{allow_extensions}</b> files. Icons are stored inside "images/" folder, eg. app/assets/images/backend-adjust.svg.'
@@ -152,8 +158,8 @@ en:
152
158
  orders:
153
159
  total: "Total: %{orders_count} invoices"
154
160
  update_order_status:
155
- success: 'Order Status update successfully'
156
- fail: 'Order Status fail to update '
161
+ success: "Order Status update successfully"
162
+ fail: "Order Status fail to update "
157
163
 
158
164
  account_deletion:
159
165
  title:
@@ -193,7 +199,7 @@ en:
193
199
  send_failed_or_method_not_support: "Send failed or method not support"
194
200
  subscribe: "Use Service"
195
201
  full_name: "name"
196
- store_credits: 'Credits'
202
+ store_credits: "Credits"
197
203
  address: "Address"
198
204
  billing_address: "Billing Address"
199
205
  shipping_address: "Shipping Address"
@@ -280,9 +286,9 @@ en:
280
286
  match_any: "Some line items must from selected age group"
281
287
  match_all: "All line items must from selected age group"
282
288
  billing:
283
- six_month_discount: '6 Months discount'
289
+ six_month_discount: "6 Months discount"
284
290
  twelve_month_discount: "12 Months discount"
285
- penalty_rate: 'Penalty Rate in %'
291
+ penalty_rate: "Penalty Rate in %"
286
292
  penalty_label: "Penalty Label"
287
293
  customer_id: "Customer ID"
288
294
  subscription:
@@ -343,11 +349,11 @@ en:
343
349
  fails: "Invoice for this month is already exist "
344
350
  customers: "Customers"
345
351
  apply_promotion:
346
- success: "Promotion Created"
347
- fails: "Promotion Creation Failed"
352
+ success: "Promotion Created"
353
+ fails: "Promotion Creation Failed"
348
354
  delete_promotion:
349
- success: "Promotion deleted"
350
- fails: "Promotion Deletion Failed"
355
+ success: "Promotion deleted"
356
+ fails: "Promotion Deletion Failed"
351
357
  service_start_date: "Service Start Date"
352
358
  export: "Export"
353
359
  select_year: "Select Year"
@@ -602,30 +608,29 @@ en:
602
608
 
603
609
  variant_availability:
604
610
  item_available_instock: Only 1 item available in stock.
605
- items_available_instock: Only %{available_quantity} items available in stock.
606
- items_out_of_stock: Item out of Stock.
611
+ items_available_instock: Only %{available_quantity} items available in stock.
612
+ items_out_of_stock: Item out of Stock.
607
613
 
608
614
  account_link:
609
615
  failure: "Failed to link your %{identity_type} account: %{reason}"
610
616
  s3:
611
617
  image:
612
618
  upload:
613
- fail: 'Failed to fetch the image'
614
- not_found: 'Image not found'
619
+ fail: "Failed to fetch the image"
620
+ not_found: "Image not found"
615
621
  amenity:
616
622
  update_success: Option Type updated successfully.
617
623
  user_roles_assigner:
618
- user_not_found: 'User not found'
619
- roles_empty: 'Roles are empty'
620
- roles_required: 'Roles are required'
621
- user_already_assigned: 'User already assigned to this vendor'
624
+ user_not_found: "User not found"
625
+ roles_empty: "Roles are empty"
626
+ roles_required: "Roles are required"
627
+ user_already_assigned: "User already assigned to this vendor"
622
628
  invite:
623
- url_not_found: 'Invite link not found or have been expired'
624
- accept_fail: 'Failed to accept invite'
625
- url_expired: 'Invitation link is expired'
626
- already_invited: 'Failed: User already invited to event'
627
- update_fail: 'Failed: to Update invite user'
629
+ url_not_found: "Invite link not found or have been expired"
630
+ accept_fail: "Failed to accept invite"
631
+ url_expired: "Invitation link is expired"
632
+ already_invited: "Failed: User already invited to event"
633
+ update_fail: "Failed: to Update invite user"
628
634
  event_blazer_queries:
629
- success: 'Event saved Successfully'
630
- fail: 'Event already saved'
631
-
635
+ success: "Event saved Successfully"
636
+ fail: "Event already saved"
@@ -55,7 +55,7 @@ km:
55
55
  empty_info: "មិនមានព័ត៌មានអំពីអ្នកលក់ទេ"
56
56
 
57
57
  telegram_bot:
58
- empty_info: "No <b>Telegram Bot</b> found"
58
+ empty_info: "No <b>Telegram Bot</b> found"
59
59
 
60
60
  guest_card_classes:
61
61
  empty_info: "មិនមានព័ត៌មានអំពីកាតភ្ញៀវទេ"
@@ -97,6 +97,11 @@ km:
97
97
  product_kind_option_types:
98
98
  empty_info: "<b>ចំណាំ:</b> កំណត់ប្រភេទសម្រាប់ផលិតផល. ដើម្បីកែប្រែ, សូមចូលទៅ <b>លម្អិត</b> tab > <b>ប្រភេទ</b>"
99
99
 
100
+ line_item:
101
+ validation:
102
+ exceeded_max_quantity_per_order: "លើសពីបរិមាណអតិបរមាក្នុងមួយការបញ្ជាទិញ"
103
+ seats_are_required: "ត្រូវការលេខកៅអីសម្រាប់ភ្ញៀវទាំងអស់"
104
+
100
105
  subscription:
101
106
  validation:
102
107
  out_of_range: "Subscription date is out of range."
@@ -174,7 +179,7 @@ km:
174
179
  send_failed_or_method_not_support: "Send failed or method not support"
175
180
  subscribe: "ប្រើសេវាកម្ម"
176
181
  full_name: "ឈ្មោះពេញ"
177
- store_credits: 'Credits'
182
+ store_credits: "Credits"
178
183
  address: "អាសយដ្ឋាន"
179
184
  billing_address: "អាសយដ្ឋានទូទាត់"
180
185
  shipping_address: "អាសយដ្ឋានប្រើ​ប្រាស់"
@@ -252,9 +257,9 @@ km:
252
257
  match_any: "Some line items must from selected age group"
253
258
  match_all: "All line items must from selected age group"
254
259
  billing:
255
- six_month_discount: 'Six Month discount'
260
+ six_month_discount: "Six Month discount"
256
261
  twelve_month_discount: "Twelve Month discount"
257
- penalty_rate: 'ការផាកពិន័យគិតជាភាគរយ'
262
+ penalty_rate: "ការផាកពិន័យគិតជាភាគរយ"
258
263
  code: "code"
259
264
  name: "name"
260
265
  logo: "logo"
@@ -400,29 +405,29 @@ km:
400
405
 
401
406
  variant_availability:
402
407
  item_available_instock: ទំនិញក្នុងស្តុកមានតែ 1 ប៉ុណ្ណោះ
403
- items_available_instock: ទំនិញក្នុងស្តុកមានតែ %{available_quantity} ប៉ុណ្ណោះ
404
- items_out_of_stock: ទំនិញអស់ពីស្តុក
408
+ items_available_instock: ទំនិញក្នុងស្តុកមានតែ %{available_quantity} ប៉ុណ្ណោះ
409
+ items_out_of_stock: ទំនិញអស់ពីស្តុក
405
410
 
406
411
  account_link:
407
412
  failure: "បរាជ័យក្នុងការភ្ជាប់គណនី %{identity_type}: %{reason}"
408
413
  s3:
409
414
  image:
410
415
  upload:
411
- fail: 'បានបរាជ័យក្នុងការទាញយករូបភាព'
412
- not_found: 'រកមិនឃើញរូបភាព'
416
+ fail: "បានបរាជ័យក្នុងការទាញយករូបភាព"
417
+ not_found: "រកមិនឃើញរូបភាព"
413
418
  user_roles_assigner:
414
- user_not_found: 'រកមិនឃើញអ្នកប្រើប្រាស់'
415
- roles_empty: 'តួនាទីគឺទទេ'
416
- roles_required: 'តួនាទីត្រូវបានទាមទារ'
417
- user_already_assigned: 'អ្នកប្រើប្រាស់បានបង្កើតតួនាទីរួចហើយ'
419
+ user_not_found: "រកមិនឃើញអ្នកប្រើប្រាស់"
420
+ roles_empty: "តួនាទីគឺទទេ"
421
+ roles_required: "តួនាទីត្រូវបានទាមទារ"
422
+ user_already_assigned: "អ្នកប្រើប្រាស់បានបង្កើតតួនាទីរួចហើយ"
418
423
 
419
424
  invite:
420
- url_not_found: 'រកមិនឃើញតំណអញ្ជើញ ឬផុតកំណត់ហើយ'
421
- accept_fail: 'បរាជ័យក្នុងការទទួលយកការអញ្ជើញ'
422
- url_expired: 'តំណ​អញ្ជើញ​បាន​ផុត​កំណត់'
423
- already_invited: 'បរាជ័យ៖ អ្នកប្រើប្រាស់បានអញ្ជើញចូលរួមព្រឹត្តិការណ៍រួចហើយ'
424
- update_fail: 'បរាជ័យ៖ ធ្វើបច្ចុប្បន្នភាពអ្នកប្រើប្រាស់អញ្ជើញ'
425
+ url_not_found: "រកមិនឃើញតំណអញ្ជើញ ឬផុតកំណត់ហើយ"
426
+ accept_fail: "បរាជ័យក្នុងការទទួលយកការអញ្ជើញ"
427
+ url_expired: "តំណ​អញ្ជើញ​បាន​ផុត​កំណត់"
428
+ already_invited: "បរាជ័យ៖ អ្នកប្រើប្រាស់បានអញ្ជើញចូលរួមព្រឹត្តិការណ៍រួចហើយ"
429
+ update_fail: "បរាជ័យ៖ ធ្វើបច្ចុប្បន្នភាពអ្នកប្រើប្រាស់អញ្ជើញ"
425
430
 
426
431
  event_blazer_queries:
427
- success: 'បានរក្សាទុកព្រឹត្តិការណ៍ដោយជោគជ័យ'
428
- fail: 'បានរក្សាទុកព្រឹត្តិការណ៍រួចហើយs'
432
+ success: "បានរក្សាទុកព្រឹត្តិការណ៍ដោយជោគជ័យ"
433
+ fail: "បានរក្សាទុកព្រឹត្តិការណ៍រួចហើយs"
data/config/routes.rb CHANGED
@@ -507,7 +507,6 @@ Spree::Core::Engine.add_routes do
507
507
  resources :id_cards, only: %i[create update destroy]
508
508
  end
509
509
 
510
- resources :dynamic_fields, only: :index
511
510
  resources :product_dynamic_fields, only: :index
512
511
  resources :dynamic_field_options, only: :index
513
512
 
@@ -0,0 +1,5 @@
1
+ class AddSectionToCmProductDynamicFields < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :cm_product_dynamic_fields, :section, :integer, if_not_exists: true
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module SpreeCmCommissioner
2
- VERSION = '2.1.5-pre1'.freeze
2
+ VERSION = '2.1.5-pre4'.freeze
3
3
 
4
4
  module_function
5
5
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_cm_commissioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5.pre.pre1
4
+ version: 2.1.5.pre.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-09-15 00:00:00.000000000 Z
11
+ date: 2025-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree
@@ -977,7 +977,6 @@ files:
977
977
  - app/controllers/spree/api/v2/tenant/cms_pages_controller.rb
978
978
  - app/controllers/spree/api/v2/tenant/customer_notifications_controller.rb
979
979
  - app/controllers/spree/api/v2/tenant/dynamic_field_options_controller.rb
980
- - app/controllers/spree/api/v2/tenant/dynamic_fields_controller.rb
981
980
  - app/controllers/spree/api/v2/tenant/guests_controller.rb
982
981
  - app/controllers/spree/api/v2/tenant/homepage_sections_controller.rb
983
982
  - app/controllers/spree/api/v2/tenant/id_cards_controller.rb
@@ -2746,6 +2745,7 @@ files:
2746
2745
  - db/migrate/20250827022757_create_spree_cm_commissioner_check_in_rules.rb
2747
2746
  - db/migrate/20250827032901_add_check_in_session_to_check_ins.rb
2748
2747
  - db/migrate/20250827083828_add_unique_index_on_guest_id_check_in_session_id_to_cm_check_ins.rb
2748
+ - db/migrate/20250902092904_add_section_to_cm_product_dynamic_fields.rb
2749
2749
  - db/migrate/20250903085931_add_importable_to_cm_imports.rb
2750
2750
  - db/migrate/20250911100738_drop_cm_variant_blocks.rb
2751
2751
  - db/migrate/20250911100835_add_variant_id_to_cm_blocks.rb
@@ -1,38 +0,0 @@
1
- module Spree
2
- module Api
3
- module V2
4
- module Tenant
5
- class DynamicFieldsController < BaseController
6
- before_action :load_product, only: :index
7
-
8
- # override
9
- def collection
10
- return @collection if defined?(@collection)
11
-
12
- dynamic_fields = @product.dynamic_fields.includes(:dynamic_field_options)
13
- if params[:phase].present?
14
- requested_phase = params[:phase].to_s
15
- if SpreeCmCommissioner::DynamicField.data_fill_stages.key?(requested_phase)
16
- dynamic_fields = dynamic_fields.where(data_fill_stage: requested_phase)
17
- end
18
- end
19
-
20
- @collection = dynamic_fields.order(:position)
21
- end
22
-
23
- private
24
-
25
- def load_product
26
- return render_error_payload({ error: 'product_id is required' }, 400) if params[:product_id].blank?
27
-
28
- @product ||= Spree::Product.find(params[:product_id])
29
- end
30
-
31
- def collection_serializer
32
- Spree::V2::Tenant::DynamicFieldSerializer
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end