mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-06 22:36:07 +00:00
Better messaging around deletion of customers
This commit is contained in:
@@ -3,6 +3,8 @@ class Customer < ActiveRecord::Base
|
||||
|
||||
belongs_to :enterprise
|
||||
belongs_to :user, class_name: Spree.user_class
|
||||
has_many :orders, class_name: Spree::Order
|
||||
before_destroy :check_for_orders
|
||||
|
||||
before_validation :downcase_email
|
||||
before_validation :empty_code
|
||||
@@ -28,4 +30,10 @@ class Customer < ActiveRecord::Base
|
||||
def associate_user
|
||||
self.user = user || Spree::User.find_by_email(email)
|
||||
end
|
||||
|
||||
def check_for_orders
|
||||
return true unless orders.any?
|
||||
errors[:base] << "Delete failed: customer has associated orders"
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user