Class: SpreeCmCommissioner::IntercityTaxiOrder::Create
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::IntercityTaxiOrder::Create
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/intercity_taxi_order/create.rb
Instance Method Summary collapse
-
#call(trip_id:, from_date:, to_date:, user: nil, quantity: 1, created_by: nil, channel: SpreeCmCommissioner::OrderChannelBitwise::SPREE_CHANNEL) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Instance Method Details
#call(trip_id:, from_date:, to_date:, user: nil, quantity: 1, created_by: nil, channel: SpreeCmCommissioner::OrderChannelBitwise::SPREE_CHANNEL) ⇒ Object
rubocop:disable Metrics/ParameterLists
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/create.rb', line 6 def call(trip_id:, from_date:, to_date:, user: nil, quantity: 1, created_by: nil, # rubocop:disable Metrics/ParameterLists channel: SpreeCmCommissioner::OrderChannelBitwise::SPREE_CHANNEL ) validate!(trip_id: trip_id, from_date: from_date, to_date: to_date, quantity: quantity) quantity = quantity.to_i order = ActiveRecord::Base.transaction do trip = SpreeCmCommissioner::Trip.find(trip_id) variant = trip.product.variants.first raise ArgumentError, 'No variant found for trip' if variant.blank? order = Spree::Order.new(state: 'cart', use_billing: true, user: user, created_by: created_by, channel: channel) = { trip_id: trip.id, service_origin_id: trip.service_origin_id.presence&.to_s }.compact line_item = order.line_items.new( variant_id: variant.id, quantity: quantity, from_date: from_date, to_date: to_date, private_metadata: ) build_guests_for!(line_item, quantity) assign_saved_guests_to_line_item(line_item) order.save! order.update_with_updater! order end success(order) rescue StandardError => e failure(nil, e.) end |