From 38ce9eb0c42cc78501e63b73d8dee7dd91f24285 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 12 May 2021 13:38:38 +0100 Subject: [PATCH] Update line item removal in CartService when the line item doesn't exist --- app/services/cart_service.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/services/cart_service.rb b/app/services/cart_service.rb index 943baa5787..5587438996 100644 --- a/app/services/cart_service.rb +++ b/app/services/cart_service.rb @@ -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