Skip to content

Commit e565531

Browse files
committed
ACP2E-3296: Checkout order email confirmation is sent to emails entered in First/Last name
1 parent 5a2037c commit e565531

File tree

5 files changed

+78
-27
lines changed

5 files changed

+78
-27
lines changed

app/code/Magento/Quote/Model/CustomerManagement.php

+33-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -10,6 +10,7 @@
1010
use Magento\Customer\Api\AccountManagementInterface as AccountManagement;
1111
use Magento\Customer\Api\AddressRepositoryInterface as CustomerAddressRepository;
1212
use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
13+
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1314
use Magento\Customer\Model\AddressFactory;
1415
use Magento\Framework\App\ObjectManager;
1516
use Magento\Framework\Validator\Exception as ValidatorException;
@@ -46,24 +47,32 @@ class CustomerManagement
4647
*/
4748
private $addressFactory;
4849

50+
/**
51+
* @var AddressInterfaceFactory
52+
*/
53+
private $customerAddressFactory;
54+
4955
/**
5056
* CustomerManagement constructor.
5157
* @param CustomerRepository $customerRepository
5258
* @param CustomerAddressRepository $customerAddressRepository
5359
* @param AccountManagement $accountManagement
60+
* @param AddressInterfaceFactory $customerAddressFactory
5461
* @param ValidatorFactory|null $validatorFactory
5562
* @param AddressFactory|null $addressFactory
5663
*/
5764
public function __construct(
5865
CustomerRepository $customerRepository,
5966
CustomerAddressRepository $customerAddressRepository,
6067
AccountManagement $accountManagement,
68+
AddressInterfaceFactory $customerAddressFactory,
6169
ValidatorFactory $validatorFactory = null,
6270
AddressFactory $addressFactory = null
6371
) {
6472
$this->customerRepository = $customerRepository;
6573
$this->customerAddressRepository = $customerAddressRepository;
6674
$this->accountManagement = $accountManagement;
75+
$this->customerAddressFactory = $customerAddressFactory;
6776
$this->validatorFactory = $validatorFactory ?: ObjectManager::getInstance()
6877
->get(ValidatorFactory::class);
6978
$this->addressFactory = $addressFactory ?: ObjectManager::getInstance()
@@ -144,24 +153,34 @@ public function validateAddresses(QuoteEntity $quote)
144153
$addresses[] = $this->customerAddressRepository->getById(
145154
$quote->getBillingAddress()->getCustomerAddressId()
146155
);
156+
} else {
157+
$billingAddress = $quote->getBillingAddress();
158+
$customerAddress = $this->customerAddressFactory->create();
159+
$customerAddress->setFirstname($billingAddress->getFirstname());
160+
$customerAddress->setLastname($billingAddress->getLastname());
161+
$customerAddress->setStreet($billingAddress->getStreet());
162+
$customerAddress->setCity($billingAddress->getCity());
163+
$customerAddress->setPostcode($billingAddress->getPostcode());
164+
$customerAddress->setTelephone($billingAddress->getTelephone());
165+
$customerAddress->setCountryId($billingAddress->getCountryId());
166+
$addresses[] = $customerAddress;
147167
}
148168
if ($quote->getShippingAddress()->getCustomerAddressId()) {
149169
$addresses[] = $this->customerAddressRepository->getById(
150170
$quote->getShippingAddress()->getCustomerAddressId()
151171
);
152172
}
153-
if (!empty($addresses)) {
154-
foreach ($addresses as $address) {
155-
$validator = $this->validatorFactory->createValidator('customer_address', 'save');
156-
$addressModel = $this->addressFactory->create();
157-
$addressModel->updateData($address);
158-
if (!$validator->isValid($addressModel)) {
159-
throw new ValidatorException(
160-
null,
161-
null,
162-
$validator->getMessages()
163-
);
164-
}
173+
174+
foreach ($addresses as $address) {
175+
$validator = $this->validatorFactory->createValidator('customer_address', 'save');
176+
$addressModel = $this->addressFactory->create();
177+
$addressModel->updateData($address);
178+
if (!$validator->isValid($addressModel)) {
179+
throw new ValidatorException(
180+
null,
181+
null,
182+
$validator->getMessages()
183+
);
165184
}
166185
}
167186
}

app/code/Magento/Quote/Model/QuoteManagement.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -565,10 +565,10 @@ protected function submitQuote(QuoteEntity $quote, $orderData = [])
565565
if (!$quote->getCustomerIsGuest()) {
566566
if ($quote->getCustomerId()) {
567567
$this->_prepareCustomerQuote($quote);
568-
$this->customerManagement->validateAddresses($quote);
569568
}
570569
$this->customerManagement->populateCustomerInfo($quote);
571570
}
571+
$this->customerManagement->validateAddresses($quote);
572572
$addresses = [];
573573
$quote->reserveOrderId();
574574
if ($quote->isVirtual()) {

app/code/Magento/Quote/Test/Unit/Model/CustomerManagementTest.php

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -11,9 +11,11 @@
1111
use Magento\Customer\Api\AddressRepositoryInterface;
1212
use Magento\Customer\Api\CustomerRepositoryInterface;
1313
use Magento\Customer\Api\Data\AddressInterface;
14+
use Magento\Customer\Api\Data\AddressInterfaceFactory;
1415
use Magento\Customer\Api\Data\CustomerInterface;
1516
use Magento\Customer\Model\AddressFactory;
1617
use Magento\Framework\Validator;
18+
use Magento\Framework\Validator\Exception as ValidatorException;
1719
use Magento\Framework\Validator\Factory;
1820
use Magento\Quote\Model\CustomerManagement;
1921
use Magento\Quote\Model\Quote;
@@ -76,6 +78,11 @@ class CustomerManagementTest extends TestCase
7678
*/
7779
private $addressFactoryMock;
7880

81+
/**
82+
* @var MockObject
83+
*/
84+
private $customerAddressFactoryMock;
85+
7986
protected function setUp(): void
8087
{
8188
$this->customerRepositoryMock = $this->getMockForAbstractClass(
@@ -136,10 +143,20 @@ protected function setUp(): void
136143
$this->validatorFactoryMock = $this->getMockBuilder(Factory::class)
137144
->disableOriginalConstructor()
138145
->getMock();
146+
$this->customerAddressFactoryMock = $this->getMockForAbstractClass(
147+
AddressInterfaceFactory::class,
148+
[],
149+
'',
150+
false,
151+
true,
152+
true,
153+
['create']
154+
);
139155
$this->customerManagement = new CustomerManagement(
140156
$this->customerRepositoryMock,
141157
$this->customerAddressRepositoryMock,
142158
$this->accountManagementMock,
159+
$this->customerAddressFactoryMock,
143160
$this->validatorFactoryMock,
144161
$this->addressFactoryMock
145162
);
@@ -249,19 +266,33 @@ public function testValidateAddresses()
249266

250267
public function testValidateAddressesNotSavedInAddressBook()
251268
{
269+
$this->expectException(ValidatorException::class);
270+
$this->quoteAddressMock->method('getStreet')->willReturn(['test']);
271+
$this->customerAddressFactoryMock->method('create')
272+
->willReturn($this->customerAddressMock);
273+
$addressMock = $this->getMockBuilder(Address::class)
274+
->disableOriginalConstructor()
275+
->getMock();
276+
$this->addressFactoryMock->expects($this->exactly(1))->method('create')->willReturn($addressMock);
252277
$this->quoteMock
253-
->expects($this->once())
278+
->expects($this->atMost(2))
254279
->method('getBillingAddress')
255280
->willReturn($this->quoteAddressMock);
256281
$this->quoteMock
257282
->expects($this->once())
258283
->method('getShippingAddress')
259284
->willReturn($this->quoteAddressMock);
260285
$this->quoteAddressMock->expects($this->any())->method('getCustomerAddressId')->willReturn(null);
286+
$validatorMock = $this->getMockBuilder(Validator::class)
287+
->disableOriginalConstructor()
288+
->getMock();
261289
$this->validatorFactoryMock
262-
->expects($this->never())
290+
->expects($this->exactly(1))
263291
->method('createValidator')
264-
->with('customer_address', 'save', null);
292+
->with('customer_address', 'save', null)
293+
->willReturn($validatorMock);
294+
$validatorMock->expects($this->exactly(1))->method('isValid')->with($addressMock)->willReturn(false);
295+
$validatorMock->expects($this->exactly(1))->method('getMessages')->willReturn([]);
265296
$this->customerManagement->validateAddresses($this->quoteMock);
266297
}
267298
}

dev/tests/integration/framework/Magento/TestFramework/ApplicationStateComparator/_files/state-filter-list.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -41,6 +41,7 @@
4141
Magento\Framework\Logger\Handler\Base::class => [ // TODO: remove this after ACPT-1034 is fixed
4242
'stream' => null,
4343
],
44+
Magento\Framework\Validator\AbstractValidator::class => ['_defaultTranslator' => null],
4445
],
4546
'services' => [ // Note: These apply only to the service names that match.
4647
Magento\Framework\ObjectManager\ConfigInterface::class => ['_mergedArguments' => null],

dev/tests/integration/framework/Magento/TestFramework/ApplicationStateComparator/_files/state-skip-list.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -81,7 +81,7 @@
8181
// Magento\Customer\Model\ResourceModel\AddressRepository::class => null,
8282
// Magento\Customer\Model\CustomerRegistry::class => null,
8383
// Magento\Customer\Model\ResourceModel\Address\Relation::class => null,
84-
// Magento\Customer\Model\ResourceModel\Address::class => null,
84+
Magento\Customer\Model\ResourceModel\Address::class => null,
8585
// Magento\Customer\Model\AttributeMetadataConverter::class => null,
8686
Magento\Customer\Model\Metadata\CustomerMetadata::class => null, // TODO?
8787
// Magento\Customer\Model\Metadata\AttributeMetadataCache::class => null,

0 commit comments

Comments
 (0)