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

18 lines
409 B
Ruby
Raw Normal View History

2022-08-19 19:59:13 +02:00
# 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?
ActiveRecord::Base.transaction do
item.destroy!
Cart::UpdateTotalService.new.call(order)
2022-08-19 19:59:13 +02:00
order.save
end
order.reload
end
end