Class: SpreeCmCommissioner::IntercityTaxiOrder::Create
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::IntercityTaxiOrder::Create
- Defined in:
- app/services/spree_cm_commissioner/intercity_taxi_order/create.rb
Instance Attribute Summary collapse
-
#from_date ⇒ Object
readonly
Returns the value of attribute from_date.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#to_date ⇒ Object
readonly
Returns the value of attribute to_date.
-
#trip_id ⇒ Object
readonly
Returns the value of attribute trip_id.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(trip_id:, from_date:, to_date:, user_id:, quantity:) ⇒ Create
constructor
A new instance of Create.
Constructor Details
#initialize(trip_id:, from_date:, to_date:, user_id:, quantity:) ⇒ Create
Returns a new instance of Create.
16 17 18 19 20 21 22 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/create.rb', line 16 def initialize(trip_id:, from_date:, to_date:, user_id:, quantity:) @trip_id = trip_id @from_date = from_date @to_date = to_date @user_id = user_id @quantity = quantity.to_i <= 0 ? 1 : quantity.to_i end |
Instance Attribute Details
#from_date ⇒ Object (readonly)
Returns the value of attribute from_date.
4 5 6 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/create.rb', line 4 def from_date @from_date end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
4 5 6 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/create.rb', line 4 def quantity @quantity end |
#to_date ⇒ Object (readonly)
Returns the value of attribute to_date.
4 5 6 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/create.rb', line 4 def to_date @to_date end |
#trip_id ⇒ Object (readonly)
Returns the value of attribute trip_id.
4 5 6 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/create.rb', line 4 def trip_id @trip_id end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
4 5 6 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/create.rb', line 4 def user_id @user_id end |
Class Method Details
.call(trip_id:, from_date:, to_date:, user_id: nil, quantity: 1) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'app/services/spree_cm_commissioner/intercity_taxi_order/create.rb', line 6 def self.call(trip_id:, from_date:, to_date:, user_id: nil, quantity: 1) new( trip_id: trip_id, from_date: from_date, to_date: to_date, user_id: user_id, quantity: quantity ).call end |
Instance Method Details
#call ⇒ Object
24 25 26 27 28 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/intercity_taxi_order/create.rb', line 24 def call validate! 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_id: user_id) line_item = order.line_items.new( variant_id: variant.id, quantity: quantity, from_date: from_date, to_date: to_date, private_metadata: { trip_id: trip.id } ) build_guests_for!(line_item, quantity) order.save! order.update_with_updater! order end end |