diff --git a/vendor/magento/module-customer/etc/validation.xml b/vendor/magento/module-customer/etc/validation.xml index bac6e54afa7b5..114733e66d04d 100644 --- a/vendor/magento/module-customer/etc/validation.xml +++ b/vendor/magento/module-customer/etc/validation.xml @@ -46,11 +46,17 @@ + + + + + + diff --git a/vendor/magento/module-quote/Model/CustomerManagement.php b/vendor/magento/module-quote/Model/CustomerManagement.php index 3607cf7f9be63..f7443b49c4f44 100644 --- a/vendor/magento/module-quote/Model/CustomerManagement.php +++ b/vendor/magento/module-quote/Model/CustomerManagement.php @@ -10,6 +10,7 @@ use Magento\Customer\Api\AccountManagementInterface as AccountManagement; use Magento\Customer\Api\AddressRepositoryInterface as CustomerAddressRepository; use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository; +use Magento\Customer\Api\Data\AddressInterfaceFactory; use Magento\Customer\Model\AddressFactory; use Magento\Framework\App\ObjectManager; use Magento\Framework\Validator\Exception as ValidatorException; @@ -46,11 +47,17 @@ class CustomerManagement */ private $addressFactory; + /** + * @var AddressInterfaceFactory + */ + private $customerAddressFactory; + /** * CustomerManagement constructor. * @param CustomerRepository $customerRepository * @param CustomerAddressRepository $customerAddressRepository * @param AccountManagement $accountManagement + * @param AddressInterfaceFactory $customerAddressFactory * @param ValidatorFactory|null $validatorFactory * @param AddressFactory|null $addressFactory */ @@ -58,12 +65,14 @@ public function __construct( CustomerRepository $customerRepository, CustomerAddressRepository $customerAddressRepository, AccountManagement $accountManagement, + AddressInterfaceFactory $customerAddressFactory, ValidatorFactory $validatorFactory = null, AddressFactory $addressFactory = null ) { $this->customerRepository = $customerRepository; $this->customerAddressRepository = $customerAddressRepository; $this->accountManagement = $accountManagement; + $this->customerAddressFactory = $customerAddressFactory; $this->validatorFactory = $validatorFactory ?: ObjectManager::getInstance() ->get(ValidatorFactory::class); $this->addressFactory = $addressFactory ?: ObjectManager::getInstance() @@ -144,24 +153,34 @@ public function validateAddresses(QuoteEntity $quote) $addresses[] = $this->customerAddressRepository->getById( $quote->getBillingAddress()->getCustomerAddressId() ); + } else { + $billingAddress = $quote->getBillingAddress(); + $customerAddress = $this->customerAddressFactory->create(); + $customerAddress->setFirstname($billingAddress->getFirstname()); + $customerAddress->setLastname($billingAddress->getLastname()); + $customerAddress->setStreet($billingAddress->getStreet()); + $customerAddress->setCity($billingAddress->getCity()); + $customerAddress->setPostcode($billingAddress->getPostcode()); + $customerAddress->setTelephone($billingAddress->getTelephone()); + $customerAddress->setCountryId($billingAddress->getCountryId()); + $addresses[] = $customerAddress; } if ($quote->getShippingAddress()->getCustomerAddressId()) { $addresses[] = $this->customerAddressRepository->getById( $quote->getShippingAddress()->getCustomerAddressId() ); } - if (!empty($addresses)) { - foreach ($addresses as $address) { - $validator = $this->validatorFactory->createValidator('customer_address', 'save'); - $addressModel = $this->addressFactory->create(); - $addressModel->updateData($address); - if (!$validator->isValid($addressModel)) { - throw new ValidatorException( - null, - null, - $validator->getMessages() - ); - } + + foreach ($addresses as $address) { + $validator = $this->validatorFactory->createValidator('customer_address', 'save'); + $addressModel = $this->addressFactory->create(); + $addressModel->updateData($address); + if (!$validator->isValid($addressModel)) { + throw new ValidatorException( + null, + null, + $validator->getMessages() + ); } } } diff --git a/vendor/magento/module-quote/Model/QuoteManagement.php b/vendor/magento/module-quote/Model/QuoteManagement.php index 51b68411d4080..294543afa9b86 100644 --- a/vendor/magento/module-quote/Model/QuoteManagement.php +++ b/vendor/magento/module-quote/Model/QuoteManagement.php @@ -530,10 +530,10 @@ protected function submitQuote(QuoteEntity $quote, $orderData = []) if (!$quote->getCustomerIsGuest()) { if ($quote->getCustomerId()) { $this->_prepareCustomerQuote($quote); - $this->customerManagement->validateAddresses($quote); } $this->customerManagement->populateCustomerInfo($quote); } + $this->customerManagement->validateAddresses($quote); $addresses = []; $quote->reserveOrderId(); if ($quote->isVirtual()) {