Skip to content

Newsletter subscription in registration form not working #67

@arutr

Description

@arutr

One of the plugins in this module, which injects into customer extension attributes, breaks signing up for the newsletter when registering a customer account:

$subscriber = $this->subscriberResource->loadBySubscriberEmail(
$customer->getEmail(),
(int)$this->storeManager->getStore($customer->getStoreId())->getWebsiteId()
);
$subscriberStatus = !empty($subscriber['subscriber_status']) ? (int)$subscriber['subscriber_status'] : 0;
$isSubscribed = $subscriberStatus === SubscriberModel::STATUS_SUBSCRIBED;
$extension->setIsSubscribed($isSubscribed);
$customer->setExtensionAttributes($extension);

When creating an account, is_subscribed is set to 1. Currently this code sets it to 0 as $subscriber is empty, which prevents signing up for the newsletter later on in the code.

To fix this, after loading $subscriber, we need to check whether the array has data. If it doesn't, then we return $extension:

diff --git a/Extensions/Customer.php b/Extensions/Customer.php
--- a/Extensions/Customer.php	(revision 356cfc294b35b7fb212224c805978fd98b92abee)
+++ b/Extensions/Customer.php	(date 1771242539606)
@@ -44,6 +44,10 @@
             (int)$this->storeManager->getStore($customer->getStoreId())->getWebsiteId()
         );

+        if (!isset($subscriber['subscriber_id'])) {
+            return $extension;
+        }
+
         $subscriberStatus = !empty($subscriber['subscriber_status']) ? (int)$subscriber['subscriber_status'] : 0;
         $isSubscribed = $subscriberStatus === SubscriberModel::STATUS_SUBSCRIBED;
         $extension->setIsSubscribed($isSubscribed);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions