|
1 | 1 | <?php
|
2 | 2 | /**
|
3 |
| - * Copyright © Magento, Inc. All rights reserved. |
4 |
| - * See COPYING.txt for license details. |
| 3 | + * Copyright 2014 Adobe |
| 4 | + * All Rights Reserved. |
5 | 5 | */
|
6 | 6 | declare(strict_types=1);
|
7 | 7 |
|
8 | 8 | namespace Magento\Quote\Model;
|
9 | 9 |
|
10 | 10 | use Magento\Customer\Api\AddressRepositoryInterface;
|
11 | 11 | use Magento\Customer\Api\CustomerRepositoryInterface;
|
| 12 | +use Magento\Customer\Api\Data\AddressInterface as CustomerAddress; |
12 | 13 | use Magento\Customer\Model\Session;
|
13 | 14 | use Magento\Framework\Exception\InputException;
|
14 | 15 | use Magento\Framework\Exception\LocalizedException;
|
@@ -68,39 +69,28 @@ public function __construct(
|
68 | 69 | */
|
69 | 70 | private function doValidate(AddressInterface $address, ?int $customerId): void
|
70 | 71 | {
|
71 |
| - //validate customer id |
72 |
| - if ($customerId) { |
73 |
| - $customer = $this->customerRepository->getById($customerId); |
74 |
| - if (!$customer->getId()) { |
75 |
| - throw new NoSuchEntityException( |
76 |
| - __('Invalid customer id %1', $customerId) |
77 |
| - ); |
78 |
| - } |
79 |
| - } |
80 |
| - |
81 |
| - if ($address->getCustomerAddressId()) { |
| 72 | + $customerAddressId = $address->getCustomerAddressId(); |
| 73 | + if ($customerAddressId) { |
82 | 74 | //Existing address cannot belong to a guest
|
83 | 75 | if (!$customerId) {
|
84 | 76 | throw new NoSuchEntityException(
|
85 |
| - __('Invalid customer address id %1', $address->getCustomerAddressId()) |
| 77 | + __('Invalid customer address id %1', $customerAddressId) |
86 | 78 | );
|
87 | 79 | }
|
| 80 | + |
| 81 | + $customer = $this->customerRepository->getById($customerId); |
| 82 | + |
88 | 83 | //Validating address ID
|
89 |
| - try { |
90 |
| - $this->addressRepository->getById($address->getCustomerAddressId()); |
91 |
| - } catch (NoSuchEntityException $e) { |
92 |
| - throw new NoSuchEntityException( |
93 |
| - __('Invalid address id %1', $address->getId()) |
94 |
| - ); |
95 |
| - } |
| 84 | + $this->addressRepository->getById($customerAddressId); |
| 85 | + |
96 | 86 | //Finding available customer's addresses
|
97 |
| - $applicableAddressIds = array_map(function ($address) { |
98 |
| - /** @var \Magento\Customer\Api\Data\AddressInterface $address */ |
| 87 | + $applicableAddressIds = array_map(function (CustomerAddress $address) { |
99 | 88 | return $address->getId();
|
100 |
| - }, $this->customerRepository->getById($customerId)->getAddresses()); |
101 |
| - if (!in_array($address->getCustomerAddressId(), $applicableAddressIds)) { |
| 89 | + }, $customer->getAddresses()); |
| 90 | + |
| 91 | + if (!in_array($customerAddressId, $applicableAddressIds)) { |
102 | 92 | throw new NoSuchEntityException(
|
103 |
| - __('Invalid customer address id %1', $address->getCustomerAddressId()) |
| 93 | + __('Invalid customer address id %1', $customerAddressId) |
104 | 94 | );
|
105 | 95 | }
|
106 | 96 | }
|
|
0 commit comments