Skip to content

Commit 6b1d49c

Browse files
cia-2.4.7-beta1-develop=bugfixes-01132023
resolve conflict
2 parents f6ac4d2 + 2b12a90 commit 6b1d49c

File tree

2 files changed

+74
-40
lines changed

2 files changed

+74
-40
lines changed

app/code/Magento/Checkout/Model/ShippingInformationManagement.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Checkout\Model;
89

@@ -39,60 +40,62 @@ class ShippingInformationManagement implements ShippingInformationManagementInte
3940
/**
4041
* @var PaymentMethodManagementInterface
4142
*/
42-
protected $paymentMethodManagement;
43+
protected PaymentMethodManagementInterface $paymentMethodManagement;
4344

4445
/**
4546
* @var PaymentDetailsFactory
4647
*/
47-
protected $paymentDetailsFactory;
48+
protected PaymentDetailsFactory $paymentDetailsFactory;
4849

4950
/**
5051
* @var CartTotalRepositoryInterface
5152
*/
52-
protected $cartTotalsRepository;
53+
protected CartTotalRepositoryInterface $cartTotalsRepository;
5354

5455
/**
5556
* @var CartRepositoryInterface
5657
*/
57-
protected $quoteRepository;
58-
58+
protected CartRepositoryInterface $quoteRepository;
5959
/**
6060
* @var Logger
6161
*/
62-
protected $logger;
62+
protected Logger $logger;
6363

6464
/**
6565
* @var QuoteAddressValidator
6666
*/
67-
protected $addressValidator;
67+
protected QuoteAddressValidator $addressValidator;
6868

6969
/**
7070
* @var AddressRepositoryInterface
7171
* @deprecated 100.2.0
72+
* @see AddressRepositoryInterface
7273
*/
73-
protected $addressRepository;
74+
protected AddressRepositoryInterface $addressRepository;
7475

7576
/**
7677
* @var ScopeConfigInterface
7778
* @deprecated 100.2.0
79+
* @see ScopeConfigInterface
7880
*/
79-
protected $scopeConfig;
81+
protected ScopeConfigInterface $scopeConfig;
8082

8183
/**
8284
* @var TotalsCollector
8385
* @deprecated 100.2.0
86+
* @see TotalsCollector
8487
*/
85-
protected $totalsCollector;
88+
protected TotalsCollector $totalsCollector;
8689

8790
/**
8891
* @var CartExtensionFactory
8992
*/
90-
private $cartExtensionFactory;
93+
private CartExtensionFactory $cartExtensionFactory;
9194

9295
/**
9396
* @var ShippingAssignmentFactory
9497
*/
95-
protected $shippingAssignmentFactory;
98+
protected ShippingAssignmentFactory $shippingAssignmentFactory;
9699

