Skip to content

Commit

Permalink
Fixed contact first/last name fields did not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Croker committed Feb 14, 2021
1 parent 61319a7 commit 221486c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.18.3 - Unreleased
### Fixed
- Fixed a bug in which an error was thrown when saving a user and contact first/last name fields did not exist ([#214](https://github.com/putyourlightson/craft-campaign/issues/214)).
- Fixed the day of the month checkbox labels for values over 29.

## 1.18.2 - 2021-02-10
Expand Down
13 changes: 4 additions & 9 deletions src/services/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,15 @@ public function syncUserMailingList(User $user, MailingListElement $mailingList)
$contact->userId = $user->id;
$contact->email = $user->email;

// Set first and last name from user fields if they exist
// Set first and last name from user fields only if they exist
if (isset($contact->firstName)) {
$contact->firstName = $user->firstName;
$contact->setFieldValue('firstName', $user->firstName);
}
if (isset($contact->lastName)) {
$contact->lastName = $user->lastName;
$contact->setFieldValue('lastName', $user->lastName);
}

$fieldValues = array_merge($user->getFieldValues(), [
'firstName' => $user->firstName,
'lastName' => $user->lastName,
]);

$contact->setFieldValues($fieldValues);
$contact->setFieldValues($user->getFieldValues());

if (!Craft::$app->getElements()->saveElement($contact)) {
return;
Expand Down

0 comments on commit 221486c

Please sign in to comment.