Class: SpreeCmCommissioner::PricingModels::CreateWithRuleGroups

Inherits:
Object
  • Object
show all
Includes:
Spree::ServiceModule::Base
Defined in:
app/services/spree_cm_commissioner/pricing_models/create_with_rule_groups.rb

Instance Method Summary collapse

Instance Method Details

#call(vendor:, params:, route: nil, origin_place_id: nil, destination_place_id: nil) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/spree_cm_commissioner/pricing_models/create_with_rule_groups.rb', line 6

def call(vendor:, params:, route: nil, origin_place_id: nil, destination_place_id: nil)
  pricing_model = vendor.pricing_models.new(model_params(params))

  ApplicationRecord.transaction do
    pricing_model.save!
    build_rule_groups(pricing_model, params[:rule_groups])
    create_route_assignment(pricing_model, route, origin_place_id, destination_place_id) if route.present?
  end

  success(pricing_model)
rescue ActiveRecord::RecordInvalid => e
  failure(pricing_model, e.message)
end