diff --git a/vendor/magento/module-customer/Model/Address/CustomerAddressDataProvider.php b/vendor/magento/module-customer/Model/Address/CustomerAddressDataProvider.php index 4334607c6b17..b9197a329a32 100644 --- a/vendor/magento/module-customer/Model/Address/CustomerAddressDataProvider.php +++ b/vendor/magento/module-customer/Model/Address/CustomerAddressDataProvider.php @@ -7,18 +7,15 @@ namespace Magento\Customer\Model\Address; +use Magento\Customer\Api\Data\CustomerInterface; use Magento\Customer\Model\Config\Share; use Magento\Directory\Model\AllowedCountries; use Magento\Framework\App\ObjectManager; +use Magento\Framework\Exception\LocalizedException; -/** - * Provides customer address data. - */ class CustomerAddressDataProvider { /** - * Customer addresses. - * * @var array */ private $customerAddresses = []; @@ -58,12 +55,14 @@ public function __construct( /** * Get addresses for customer. * - * @param \Magento\Customer\Api\Data\CustomerInterface $customer + * @param CustomerInterface $customer + * @param int|null $addressLimit * @return array - * @throws \Magento\Framework\Exception\LocalizedException + * @throws LocalizedException */ public function getAddressDataByCustomer( - \Magento\Customer\Api\Data\CustomerInterface $customer + \Magento\Customer\Api\Data\CustomerInterface $customer, + ?int $addressLimit = null ): array { if (!empty($this->customerAddresses)) { return $this->customerAddresses; @@ -83,6 +82,9 @@ public function getAddressDataByCustomer( } $customerAddresses[$address->getId()] = $this->customerAddressDataFormatter->prepareAddress($address); + if ($addressLimit && count($customerAddresses) >= $addressLimit) { + break; + } } $this->customerAddresses = $customerAddresses;