7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/interactors/spree_cm_commissioner/customer_promotion_creator.rb', line 7
def call
customer = SpreeCmCommissioner::Customer.find(context.customer_id)
if customer.blank?
context.fail!(message: 'Customer not found')
return
end
promotion = find_or_initialize_promotion(customer)
if promotion.new_record?
create_promotion(promotion, customer, context.reason, context.discount_amount, context.store)
else
update_promotion(promotion, customer, context.reason, context.discount_amount)
end
context.success = true
rescue StandardError => e
context.fail!(message: e.message)
end
|