spree_cm_commissioner 2.1.0.pre.pre2 → 2.1.2

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: a327dc0e2f40dd0da82e2f110b079f4ff3a81bec76974745c82a27a37b273c63
4
- data.tar.gz: 8ce2e93eaec4b8c005818e0c321430d598e3318a647b4caea08945b02291c785
3
+ metadata.gz: ee0ae4eae84a0969d4e124d27edbd5f05f82439960fe814dab8221f9e7b486da
4
+ data.tar.gz: fce2acf06b539cd00604bc66d1ae0bb2b951c20a3d1769b1a37405b3b0bbe986
5
5
  SHA512:
6
- metadata.gz: 923d60bccd00c23a3a6ad8b7ff8ea05b9204fd9f871f3664a24e7d761adc7fe75275ff850efedbe5c34454af4561d3c8830f29f6dc43450052ec90fb37cc45ca
7
- data.tar.gz: f5abc2ec078ab65c637f2f368d35d4d0b7c3d7337c7d9cddc13c94177f46b55e06bb39288eaab00087c3f6b4cfb6bdf4d2bf07fe5bdc29916500ad2481a153c3
6
+ metadata.gz: aae15d8c9a0c90580e07999aaea7c06410ac052c8570c9a5849864b40e871c979458932e222ea734c8fb433eb6d4923a6985a8d98e8fe6c66e775e66881e0edd
7
+ data.tar.gz: d6caf18d6baed70edf799ec7a719254fb144ce882bafe5fbdebcb3930913946e72191a53327803b0c016263e5fb4a0f6b6929309afa3ea602c15a635dc83c1e8
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GIT
34
34
  PATH
35
35
  remote: .
36
36
  specs:
37
- spree_cm_commissioner (2.1.0.pre.pre2)
37
+ spree_cm_commissioner (2.1.2)
38
38
  activerecord-multi-tenant
39
39
  activerecord_json_validator (~> 2.1, >= 2.1.3)
40
40
  aws-sdk-cloudfront
@@ -18,7 +18,7 @@ module Spree
18
18
 
19
19
  # override
20
20
  def resource
21
- @resource ||= collection.find_by!(slug: params[:id])
21
+ @resource ||= Spree::Vendor.by_vendor_id!(params[:id])
22
22
  end
23
23
 
24
24
  # override
@@ -38,6 +38,8 @@ module Spree
38
38
 
39
39
  # override
40
40
  def required_schema
41
+ return nil unless action_name == 'index'
42
+
41
43
  SpreeCmCommissioner::AccommodationRequestSchema
42
44
  end
43
45
  end
@@ -63,13 +63,15 @@ module SpreeCmCommissioner
63
63
  def process_line_items_attributes(params)
64
64
  date_param = raw_params[:date] || Date.current.to_s
65
65
 
66
+ load_variant
67
+
66
68
  params[:line_items_attributes].each_value do |item|
67
69
  pickup_time_minutes = item[:from_date]
68
70
  combined_datetime = "#{date_param} #{pickup_time_minutes}"
69
71
 
70
72
  item[:from_date] = combined_datetime
71
73
  item[:to_date] = combined_datetime
72
- item[:variant_id] = load_variant
74
+ item[:variant_id] = @variant.id
73
75
  item[:vendor_id] = current_vendor.id
74
76
  item[:quantity] = 1
75
77
  item[:currency] = 'USD'
@@ -100,7 +102,7 @@ module SpreeCmCommissioner
100
102
  end
101
103
 
102
104
  def load_variant
103
- trip.product.master.id
105
+ @variant = trip.product.variants.first
104
106
  end
105
107
  end
106
108
  end
