Skip to content

Commit

Permalink
Merged PR 57979: Fix upstream preferences not displaying in customer …
Browse files Browse the repository at this point in the history
…account

## What's being changed

Preferences, lists and data field visibility in the customer account.

## Why it's being changed

Pre-existing preferences, list membership and data field values were not displaying in the customer account at first, if the customer did not yet have a Dotdigital contact id in the table.

This was a regression from [this commit](https://dev.azure.com/dotdigital/ec/_git/ec-core-magento2-extension/commit/d96121a2b26d54d8ec0c524696dbe42880e47ef4) in v4.22.0.

## How to review / test this change

- Create a contact in Dotdigital
- Assign list membership
- Assign some data fields
- Assign marketing preferences
- In Magento, configure your options to display these lists, DFs and prefs in the customer account
- Create a customer account in Magento using the same email
- In the 'Newsletter Subscriptions' page, you should see existing preferences, lists and data fields
- Test with another contact that already has a contact id
- Test changing and updating values
- Log in with a contact, then in the background delete their contact id (does anything break)
- Log in with a contact, then in the background delete their row in email_contact (you should see the account's preferences listed, but nothing checked)

Related work items: #270677
  • Loading branch information
sta1r committed Sep 23, 2024
1 parent 661691b commit a64a8fe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ViewModel/Customer/Account/AddressBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getAdditionalBooksToShow()
$this->storeManager->getWebsite()->getId()
);
$contactFromTable = $this->containerViewModel->getContactFromTable();
if (! empty($additionalFromConfig) && $contactFromTable && $contactFromTable->getContactId()) {
if (! empty($additionalFromConfig) && $contactFromTable) {
$contact = $this->containerViewModel->getConnectorContact();
if (isset($contact->id) && isset($contact->status) && $contact->status !== 'PendingOptIn') {
$addressBooks = $this->containerViewModel->getApiClient()
Expand Down
2 changes: 1 addition & 1 deletion ViewModel/Customer/Account/DataFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getDataFieldsToShow()
$contactFromTable = $this->containerViewModel->getContactFromTable();
$dataFieldsFromConfig = explode(',', $dataFieldsFromConfig);

if ($contactFromTable && $contactFromTable->getContactId()) {
if ($contactFromTable) {
$contact = $this->containerViewModel->getConnectorContact();
if (isset($contact->id)) {
$contactDataFields = $contact->dataFields ?? [];
Expand Down
21 changes: 12 additions & 9 deletions ViewModel/Customer/Account/Preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,26 @@ public function __construct(
*/
public function getPreferencesToShow()
{
$preferences = [];
$processedPreferences = [];
$contactFromTable = $this->containerViewModel->getContactFromTable();

if ($contactFromTable && $contactFromTable->getContactId()) {
if (!$contactFromTable) {
$preferences = $this->containerViewModel->getApiClient()->getPreferences();
} elseif ($contactFromTable->getContactId()) {
$preferences = $this->containerViewModel->getApiClient()->getPreferencesForContact(
$contactFromTable->getContactId()
);
} else {
$contact = $this->containerViewModel->getConnectorContact();
if (isset($contact->id)) {
$preferences = $this->containerViewModel->getApiClient()->getPreferencesForContact($contact->id);
if (is_array($preferences)) {
$processedPreferences = $this->processPreferences($preferences, $processedPreferences);
}
}
} else {
$preferences = $this->containerViewModel->getApiClient()->getPreferences();
if (is_array($preferences)) {
$processedPreferences = $this->processPreferences($preferences, $processedPreferences);
}
}

if (!empty($preferences)) {
$processedPreferences = $this->processPreferences($preferences, $processedPreferences);
}
$this->customerSession->setDmContactPreferences($processedPreferences);
return $processedPreferences;
}
Expand Down

0 comments on commit a64a8fe

Please sign in to comment.