From 43c04415ef4fc007f54acf25772d527ee69ef661 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 20 Mar 2017 11:59:29 +0200 Subject: [PATCH] Support changing primary vendor contact --- app/Ninja/Repositories/VendorRepository.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Ninja/Repositories/VendorRepository.php b/app/Ninja/Repositories/VendorRepository.php index e0729a8f7a09..232a66cdfdda 100644 --- a/app/Ninja/Repositories/VendorRepository.php +++ b/app/Ninja/Repositories/VendorRepository.php @@ -95,6 +95,15 @@ class VendorRepository extends BaseRepository $vendorcontactIds = []; + // If the primary is set ensure it's listed first + usort($vendorcontacts, function ($left, $right) { + if (isset($right['is_primary']) && isset($left['is_primary'])) { + return $right['is_primary'] - $left['is_primary']; + } else { + return 0; + } + }); + foreach ($vendorcontacts as $vendorcontact) { $vendorcontact = $vendor->addVendorContact($vendorcontact, $first); $vendorcontactIds[] = $vendorcontact->public_id;