Skip to content

Commit 9f643b4

Browse files
Merge branch '2.4.8-beta1-develop' into AC-11946
2 parents 7e7e711 + 06139a7 commit 9f643b4

File tree

22 files changed

+227
-503
lines changed

22 files changed

+227
-503
lines changed

app/code/Magento/Customer/Model/Plugin/UpdateCustomer.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ public function beforeSave(
5252
CustomerInterface $customer,
5353
?string $passwordHash = null
5454
): array {
55-
$customerSessionId = $this->userContext->getUserType() === $this->userContext::USER_TYPE_CUSTOMER ?
56-
(int)$this->userContext->getUserId() : 0;
55+
$userType = $this->userContext->getUserType();
56+
$customerSessionId = (int)$this->userContext->getUserId();
5757
$customerId = (int)$this->request->getParam('customerId');
5858
$bodyParams = $this->request->getBodyParams();
59-
if (!isset($bodyParams['customer']['Id']) && $customerId) {
60-
if ($customerId === $customerSessionId || $customerSessionId === 0) {
61-
$customer = $this->getUpdatedCustomer($customerRepository->getById($customerId), $customer);
62-
}
59+
60+
if ($userType === UserContextInterface::USER_TYPE_CUSTOMER &&
61+
!isset($bodyParams['customer']['Id']) &&
62+
$customerId &&
63+
$customerId === $customerSessionId
64+
) {
65+
$customer = $this->getUpdatedCustomer($customerRepository->getById($customerId), $customer);
66+
} elseif ($userType === UserContextInterface::USER_TYPE_ADMIN && $customerId) {
67+
$customer = $this->getUpdatedCustomer($customerRepository->getById($customerId), $customer);
6368
}
6469

6570
return [$customer, $passwordHash];

app/code/Magento/Customer/Plugin/Webapi/Controller/Rest/ValidateCustomerData.php

Lines changed: 0 additions & 56 deletions
This file was deleted.

app/code/Magento/Customer/Test/Unit/Plugin/Webapi/Controller/Rest/ValidateCustomerDataTest.php

Lines changed: 0 additions & 123 deletions
This file was deleted.

app/code/Magento/Customer/etc/webapi_rest/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
</argument>
3232
</arguments>
3333
</type>
34-
<type name="Magento\Webapi\Controller\Rest\ParamsOverrider">
35-
<plugin name="validateCustomerData" type="Magento\Customer\Plugin\Webapi\Controller\Rest\ValidateCustomerData" sortOrder="1" disabled="false" />
36-
</type>
3734
<preference for="Magento\Customer\Api\AccountManagementInterface"
3835
type="Magento\Customer\Model\AccountManagementApi" />
3936
</config>

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ public function assign($cartId, AddressInterface $address, $useForShipping = fal
7777
{
7878
/** @var \Magento\Quote\Model\Quote $quote */
7979
$quote = $this->quoteRepository->getActive($cartId);
80-
81-
// validate the address
82-
$this->addressValidator->validateWithExistingAddress($quote, $address);
83-
8480
$address->setCustomerId($quote->getCustomerId());
8581
$quote->removeAddress($quote->getBillingAddress()->getId());
8682
$quote->setBillingAddress($address);

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

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -121,27 +121,6 @@ public function validate(AddressInterface $addressData): bool
121121
return true;
122122
}
123123

124-
/**
125-
* Validate Quest Address for guest user
126-
*
127-
* @param AddressInterface $address
128-
* @param CartInterface $cart
129-
* @return void
130-
* @throws NoSuchEntityException
131-
*/
132-
private function doValidateForGuestQuoteAddress(AddressInterface $address, CartInterface $cart): void
133-
{
134-
//validate guest cart address
135-
if ($address->getId() !== null) {
136-
$old = $cart->getAddressById($address->getId());
137-
if ($old === false) {
138-
throw new NoSuchEntityException(
139-
__('Invalid quote address id %1', $address->getId())
140-
);
141-
}
142-
}
143-
}
144-
145124
/**
146125
* Validate address to be used for cart.
147126
*
@@ -153,9 +132,6 @@ private function doValidateForGuestQuoteAddress(AddressInterface $address, CartI
153132
*/
154133
public function validateForCart(CartInterface $cart, AddressInterface $address): void
155134
{
156-
if ($cart->getCustomerIsGuest()) {
157-
$this->doValidateForGuestQuoteAddress($address, $cart);
158-
}
159135
$this->doValidate($address, $cart->getCustomerIsGuest() ? null : (int) $cart->getCustomer()->getId());
160136
}
161137

@@ -171,8 +147,8 @@ public function validateWithExistingAddress(CartInterface $cart, AddressInterfac
171147
{
172148
// check if address belongs to quote.
173149
if ($address->getId() !== null) {
174-
$old = $cart->getAddressesCollection()->getItemById($address->getId());
175-
if ($old === null) {
150+
$old = $cart->getAddressById($address->getId());
151+
if (empty($old)) {
176152
throw new NoSuchEntityException(
177153
__('Invalid quote address id %1', $address->getId())
178154
);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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\Quote\Plugin;
9+
10+
use Magento\Framework\Exception\NoSuchEntityException;
11+
use Magento\Quote\Model\Quote;
12+
use Magento\Quote\Api\Data\AddressInterface;
13+
use Magento\Quote\Model\QuoteAddressValidator;
14+
15+
/**
16+
* Quote address plugin
17+
*/
18+
class QuoteAddress
19+
{
20+
/**
21+
* @var QuoteAddressValidator
22+
*/
23+
protected QuoteAddressValidator $addressValidator;
24+
25+
/**
26+
* @param QuoteAddressValidator $addressValidator
27+
*/
28+
public function __construct(
29+
QuoteAddressValidator $addressValidator
30+
) {
31+
$this->addressValidator = $addressValidator;
32+
}
33+
34+
/**
35+
* Validate address before setting billing address
36+
*
37+
* @param Quote $subject
38+
* @param AddressInterface|null $address
39+
* @return array
40+
* @throws NoSuchEntityException
41+
*/
42+
public function beforeSetBillingAddress(Quote $subject, AddressInterface $address = null): array
43+
{
44+
if ($address !== null) {
45+
$this->addressValidator->validateWithExistingAddress($subject, $address);
46+
}
47+
48+
return [$address];
49+
}
50+
51+
/**
52+
* Validate address before setting shipping address
53+
*
54+
* @param Quote $subject
55+
* @param AddressInterface|null $address
56+
* @return array
57+
* @throws NoSuchEntityException
58+
*/
59+
public function beforeSetShippingAddress(Quote $subject, AddressInterface $address = null): array
60+
{
61+
if ($address !== null) {
62+
$this->addressValidator->validateWithExistingAddress($subject, $address);
63+
}
64+
65+
return [$address];
66+
}
67+
}

0 commit comments

Comments
 (0)