1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00
fab-manager/app/services/cart/refresh_item_service.rb

21 lines
558 B
Ruby
Raw Normal View History

# frozen_string_literal: true
# Provides methods for refresh amount of order item
class Cart::RefreshItemService
def call(order, orderable)
raise Cart::InactiveProductError unless orderable.is_active
2023-01-09 17:36:11 +01:00
item = order.order_items.find_by(orderable_type: orderable.class.name, orderable_id: orderable.id)
raise ActiveRecord::RecordNotFound if item.nil?
item.amount = orderable.amount || 0
ActiveRecord::Base.transaction do
item.save
Cart::UpdateTotalService.new.call(order)
order.save
end
order.reload
end
end