Class: SpreeCmCommissioner::Trips::CreateOpenDatedTrip
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::Trips::CreateOpenDatedTrip
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/trips/create_open_dated_trip.rb
Overview
Service class responsible for creating Open Dated trips in the booking system. Open Dated trips are flexible, date-agnostic products that can be redeemed on any scheduled trip within the same route. They don’t have fixed departure times or calendars.
Key characteristics of Open Dated trips:
-
is_open_dated: true
-
departure_time: nil (no fixed schedule)
-
No service calendar (not tied to specific dates)
-
Special “Open Dated” variant option
-
Can be linked to multiple fixed-date trips via ProductRelations (open_dated_pair)
-
No specific vehicle type (can be used on any vehicle in the route)
Required trip_form attributes for Open Dated trips:
-
route_id: The route this open dated trip is for
-
price: Ticket price
-
is_open_dated: Must be true
Instance Method Summary collapse
-
#call(vendor:, trip_form:) ⇒ Spree::ServiceModule::Result
Main service method that validates the trip form and orchestrates OT creation.
Instance Method Details
#call(vendor:, trip_form:) ⇒ Spree::ServiceModule::Result
Main service method that validates the trip form and orchestrates OT creation. Creates variant, trip, and inventory within a database transaction. Note: Open dated trips do NOT have calendars since they’re not date-specific.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/spree_cm_commissioner/trips/create_open_dated_trip.rb', line 29 def call(vendor:, trip_form:) return failure(nil, trip_form.errors..to_sentence) unless trip_form.valid_open_dated_data? ApplicationRecord.transaction do route = vendor.routes.find(trip_form.route_id) variant = create_variant!(vendor, trip_form) trip = create_trip!(vendor, trip_form, variant, route) generate_inventory!(variant) success(trip: trip, variant: variant, route: route) end rescue StandardError => e CmAppLogger.error( label: 'SpreeCmCommissioner::Trips::CreateOpenDatedTrip#call', data: { error_class: e.class.name, error_message: e., vendor_id: vendor&.id, route_id: trip_form&.route_id } ) failure(nil, e.) end |