Sha256: 6588e9fe6414f36ac08b6cde35d123905bba0ff59bc39e5a2f4efed8fc96bc4e
Contents?: true
Size: 1.21 KB
Versions: 100
Compression:
Stored size: 1.21 KB
Contents
module Spree module Cart class RemoveItem prepend Spree::ServiceModule::Base def call(order:, variant:, quantity: nil, options: nil) options ||= {} quantity ||= 1 ActiveRecord::Base.transaction do line_item = remove_from_line_item(order: order, variant: variant, quantity: quantity, options: options) Spree::Dependencies.cart_recalculate_service.constantize.call(line_item: line_item, order: order, options: options) success(line_item) end end private def remove_from_line_item(order:, variant:, quantity:, options:) line_item = Spree::Dependencies.line_item_by_variant_finder.constantize.new.execute(order: order, variant: variant, options: options) raise ActiveRecord::RecordNotFound if line_item.nil? line_item.quantity -= quantity line_item.target_shipment = options[:shipment] if line_item.quantity.zero? order.line_items.destroy(line_item) else line_item.save! end line_item end end end end
Version data entries
100 entries across 100 versions & 1 rubygems