Skip to content

Commit

Permalink
Merged PR 57983: Fix cannot clear preferences or data fields in custo…
Browse files Browse the repository at this point in the history
…mer account

## What's being changed

The Newsletter controller that is hit when customers save their newsletter subscription, preferences, data fields or list memberships from within their customer account.

## Why it's being changed

We had some bits of conditional logic in place here dating back 6 years, that prevented the _clearing_ or resetting of preferences and data fields. So it was impossible to unset all preference checkboxes and opt out of everything. In addition any data field values that were cleared would not result in those values being cleared upstream in Dotdigital, and cleared date-type values would actually cause today's date to be set as a replacement.

## How to review / test this change

- Configure your options to display customer preferences and data fields
- Log in as a customer and check some preferences, save
- Try to uncheck all preferences, save > your options should all be unchecked in Dotdigital
- For a thorough test of data fields, you want to be displaying in the account one of each type (Numeric, String, Date and Boolean)
- Opt out or uncheck or clear all of these data field values, confirming that these are reflected on DD
- Make sure in particular that cleared dates are subsequently null in DD

Related work items: #269315
  • Loading branch information
sta1r committed Sep 23, 2024
1 parent a64a8fe commit 82adf10
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Controller/Customer/Newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,24 +350,28 @@ private function getDataFields($client, $paramDataFields)
foreach ($paramDataFields as $key => $value) {
/*
* Allow boolean "0" to pass (e.g. "No" for "Yes/No" select)
* as well as any other truthy $value
* Empty Dates will not be adjusted.
*/
if (isset($processedFields[$key]) && ($value || $value === "0")) {
if (isset($processedFields[$key])) {
if ($processedFields[$key] == 'Numeric') {
$paramDataFields[$key] = (int)$value;
$paramDataFields[$key] = (int) $value;
}
if ($processedFields[$key] == 'String') {
$paramDataFields[$key] = (string)$value;
$paramDataFields[$key] = (string) $value;
}
if ($processedFields[$key] == 'Date') {
$paramDataFields[$key] = $this->dateField
->getScopeAdjustedDate(
$this->storeManager->getStore()->getId(),
$value
);
if (!$value) {
$paramDataFields[$key] = '';
} else {
$paramDataFields[$key] = $this->dateField
->getScopeAdjustedDate(
$this->storeManager->getStore()->getId(),
$value
);
}
}
if ($processedFields[$key] == 'Boolean') {
$paramDataFields[$key] = (bool)$value;
$paramDataFields[$key] = (bool) $value;
}
$data[] = [
'Key' => $key,
Expand All @@ -389,14 +393,12 @@ private function getDataFields($client, $paramDataFields)
*/
private function processContactPreferences(Client $client, $contactId): bool
{
$paramPreferences = $this->request->getParam('preferences', []);
$preferencesFromSession = $this->customerSession->getDmContactPreferences();

if (empty($paramPreferences) || empty($preferencesFromSession)) {
if (empty($preferencesFromSession)) {
return true;
}

$preferences = $this->processParamPreferences($paramPreferences);
$preferences = $this->processParamPreferences($this->request->getParam('preferences', []));
$this->augmentPreferencesFromSession($preferencesFromSession, $preferences);

foreach ($preferences as $id => $preference) {
Expand Down

0 comments on commit 82adf10

Please sign in to comment.