summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/models/product_cart.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/app/models/product_cart.rb b/app/models/product_cart.rb
index eb9cf9f..09e7a25 100644
--- a/app/models/product_cart.rb
+++ b/app/models/product_cart.rb
@@ -10,7 +10,7 @@ class ProductCart < ApplicationRecord
validate :sole_product_in_cart
def sole_product_in_cart
- return if cart.products.find_by(id: product_id).nil?
+ return if cart.nil? || cart.products.find_by(id: product_id).nil?
errors.add(:product_id, "cart already has product with id #{product_id}")
end