97100
/**
98101
* @var ShippingFactory
@@ -262,8 +265,11 @@ protected function validateQuote(Quote $quote): void
262265
* @param string $method
263266
* @return CartInterface
264267
*/
265-
private function prepareShippingAssignment(CartInterface $quote, AddressInterface $address, $method): CartInterface
266-
{
268+
private function prepareShippingAssignment(
269+
CartInterface $quote,
270+
AddressInterface $address,
271+
string $method
272+
): CartInterface {
267273
$cartExtension = $quote->getExtensionAttributes();
268274
if ($cartExtension === null) {
269275
$cartExtension = $this->cartExtensionFactory->create();

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

Lines changed: 54 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Quote\Model;
79

10+
use Magento\Customer\Api\AddressRepositoryInterface;
11+
use Magento\Customer\Api\CustomerRepositoryInterface;
12+
use Magento\Customer\Model\Session;
13+
use Magento\Framework\Exception\InputException;
14+
use Magento\Framework\Exception\LocalizedException;
815
use Magento\Framework\Exception\NoSuchEntityException;
916
use Magento\Quote\Api\Data\AddressInterface;
1017
use Magento\Quote\Api\Data\CartInterface;
@@ -17,37 +24,33 @@
1724
class QuoteAddressValidator
1825
{
1926
/**
20-
* Address factory.
21-
*
22-
* @var \Magento\Customer\Api\AddressRepositoryInterface
27+
* @var AddressRepositoryInterface
2328
*/
24-
protected $addressRepository;
29+
protected AddressRepositoryInterface $addressRepository;
2530

2631
/**
27-
* Customer repository object.
28-
*
29-
* @var \Magento\Customer\Api\CustomerRepositoryInterface
32+
* @var CustomerRepositoryInterface
3033
*/
31-
protected $customerRepository;
34+
protected CustomerRepositoryInterface $customerRepository;
3235

3336
/**
37+
* @var Session
3438
* @deprecated 101.1.1 This class is not a part of HTML presentation layer and should not use sessions.
35-
*
36-
* @var \Magento\Customer\Model\Session
39+
* @see Session
3740
*/
38-
protected $customerSession;
41+
protected Session $customerSession;
3942

4043
/**
4144
* Constructs a quote shipping address validator service object.
4245
*
43-
* @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
44-
* @param \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository Customer repository.
45-
* @param \Magento\Customer\Model\Session $customerSession
46+
* @param AddressRepositoryInterface $addressRepository
47+
* @param CustomerRepositoryInterface $customerRepository Customer repository.
48+
* @param Session $customerSession
4649
*/
4750
public function __construct(
48-
\Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
49-
\Magento\Customer\Api\CustomerRepositoryInterface $customerRepository,
50-
\Magento\Customer\Model\Session $customerSession
51+
AddressRepositoryInterface $addressRepository,
52+
CustomerRepositoryInterface $customerRepository,
53+
Session $customerSession
5154
) {
5255
$this->addressRepository = $addressRepository;
5356
$this->customerRepository = $customerRepository;
@@ -58,9 +61,9 @@ public function __construct(
5861
* Validate address.
5962
*
6063
* @param AddressInterface $address
61-
* @param int|null $customerId Cart belongs to
64+
* @param int|null $customerId
6265
* @return void
63-
* @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer.
66+
* @throws LocalizedException The specified customer ID or address ID is not valid.
6467
* @throws NoSuchEntityException The specified customer ID or address ID is not valid.
6568
*/
6669
private function doValidate(AddressInterface $address, ?int $customerId): void
@@ -106,30 +109,55 @@ private function doValidate(AddressInterface $address, ?int $customerId): void
106109
/**
107110
* Validates the fields in a specified address data object.
108111
*
109-
* @param \Magento\Quote\Api\Data\AddressInterface $addressData The address data object.
112+
* @param AddressInterface $addressData The address data object.
110113
* @return bool
111-
* @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer.
112-
* @throws NoSuchEntityException The specified customer ID or address ID is not valid.
114+
* @throws InputException The specified address belongs to another customer.
115+
* @throws NoSuchEntityException|LocalizedException The specified customer ID or address ID is not valid.
113116
*/
114-
public function validate(AddressInterface $addressData)
117+
public function validate(AddressInterface $addressData): bool
115118
{
116119
$this->doValidate($addressData, $addressData->getCustomerId());
117120

118121
return true;
119122
}
120123

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+
$size = $cart->getAddressesCollection()->getSize();
137+
$old = $cart->getAddressesCollection()->getItemById($address->getId());
138+
if ($old === null && $size > 0) {
139+
throw new NoSuchEntityException(
140+
__('Invalid quote address id %1', $address->getId())
141+
);
142+
}
143+
}
144+
}
145+
121146
/**
122147
* Validate address to be used for cart.
123148
*
124149
* @param CartInterface $cart
125150
* @param AddressInterface $address
126151
* @return void
127-
* @throws \Magento\Framework\Exception\InputException The specified address belongs to another customer.
128-
* @throws NoSuchEntityException The specified customer ID or address ID is not valid.
152+
* @throws InputException The specified address belongs to another customer.
153+
* @throws NoSuchEntityException|LocalizedException The specified customer ID or address ID is not valid.
129154
*/
130155
public function validateForCart(CartInterface $cart, AddressInterface $address): void
131156
{
132-
$this->doValidate($address, $cart->getCustomerIsGuest() ? null : $cart->getCustomer()->getId());
157+
if ($cart->getCustomerIsGuest()) {
158+
$this->doValidateForGuestQuoteAddress($address, $cart);
159+
}
160+
$this->doValidate($address, $cart->getCustomerIsGuest() ? null : (int) $cart->getCustomer()->getId());
133161
}
134162

135163
/**

0 commit comments

Comments
 (0)