Skip to content

Commit 52d63fa

Browse files
committed
MC-29102: [2.4.x] [Magento Cloud] Customer receives newsletter unsubscription email after registering for new account
1 parent dfcf683 commit 52d63fa

File tree

6 files changed

+26
-52
lines changed

6 files changed

+26
-52
lines changed

app/code/Magento/Newsletter/Controller/Ajax/Status.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Newsletter\Controller\Ajax;
77

88
use Magento\Framework\App\Action;
9-
use Magento\Framework\App\Action\HttpGetActionInterface;
109
use Magento\Framework\Controller\ResultFactory;
1110
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\Framework\Validator\EmailAddress as EmailAddressValidator;
@@ -16,7 +15,7 @@
1615
/**
1716
* Newsletter subscription status verification controller.
1817
*/
19-
class Status extends Action\Action implements HttpGetActionInterface
18+
class Status extends Action\Action implements Action\HttpGetActionInterface
2019
{
2120
/**
2221
* @var EmailAddressValidator
@@ -67,15 +66,11 @@ public function execute()
6766
$response['subscribed'] = $this->guestSubscriptionChecker->isSubscribed($email);
6867
}
6968
} catch (LocalizedException $exception) {
70-
$response = [
71-
'errors' => true,
72-
'message' => $exception->getMessage(),
73-
];
69+
$this->logger->error($exception->getMessage());
70+
$response['errors'] = true;
7471
} catch (\Throwable $exception) {
75-
$response = [
76-
'errors' => true,
77-
'message' => __('Something went wrong.'),
78-
];
72+
$this->logger->error($exception->getMessage());
73+
$response['errors'] = true;
7974
}
8075

8176
/** @var \Magento\Framework\Controller\Result\Json $resultJson */

app/code/Magento/Newsletter/Model/GuestSubscriptionChecker.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class GuestSubscriptionChecker
1919
* @var ResourceConnection
2020
*/
2121
private $resourceConnection;
22+
2223
/**
2324
* @var StoreManagerInterface
2425
*/
@@ -39,6 +40,7 @@ public function __construct(ResourceConnection $resourceConnection, StoreManager
3940
*
4041
* @param string $subscriberEmail
4142
* @return bool
43+
* @throws \Magento\Framework\Exception\LocalizedException
4244
*/
4345
public function isSubscribed(string $subscriberEmail): bool
4446
{
@@ -53,9 +55,7 @@ public function isSubscribed(string $subscriberEmail): bool
5355
->where('customer_id = 0')
5456
->limit(1);
5557

56-
$result = (bool)$connection->fetchOne($select);
57-
58-
return $result;
58+
return (bool)$connection->fetchOne($select);
5959
}
6060

6161
return false;

app/code/Magento/Newsletter/view/frontend/web/js/newsletter-sign-up.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
define([
77
'jquery',
88
'uiElement',
9-
'mage/storage',
109
'mage/url',
1110
'subscriptionStatusResolver',
1211
'mage/validation'
13-
], function ($, Component, storage, urlBuilder, subscriptionStatusResolver) {
12+
], function ($, Component, urlBuilder, subscriptionStatusResolver) {
1413
'use strict';
1514

1615
return Component.extend({

app/code/Magento/Newsletter/view/frontend/web/js/subscription-status-resolver.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55

66
define([
77
'jquery',
8-
'mage/storage',
98
'mage/url'
10-
], function ($, storage, urlBuilder) {
9+
], function ($, urlBuilder) {
1110
'use strict';
1211

1312
return function (email, deferred) {
@@ -17,7 +16,11 @@ define([
1716
email: email
1817
}
1918
).done(function (response) {
20-
deferred.resolve(response.subscribed);
19+
if (response.errors) {
20+
deferred.reject();
21+
} else {
22+
deferred.resolve(response.subscribed);
23+
}
2124
}).fail(function () {
2225
deferred.reject();
2326
});

dev/tests/integration/testsuite/Magento/Newsletter/Controller/Ajax/StatusTest.php

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,31 @@
77

88
namespace Magento\Newsletter\Controller\Ajax;
99

10+
use Magento\Framework\Serialize\Serializer\Json;
1011
use Magento\TestFramework\TestCase\AbstractController;
1112

1213
/**
1314
* Test Subscriber status ajax
1415
*/
1516
class StatusTest extends AbstractController
1617
{
17-
const STATUS_NOT_SUBSCRIBED = '"subscribed":false';
18-
1918
/**
2019
* Check newsletter subscription status verification
2120
*
2221
* @magentoDataFixture Magento/Newsletter/_files/subscribers.php
2322
* @dataProvider ajaxSubscriberDataProvider
23+
* @param string $expStatus
2424
* @param string $email
25-
* @param string $expected
2625
*
2726
* @return void
2827
*/
29-
public function testExecute(string $email, string $expected): void
28+
public function testExecute(string $expStatus, string $email): void
3029
{
3130
$this->getRequest()->setParam('email', $email);
3231
$this->dispatch('newsletter/ajax/status');
33-
$actual = $this->getResponse()->getBody();
32+
$actual = $this->_objectManager->get(Json::class)->unserialize($this->getResponse()->getBody());
3433

35-
$this->assertContains($expected, $actual);
34+
$this->assertEquals($expStatus, $actual['subscribed']);
3635
}
3736

3837
/**
@@ -44,26 +43,12 @@ public function testExecute(string $email, string $expected): void
4443
public function ajaxSubscriberDataProvider(): array
4544
{
4645
return [
47-
[
48-
'',
49-
self::STATUS_NOT_SUBSCRIBED,
50-
],
51-
[
52-
53-
self::STATUS_NOT_SUBSCRIBED,
54-
],
55-
[
56-
57-
self::STATUS_NOT_SUBSCRIBED,
58-
],
59-
[
60-
61-
'"subscribed":true',
62-
],
63-
[
64-
65-
self::STATUS_NOT_SUBSCRIBED,
66-
],
46+
[false, ''],
47+
[false, '[email protected]'],
48+
[false, '[email protected]'],
49+
[true, '[email protected]'],
50+
[false, '[email protected]'],
51+
[false, 'invalid_email.com'],
6752
];
6853
}
6954
}

dev/tests/js/jasmine/tests/app/code/Magento/Newsletter/frontend/js/newsletter-sign-up.test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ define([
3333
injector.mock(mocks);
3434
injector.require(['Magento_Newsletter/js/newsletter-sign-up'], function (Constr) {
3535
obj = new Constr({
36-
provider: 'provName',
37-
name: '',
38-
index: '',
3936
submitButton: '#button',
4037
signUpElement: '#is_subscribed'
4138
}, '#email_address');
@@ -67,7 +64,6 @@ define([
6764
it('Verify Subscription is checked', function () {
6865
emailElem.val('[email protected]');
6966
checkbox.prop('checked', true);
70-
expect(checkbox.is(':checked')).toBeTruthy();
7167

7268
obj.updateSignUpStatus();
7369

@@ -78,7 +74,6 @@ define([
7874

7975
it('Verify sign-up process without email', function () {
8076
checkbox.prop('checked', false);
81-
expect(checkbox.is(':checked')).toBeFalsy();
8277

8378
obj.updateSignUpStatus();
8479

@@ -89,7 +84,6 @@ define([
8984
it('Verify sign-up process with incorrect email', function () {
9085
emailElem.val('emailexample.com');
9186
checkbox.prop('checked', false);
92-
expect(checkbox.is(':checked')).toBeFalsy();
9387

9488
obj.updateSignUpStatus();
9589

@@ -100,7 +94,6 @@ define([
10094
it('Verify Subscription with correct data', function () {
10195
emailElem.val('[email protected]');
10296
checkbox.prop('checked', false);
103-
expect(checkbox.is(':checked')).toBeFalsy();
10497

10598
obj.updateSignUpStatus();
10699

@@ -113,7 +106,6 @@ define([
113106
resolveStatus(false);
114107
emailElem.val('[email protected]');
115108
checkbox.prop('checked', false);
116-
expect(checkbox.is(':checked')).toBeFalsy();
117109

118110
obj.updateSignUpStatus();
119111

0 commit comments

Comments
 (0)