Skip to content

Commit 48423d7

Browse files
authored
Merge pull request #5381 from magento-tsg/2.4-develop-pr13
[TSG] Fixes for 2.4 (pr13) (2.4-develop)
2 parents 9003079 + 2803428 commit 48423d7

File tree

30 files changed

+887
-126
lines changed

30 files changed

+887
-126
lines changed

app/code/Magento/Checkout/Test/Mftf/ActionGroup/AssertStorefrontCheckoutCartItemsActionGroup.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
<argument name="subtotal" type="string"/>
2020
<argument name="qty" type="string"/>
2121
</arguments>
22-
22+
2323
<see selector="{{CheckoutCartProductSection.productName}}" userInput="{{productName}}" stepKey="seeProductNameInCheckoutSummary"/>
24-
<see selector="{{CheckoutCartProductSection.checkoutCartProductPrice}}" userInput="{{productPrice}}" stepKey="seeProductPriceInCart"/>
25-
<see selector="{{CheckoutCartProductSection.checkoutCartSubtotal}}" userInput="{{subtotal}}" stepKey="seeSubtotalPrice"/>
26-
<seeInField selector="{{CheckoutCartProductSection.qtyByContains(productSku)}}" userInput="{{qty}}" stepKey="seeProductQuantity"/>
24+
<see selector="{{CheckoutCartProductSection.ProductPriceByName(productName)}}" userInput="{{productPrice}}" stepKey="seeProductPriceInCart"/>
25+
<see selector="{{CheckoutCartProductSection.productSubtotalByName(productName)}}" userInput="{{subtotal}}" stepKey="seeSubtotalPrice"/>
26+
<seeInField selector="{{CheckoutCartProductSection.ProductQuantityByName(productName)}}" userInput="{{qty}}" stepKey="seeProductQuantity"/>
2727
</actionGroup>
2828
</actionGroups>

