Fix for deleting vendor contacts

This commit is contained in:
Hillel Coren 2016-10-18 14:22:04 +03:00
parent 6c02ee2c60
commit 9fe183f125

View File

@ -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;
}
}