Update line item removal in CartService when the line item doesn't exist

This commit is contained in:
Matt-Yorkley
2021-05-12 13:38:38 +01:00
parent 3b52b173e8
commit 38ce9eb0c4

View File

@@ -36,7 +36,7 @@ class CartService
loaded_variant = loaded_variants[variant_data[:variant_id]]
if loaded_variant.deleted? || !variant_data[:quantity].positive?
order.contents.remove(loaded_variant)
cart_remove(loaded_variant)
next
end
@@ -69,7 +69,15 @@ class CartService
if attributes[:quantity].positive?
@order.contents.update_or_create(variant, attributes)
else
@order.contents.remove(variant)
cart_remove(variant)
end
end
def cart_remove(variant)
begin
order.contents.remove(variant)
rescue ActiveRecord::RecordNotFound
# Nothing to remove; no line items for this variant were found.
end
end