app/code/Magento/ImportExport/Test/Mftf/Test/AdminCheckDoubleImportOfProductsTest.xml

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Newsletter\Controller\Ajax;
9+
10+
use Magento\Framework\App\Action\Action;
11+
use Magento\Framework\App\Action\Context;
12+
use Magento\Framework\App\Action\HttpGetActionInterface;
13+
use Magento\Framework\Controller\Result\Json;
14+
use Magento\Framework\Controller\ResultFactory;
15+
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Validator\EmailAddress as EmailAddressValidator;
17+
use Magento\Newsletter\Model\GuestSubscriptionChecker;
18+
use Psr\Log\LoggerInterface;
19+
20+
/**
21+
* Newsletter subscription status verification controller.
22+
*/
23+
class Status extends Action implements HttpGetActionInterface
24+
{
25+
/**
26+
* @var EmailAddressValidator
27+
*/
28+
private $emailAddressValidator;
29+
30+
/**
31+
* @var GuestSubscriptionChecker
32+
*/
33+
private $guestSubscriptionChecker;
34+
35+
/**
36+
* @var LoggerInterface
37+
*/
38+
private $logger;
39+
40+
/**
41+
* @param Context $context
42+
* @param EmailAddressValidator $emailAddressValidator
43+
* @param GuestSubscriptionChecker $guestSubscriptionChecker
44+
* @param LoggerInterface $logger
45+
*/
46+
public function __construct(
47+
Context $context,
48+
EmailAddressValidator $emailAddressValidator,
49+
GuestSubscriptionChecker $guestSubscriptionChecker,
50+
LoggerInterface $logger
51+
) {
52+
parent::__construct($context);
53+
$this->emailAddressValidator = $emailAddressValidator;
54+
$this->guestSubscriptionChecker = $guestSubscriptionChecker;
55+
$this->logger = $logger;
56+
}
57+
58+
/**
59+
* @inheritdoc
60+
*/
61+
public function execute()
62+
{
63+
$email = (string)$this->getRequest()->getParam('email');
64+
65+
$response = [
66+
'subscribed' => false,
67+
'errors' => false,
68+
];
69+
try {
70+
if (!empty($email) && $this->emailAddressValidator->isValid($email)) {
71+
$response['subscribed'] = $this->guestSubscriptionChecker->isSubscribed($email);
72+
}
73+
} catch (LocalizedException | \DomainException $exception) {
74+
$this->logger->error($exception->getMessage());
75+
$response['errors'] = true;
76+
}
77+
78+
/** @var Json $resultJson */
79+
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
80+
81+
return $resultJson->setData($response);
82+
}
83+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Newsletter\Model;
9+
10+
use Magento\Framework\App\ResourceConnection;
11+
use Magento\Store\Model\StoreManagerInterface;
12+
13+
/**
14+
* Checks guest subscription by email.
15+
*/
16+
class GuestSubscriptionChecker
17+
{
18+
/**
19+
* @var ResourceConnection
20+
*/
21+
private $resourceConnection;
22+
23+
/**
24+
* @var StoreManagerInterface
25+
*/
26+
private $storeManager;
27+
28+
/**
29+
* @param ResourceConnection $resourceConnection
30+
* @param StoreManagerInterface $storeManager
31+
*/
32+
public function __construct(ResourceConnection $resourceConnection, StoreManagerInterface $storeManager)
33+
{
34+
$this->resourceConnection = $resourceConnection;
35+
$this->storeManager = $storeManager;
36+
}
37+
38+
/**
39+
* Check is subscribed by email
40+
*
41+
* @param string $subscriberEmail
42+
* @return bool
43+
*/
44+
public function isSubscribed(string $subscriberEmail): bool
45+
{
46+
if (!empty($subscriberEmail)) {
47+
$storeIds = $this->storeManager->getWebsite()->getStoreIds();
48+
$connection = $this->resourceConnection->getConnection();
49+
$select = $connection
50+
->select()
51+
->from($this->resourceConnection->getTableName('newsletter_subscriber'))
52+
->where('subscriber_email = ?', $subscriberEmail)
53+
->where('store_id IN (?)', $storeIds)
54+
->where('customer_id = 0')
55+
->limit(1);
56+
57+
return (bool)$connection->fetchOne($select);
58+
}
59+
60+
return false;
61+
}
62+
}

app/code/Magento/Newsletter/Model/Plugin/CustomerPlugin.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,16 +109,20 @@ public function afterSave(
109109
CustomerInterface $result,
110110
CustomerInterface $customer
111111
) {
112+
/** @var Subscriber $subscriber */
112113
$subscriber = $this->getSubscriber($result);
113-
$subscribeStatus = $this->getIsSubscribedFromExtensionAttr($customer) ?? $subscriber->isSubscribed();
114+
$subscribeStatus = $this->getIsSubscribedFromExtensionAttributes($customer) ?? $subscriber->isSubscribed();
114115
$needToUpdate = $this->isSubscriptionChanged($result, $subscriber, $subscribeStatus);
115116

116117
/**
117118
* If subscriber is waiting to confirm customer registration
118119
* and customer is already confirmed registration
119120
* than need to subscribe customer
120121
*/
121-
if ((int)$subscriber->getStatus() === Subscriber::STATUS_UNCONFIRMED && empty($result->getConfirmation())) {
122+
if ($subscriber->getId()
123+
&& (int)$subscriber->getStatus() === Subscriber::STATUS_UNCONFIRMED
124+
&& empty($result->getConfirmation())
125+
) {
122126
$needToUpdate = true;
123127
$subscribeStatus = true;
124128
}
@@ -129,7 +133,7 @@ public function afterSave(
129133
: $this->subscriptionManager->unsubscribeCustomer((int)$result->getId(), $storeId);
130134
$this->customerSubscriber[(int)$result->getId()] = $subscriber;
131135
}
132-
$this->addIsSubscribedExtensionAttr($result, $subscriber->isSubscribed());
136+
$this->addIsSubscribedExtensionAttribute($result, $subscriber->isSubscribed());
133137

134138
return $result;
135139
}
@@ -140,14 +144,14 @@ public function afterSave(
140144
* @param CustomerInterface $customer
141145
* @return bool|null
142146
*/
143-
private function getIsSubscribedFromExtensionAttr(CustomerInterface $customer): ?bool
147+
private function getIsSubscribedFromExtensionAttributes(CustomerInterface $customer): ?bool
144148
{
145-
$newExtensionAttributes = $customer->getExtensionAttributes();
146-
if ($newExtensionAttributes === null || $newExtensionAttributes->getIsSubscribed() === null) {
149+
$extensionAttributes = $customer->getExtensionAttributes();
150+
if ($extensionAttributes === null || $extensionAttributes->getIsSubscribed() === null) {
147151
return null;
148152
}
149153

150-
return (bool)$newExtensionAttributes->getIsSubscribed();
154+
return (bool)$extensionAttributes->getIsSubscribed();
151155
}
152156

153157
/**
@@ -223,7 +227,7 @@ public function afterGetById(CustomerRepositoryInterface $subject, CustomerInter
223227
$extensionAttributes = $customer->getExtensionAttributes();
224228
if ($extensionAttributes === null || $extensionAttributes->getIsSubscribed() === null) {
225229
$isSubscribed = $this->getSubscriber($customer)->isSubscribed();
226-
$this->addIsSubscribedExtensionAttr($customer, $isSubscribed);
230+
$this->addIsSubscribedExtensionAttribute($customer, $isSubscribed);
227231
}
228232

229233
return $customer;
@@ -235,7 +239,7 @@ public function afterGetById(CustomerRepositoryInterface $subject, CustomerInter
235239
* @param CustomerInterface $customer
236240
* @param bool $isSubscribed
237241
*/
238-
private function addIsSubscribedExtensionAttr(CustomerInterface $customer, bool $isSubscribed): void
242+
private function addIsSubscribedExtensionAttribute(CustomerInterface $customer, bool $isSubscribed): void
239243
{
240244
$extensionAttributes = $customer->getExtensionAttributes();
241245
if ($extensionAttributes === null) {

app/code/Magento/Newsletter/Test/Unit/Model/Plugin/CustomerPluginTest.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,14 @@ public function testAfterSave(?int $originalStatus, ?bool $newValue, ?bool $expe
124124
->method('loadByCustomer')
125125
->with($customerId, $websiteId)
126126
->willReturnSelf();
127-
$subscriber->expects($this->once())
128-
->method('loadBySubscriberEmail')
129-
->with($customerEmail, $websiteId)
130-
->willReturnSelf();
127+
if ($originalStatus !== null && $originalStatus === Subscriber::STATUS_UNCONFIRMED) {
128+
$subscriber->method('getId')->willReturn(1);
129+
} else {
130+
$subscriber->expects($this->once())
131+
->method('loadBySubscriberEmail')
132+
->with($customerEmail, $websiteId)
133+
->willReturnSelf();
134+
}
131135
$this->subscriberFactory->method('create')->willReturn($subscriber);
132136

133137
$customerExtension = $this->createPartialMock(CustomerExtensionInterface::class, ['getIsSubscribed']);
@@ -162,23 +166,25 @@ public function testAfterSave(?int $originalStatus, ?bool $newValue, ?bool $expe
162166
}
163167

164168
/**
169+
* Data provider for testAfterSave()
170+
*
165171
* @return array
166172
*/
167-
public function afterSaveDataProvider()
173+
public function afterSaveDataProvider(): array
168174
{
169175
return [
170-
[null, null, null],
171-
[null, true, true],
172-
[null, false, null],
173-
[Subscriber::STATUS_SUBSCRIBED, null, null],
174-
[Subscriber::STATUS_SUBSCRIBED, true, null],
175-
[Subscriber::STATUS_SUBSCRIBED, false, false],
176-
[Subscriber::STATUS_UNSUBSCRIBED, null, null],
177-
[Subscriber::STATUS_UNSUBSCRIBED, true, true],
178-
[Subscriber::STATUS_UNSUBSCRIBED, false, null],
179-
[Subscriber::STATUS_UNCONFIRMED, null, true],
180-
[Subscriber::STATUS_UNCONFIRMED, true, true],
181-
[Subscriber::STATUS_UNCONFIRMED, false, true],
176+
'missing_previous_and_new_status' => [null, null, null],
177+
'missing_previous_status_and_subscribe' => [null, true, true],
178+
'new_unsubscribed_value_and_missing_previous_status' => [null, false, null],
179+
'previous_subscribed_status_without_new_value' => [Subscriber::STATUS_SUBSCRIBED, null, null],
180+
'same_subscribed_previous_and_new_status' => [Subscriber::STATUS_SUBSCRIBED, true, null],
181+
'unsubscribe_previously_subscribed_customer' => [Subscriber::STATUS_SUBSCRIBED, false, false],
182+
'previously_unsubscribed_status_without_new_value' => [Subscriber::STATUS_UNSUBSCRIBED, null, null],
183+
'subscribe_previously_unsubscribed_customer' => [Subscriber::STATUS_UNSUBSCRIBED, true, true],
184+
'same_unsubscribed_previous_and_new_status' => [Subscriber::STATUS_UNSUBSCRIBED, false, null],
185+
'previous_unconfirmed_status_without_new_value' => [Subscriber::STATUS_UNCONFIRMED, null, true],
186+
'subscribe_previously_unconfirmed_status' => [Subscriber::STATUS_UNCONFIRMED, true, true],
187+
'unsubscribe_previously_unconfirmed_status' => [Subscriber::STATUS_UNCONFIRMED, false, true],
182188
];
183189
}
184190

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceBlock name="customer_form_register">
11+
<block name="customer.form.register.newsletter" template="Magento_Newsletter::form/register/newsletter.phtml"/>
12+
</referenceBlock>
13+
</body>
14+
</page>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
var config = {
7+
map: {
8+
'*': {
9+
subscriptionStatusResolver: 'Magento_Newsletter/js/subscription-status-resolver',
10+
newsletterSignUp: 'Magento_Newsletter/js/newsletter-sign-up'
11+
}
12+
}
13+
};

0 commit comments

Comments
 (0)