Skip to content

Commit

Permalink
fix: missing phone number for existing donors not logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
glaubersilva committed Apr 18, 2024
1 parent fed13cb commit f849eea
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/DonationForms/Actions/GetOrCreateDonor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,23 @@ public function __invoke(
// first check if donor exists as a user
$donor = $userId ? Donor::whereUserId($userId) : null;

// If they exist as a donor & user then make sure they don't already own this email before adding to their additional emails list..
// if they exist as a donor & user then make sure they don't already own this email before adding to their additional emails list..
if ($donor && !$donor->hasEmail($donorEmail) && !Donor::whereEmail($donorEmail)) {
$donor->additionalEmails = array_merge($donor->additionalEmails ?? [], [$donorEmail]);
$donor->save();
}

if ($donor && empty($donor->phone)) {
$donor->phone = $donorPhone;
$donor->save();
}

// if donor is not a user than check for any donor matching this email
if (!$donor) {
$donor = Donor::whereEmail($donorEmail);
}

// if they exist as a donor & user but don't have a phone number then add it to their profile.
if ($donor && empty($donor->phone)) {
$donor->phone = $donorPhone;
$donor->save();
}

// if no donor exists then create a new one using their personal information from the form.
if (!$donor) {
$donor = Donor::create([
Expand Down

0 comments on commit f849eea

Please sign in to comment.