@@ -0,0 +1,56 @@
1
+ module SpreeCmCommissioner
2
+ class TripStopsCreator < BaseInteractor
3
+ delegate :trip, :origin_place, :destination_place, :departure_time, :duration_seconds, to: :context
4
+
5
+ def call
6
+ validate_context!
7
+
8
+ ActiveRecord::Base.transaction do
9
+ create_origin_stop
10
+ create_destination_stop
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def validate_context!
17
+ context.fail!(message: 'Trip is missing') unless trip
18
+ context.fail!(message: 'Origin place is missing') unless origin_place
19
+ context.fail!(message: 'Destination place is missing') unless destination_place
20
+ context.fail!(message: 'Departure time is missing') unless departure_time
21
+ context.fail!(message: 'Duration (seconds) is missing') unless duration_seconds
22
+ end
23
+
24
+ def create_origin_stop
25
+ attributes = {
26
+ trip: trip,
27
+ stop_place: origin_place,
28
+ location_place: origin_place,
29
+ stop_type: :boarding
30
+ }
31
+
32
+ attributes[:departure_time] = departure_time
33
+
34
+ origin_trip_stop = SpreeCmCommissioner::TripStop.new(attributes)
35
+
36
+ context.fail!(message: origin_trip_stop.errors.full_messages.to_sentence) unless origin_trip_stop.save
37
+ context.origin_trip_stop = origin_trip_stop
38
+ end
39
+
40
+ def create_destination_stop
41
+ attributes = {
42
+ trip: trip,
43
+ stop_place: destination_place,
44
+ location_place: destination_place,
45
+ stop_type: :drop_off
46
+ }
47
+
48
+ attributes[:arrival_time] = departure_time + duration_seconds.seconds
49
+
50
+ destination_trip_stop = SpreeCmCommissioner::TripStop.new(attributes)
51
+
52
+ context.fail!(message: destination_trip_stop.errors.full_messages.to_sentence) unless destination_trip_stop.save
53
+ context.destination_trip_stop = destination_trip_stop
54
+ end
55
+ end
56
+ end
@@ -66,9 +66,12 @@ module SpreeCmCommissioner
66
66
 
67
67
  def find_existing_user
68
68
  user_data = context.user_data
69
+ intel_phone = normalized_phone_number(user_data['intel_phone'])
69
70
 
70
- context.user = Spree::User.find_by(
71
- 'email = ? OR phone_number = ?', user_data['email'], user_data['phoneNum']
71
+ context.user = Spree::User.by_non_tenant.find_by(
72
+ 'email = :email OR intel_phone_number = :intel_phone',
73
+ email: user_data['email'],
74
+ intel_phone: intel_phone
72
75
  )
73
76
  end
74
77
 
@@ -84,6 +87,7 @@ module SpreeCmCommissioner
84
87
  last_name: user_data['lastName'],
85
88
  email: user_data['email'],
86
89
  phone_number: user_data['phoneNum'],
90
+ intel_phone_number: normalized_phone_number(user_data['phoneNum']),
87
91
  password: SecureRandom.base64(16),
88
92
  user_identity_providers: [identity]
89
93
  )
@@ -119,6 +123,10 @@ module SpreeCmCommissioner
119
123
  context.data = signed_data
120
124
  end
121
125
 
126
+ def normalized_phone_number(phone_number)
127
+ SpreeCmCommissioner::PhoneNumberParser.call(phone_number: phone_number).intel_phone_number
128
+ end
129
+
122
130
  def session_id
123
131
  payload = { user_id: context.user.id }
124
132
  SpreeCmCommissioner::UserSessionJwtToken.encode(payload, context.user.reload.secure_token)
@@ -42,8 +42,7 @@ module SpreeCmCommissioner
42
42
  'bib-pre-generation-on-create' => 'boolean',
43
43
  'seat-number-positions' => 'array',
44
44
  'seat-type' => 'string',
45
- 'intercity-taxi' => 'string',
46
- 'pickup-time' => 'integer'
45
+ 'intercity-taxi' => 'string'
47
46
  }.freeze
48
47
 
49
48
  included do
@@ -33,6 +33,7 @@ module SpreeCmCommissioner
33
33
 
34
34
  base.multi_tenant :tenant, class_name: 'SpreeCmCommissioner::Tenant'
35
35
  base.scope :by_tenant, -> (tenant_id) { where(tenant_id: tenant_id) }
36
+ base.scope :by_non_tenant, -> { where(tenant_id: nil) }
36
37
  base.scope :vendor_users, -> (vendor_id) { joins(:role_users => :role).where(spree_roles: { vendor_id: vendor_id }).distinct }
37
38
 
38
39
  base.whitelisted_ransackable_attributes = %w[email first_name last_name gender phone_number]
@@ -1,5 +1,5 @@
1
1
  module SpreeCmCommissioner
2
- VERSION = '2.1.0-pre2'.freeze
2
+ VERSION = '2.1.2'.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.0.pre.pre2
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - You
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-08-28 00:00:00.000000000 Z
11
+ date: 2025-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree
@@ -1206,6 +1206,7 @@ files:
1206
1206
  - app/interactors/spree_cm_commissioner/transactional_email_sender.rb
