Skip to content

Commit 108de23

Browse files
committed
Merge remote-tracking branch 'adobe-commerce-tier-4/ACP2E-3311' into Tier4-Kings-PR-10-28-2024
2 parents 7d7565c + ee3fcef commit 108de23

File tree

4 files changed

+81
-25
lines changed

4 files changed

+81
-25
lines changed

app/code/Magento/Customer/Model/Address/Validator/Customer.php

Lines changed: 3 additions & 6 deletions
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

@@ -44,10 +44,7 @@ public function validate(AbstractAddress $address): array
4444
->getCustomerId();
4545

4646
if ($originalAddressCustomerId !== 0 && $originalAddressCustomerId !== $addressCustomerId) {
47-
$errors[] = __(
48-
'Provided customer ID "%customer_id" isn\'t related to current customer address.',
49-
['customer_id' => $addressCustomerId]
50-
);
47+
$errors[] = __('A customer with the same email address already exists in an associated website.');
5148
}
5249
}
5350

app/code/Magento/Customer/Test/Unit/Model/Address/Validator/CustomerTest.php

Lines changed: 4 additions & 14 deletions
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

@@ -82,12 +82,7 @@ public function testValidateNewCustomerWithExistingCustomerAddress(): void
8282
$originalAddressMock->expects($this->once())->method('getCustomerId')->willReturn(2);
8383

8484
$this->assertEquals(
85-
[
86-
__(
87-
'Provided customer ID "%customer_id" isn\'t related to current customer address.',
88-
['customer_id' => null]
89-
)
90-
],
85+
[__('A customer with the same email address already exists in an associated website.')],
9186
$this->model->validate($addressMock)
9287
);
9388
}
@@ -160,12 +155,7 @@ public function testValidateExistingCustomerAddressWithNotRelevantCustomer(): vo
160155
$originalAddressMock->expects($this->once())->method('getCustomerId')->willReturn(1);
161156

162157
$this->assertEquals(
163-
[
164-
__(
165-
'Provided customer ID "%customer_id" isn\'t related to current customer address.',
166-
['customer_id' => 2]
167-
)
168-
],
158+
[__('A customer with the same email address already exists in an associated website.')],
169159
$this->model->validate($addressMock)
170160
);
171161
}

app/code/Magento/Quote/Model/ValidationRules/BillingAddressValidationRule.php

Lines changed: 8 additions & 5 deletions
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

@@ -46,12 +46,15 @@ public function validate(Quote $quote): array
4646
$billingAddress = $quote->getBillingAddress();
4747
$billingAddress->setStoreId($quote->getStoreId());
4848
$validationResult = $billingAddress->validate();
49-
if ($validationResult !== true) {
50-
$validationErrors = [__($this->generalMessage)];
51-
}
5249
if (is_array($validationResult)) {
5350
$validationErrors = array_merge($validationErrors, $validationResult);
5451
}
52+
if ($quote->getCustomerId() === null && $quote->getCustomerId() !== $quote->getOrigData('customer_id')) {
53+
return [$this->validationResultFactory->create(['errors' => $validationErrors])];
54+
}
55+
if ($validationResult !== true) {
56+
$validationErrors = array_merge([__($this->generalMessage)], $validationErrors);
57+
}
5558

5659
return [$this->validationResultFactory->create(['errors' => $validationErrors])];
5760
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Quote\Test\Unit\Model\ValidationRules;
9+
10+
use Magento\Quote\Model\Quote\Address;
11+
use PHPUnit\Framework\MockObject\MockObject;
12+
use Magento\Framework\Validation\ValidationResultFactory;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Quote\Model\ValidationRules\BillingAddressValidationRule;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class BillingAddressValidationRuleTest extends TestCase
18+
{
19+
/**
20+
* @var BillingAddressValidationRule
21+
*/
22+
private $model;
23+
24+
/**
25+
* @var ValidationResultFactory|MockObject
26+
*/
27+
private $validationResultFactoryMock;
28+
29+
protected function setUp(): void
30+
{
31+
$this->validationResultFactoryMock = $this->getMockBuilder(ValidationResultFactory::class)
32+
->disableOriginalConstructor()
33+
->onlyMethods(['create'])
34+
->getMock();
35+
$this->model = new BillingAddressValidationRule($this->validationResultFactoryMock);
36+
}
37+
38+
public function testValidate()
39+
{
40+
$storeId = 1;
41+
$error = new \Magento\Framework\Phrase(
42+
'A customer with the same email address already exists in an associated website.'
43+
);
44+
$validationResult = [$error];
45+
$validationResultObj = new \Magento\Framework\Validation\ValidationResult($validationResult);
46+
$this->validationResultFactoryMock->expects($this->once())->method('create')->with(
47+
['errors' => $validationResult]
48+
)->willReturn($validationResultObj);
49+
$addressMock = $this->getMockBuilder(Address::class)->disableOriginalConstructor()->getMock();
50+
$addressMock->expects($this->once())->method('validate')->willReturn($validationResult);
51+
$quoteMock = $this->getMockBuilder(Quote::class)
52+
->disableOriginalConstructor()
53+
->getMock();
54+
$quoteMock->expects($this->once())->method('getBillingAddress')->willReturn($addressMock);
55+
$quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
56+
$quoteMock->expects($this->any())->method('__call')->with('getCustomerId')
57+
->willReturn(null);
58+
$quoteMock->expects($this->once())->method('getOrigData')->willReturn(['customer_id' => 2]);
59+
$result = $this->model->validate($quoteMock);
60+
$this->assertIsArray($result);
61+
$this->assertEquals(
62+
'A customer with the same email address already exists in an associated website.',
63+
$result[0]->getErrors()[0]->getText()
64+
);
65+
}
66+
}

0 commit comments

Comments
 (0)