From 9fe183f125596902ddaeaedc5f086574596861ce Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 18 Oct 2016 14:22:04 +0300 Subject: [PATCH] Fix for deleting vendor contacts --- app/Ninja/Repositories/VendorRepository.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Ninja/Repositories/VendorRepository.php b/app/Ninja/Repositories/VendorRepository.php index 0dbb43ebd814..43500c0f1ae2 100644 --- a/app/Ninja/Repositories/VendorRepository.php +++ b/app/Ninja/Repositories/VendorRepository.php @@ -85,12 +85,22 @@ class VendorRepository extends BaseRepository $first = true; $vendorcontacts = isset($data['vendor_contact']) ? [$data['vendor_contact']] : $data['vendor_contacts']; + $vendorcontactIds = []; foreach ($vendorcontacts as $vendorcontact) { $vendorcontact = $vendor->addVendorContact($vendorcontact, $first); + $vendorcontactIds[] = $vendorcontact->public_id; $first = false; } + if ( ! $vendor->wasRecentlyCreated) { + foreach ($vendor->vendor_contacts as $contact) { + if (!in_array($contact->public_id, $vendorcontactIds)) { + $contact->delete(); + } + } + } + return $vendor; } }