1207
1207
  - app/interactors/spree_cm_commissioner/transit/draft_order_creator.rb
1208
1208
  - app/interactors/spree_cm_commissioner/trip_clone_creator.rb
1209
+ - app/interactors/spree_cm_commissioner/trip_stops_creator.rb
1209
1210
  - app/interactors/spree_cm_commissioner/unique_device_token_cron_executor.rb
1210
1211
  - app/interactors/spree_cm_commissioner/update_payment_gateway_status.rb
1211
1212
  - app/interactors/spree_cm_commissioner/user_contact_updater.rb
@@ -2720,7 +2721,6 @@ files:
2720
2721
  - db/migrate/20250725092713_add_block_type_to_cm_blocks.rb
2721
2722
  - db/migrate/20250731062816_add_departure_time_and_arrival_time_to_trip_stop.rb
2722
2723
  - db/migrate/20250807033035_create_spree_cm_commissioner_saved_guests.rb
2723
- - db/migrate/20250807040000_generate_pickup_time_integer_option_values.rb
2724
2724
  - db/migrate/20250808054835_add_saved_guest_reference_to_cm_blocks.rb
2725
2725
  - db/migrate/20250812015522_remove_unique_indexes_from_cm_user_identity_providers.rb
2726
2726
  - db/migrate/20250812121745_add_data_fill_stage_phase_to_cm_guests.rb
@@ -2885,9 +2885,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
2885
2885
  version: '2.7'
2886
2886
  required_rubygems_version: !ruby/object:Gem::Requirement
2887
2887
  requirements:
2888
- - - ">"
2888
+ - - ">="
2889
2889
  - !ruby/object:Gem::Version
2890
- version: 1.3.1
2890
+ version: '0'
2891
2891
  requirements:
2892
2892
  - none
2893
2893
  rubygems_version: 3.4.1
@@ -1,71 +0,0 @@
1
- class GeneratePickupTimeIntegerOptionValues < ActiveRecord::Migration[7.0]
2
- def up
3
- generate_time_option_values(
4
- option_type_name: 'pickup-time',
5
- option_type_presentation: 'Pickup Time',
6
- start_time: '00:00',
7
- end_time: '23:45',
8
- interval_minutes: 15
9
- )
10
- end
11
-
12
- def down
13
- remove_time_option_values('pickup-time')
14
- end
15
-
16
- private
17
-
18
- def generate_time_option_values(option_type_name:, option_type_presentation:, start_time:, end_time:, interval_minutes:)
19
- option_type = Spree::OptionType.find_by(name: option_type_name)
20
- unless option_type
21
- option_type = Spree::OptionType.new(name: option_type_name, presentation: option_type_presentation)
22
- option_type.save(validate: false)
23
- end
24
-
25
- # Ensure correct attributes and scope
26
- option_type.update_columns(attr_type: 'integer', kind: 'variant')
27
-
28
- Spree::OptionValue.where(option_type_id: option_type.id).delete_all
29
-
30
- time_slots = []
31
- current_time = parse_time(start_time)
32
- end_time_parsed = parse_time(end_time)
33
-
34
- while current_time <= end_time_parsed
35
- time_slots << current_time
36
- current_time += interval_minutes.minutes
37
- end
38
-
39
- rows = []
40
- time_slots.each_with_index do |time, index|
41
- minutes_since_midnight = (time.hour * 60) + time.min
42
- rows << {
43
- name: minutes_since_midnight.to_s,
44
- presentation: minutes_since_midnight.to_s,
45
- position: index,
46
- option_type_id: option_type.id,
47
- created_at: Time.current,
48
- updated_at: Time.current
49
- }
50
- end
51
-
52
- Spree::OptionValue.insert_all(rows) if rows.any?
53
- puts "Created #{rows.size} #{option_type_name} option values as integer minutes since midnight"
54
- end
55
-
56
- def remove_time_option_values(option_type_name)
57
- option_type = Spree::OptionType.find_by(name: option_type_name)
58
- return unless option_type
59
-
60
- count = Spree::OptionValue.where(option_type_id: option_type.id).count
61
- Spree::OptionValue.where(option_type_id: option_type.id).delete_all
62
- option_type.delete
63
- puts "Removed #{option_type_name} option type and #{count} option values"
64
- end
65
-
66
- def parse_time(time_string)
67
- Time.zone.parse("2000-01-01 #{time_string}")
68
- end
69
- end
70
-
71
-