mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-31 20:52:21 +01:00
18 lines
417 B
Ruby
18 lines
417 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
# Provides methods for remove order item to cart
|
||
|
class Cart::RemoveItemService
|
||
|
def call(order, orderable)
|
||
|
item = order.order_items.find_by(orderable: orderable)
|
||
|
|
||
|
raise ActiveRecord::RecordNotFound if item.nil?
|
||
|
|
||
|
order.amount -= (item.amount * item.quantity.to_i)
|
||
|
ActiveRecord::Base.transaction do
|
||
|
item.destroy!
|
||
|
order.save
|
||
|
end
|
||
|
order.reload
|
||
|
end
|
||
|
end
|