1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-04 15:24:23 +01:00
fab-manager/app/services/cart/set_offer_service.rb
Sylvain 451cd0e915 (test) add admin offer product to himself
Also: split AdminPayOrderTest in two files
2022-11-17 17:14:31 +01:00

22 lines
486 B
Ruby

# frozen_string_literal: true
# module definition
module Cart; end
# Provides methods for set offer to item in cart
class Cart::SetOfferService
def call(order, orderable, is_offered)
item = order.order_items.find_by(orderable: orderable)
raise ActiveRecord::RecordNotFound if item.nil?
item.is_offered = is_offered
ActiveRecord::Base.transaction do
item.save
Cart::UpdateTotalService.new.call(order)
order.save
end
order.reload
end
end