2022-09-08 15:10:56 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-11-17 17:14:31 +01:00
|
|
|
# module definition
|
|
|
|
module Cart; end
|
|
|
|
|
2022-09-08 15:10:56 +02:00
|
|
|
# Provides methods for set offer to item in cart
|
|
|
|
class Cart::SetOfferService
|
|
|
|
def call(order, orderable, is_offered)
|
2023-01-09 17:36:11 +01:00
|
|
|
item = order.order_items.find_by(orderable_type: orderable.class.name, orderable_id: orderable.id)
|
2022-09-08 15:10:56 +02:00
|
|
|
|
|
|
|
raise ActiveRecord::RecordNotFound if item.nil?
|
|
|
|
|
|
|
|
item.is_offered = is_offered
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
item.save
|
2022-10-14 10:52:24 +02:00
|
|
|
Cart::UpdateTotalService.new.call(order)
|
2022-09-08 15:10:56 +02:00
|
|
|
order.save
|
|
|
|
end
|
|
|
|
order.reload
|
|
|
|
end
|
|
|
|
end
|