mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-04 15:24:23 +01:00
21 lines
514 B
Ruby
21 lines
514 B
Ruby
# 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
|
|
|
|
item = order.order_items.find_by(orderable: orderable)
|
|
|
|
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
|