|
11 | 11 | use Magento\Checkout\Model\Session as CheckoutSession;
|
12 | 12 | use Magento\Customer\Api\AddressMetadataInterface;
|
13 | 13 | use Magento\Customer\Api\CustomerRepositoryInterface as CustomerRepository;
|
| 14 | +use Magento\Customer\Api\Data\CustomerInterface; |
14 | 15 | use Magento\Customer\Model\Address\CustomerAddressDataProvider;
|
15 | 16 | use Magento\Customer\Model\Context as CustomerContext;
|
16 | 17 | use Magento\Customer\Model\Session as CustomerSession;
|
@@ -311,14 +312,11 @@ public function getConfig()
|
311 | 312 | $output['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
|
312 | 313 | $output['selectedShippingMethod'] = $this->getSelectedShippingMethod();
|
313 | 314 | if ($email && !$this->isCustomerLoggedIn()) {
|
314 |
| - $shippingAddressFromData = $this->getAddressFromData($quote->getShippingAddress()); |
315 |
| - $billingAddressFromData = $this->getAddressFromData($quote->getBillingAddress()); |
316 |
| - $output['shippingAddressFromData'] = $shippingAddressFromData; |
317 |
| - if ($shippingAddressFromData != $billingAddressFromData) { |
318 |
| - $output['billingAddressFromData'] = $billingAddressFromData; |
319 |
| - } |
320 | 315 | $output['validatedEmailValue'] = $email;
|
321 | 316 | }
|
| 317 | + if (!$this->isCustomerLoggedIn() || !$this->getCustomer()->getAddresses()) { |
| 318 | + $output = array_merge($output, $this->getQuoteAddressData()); |
| 319 | + } |
322 | 320 | $output['storeCode'] = $this->getStoreCode();
|
323 | 321 | $output['isGuestCheckoutAllowed'] = $this->isGuestCheckoutAllowed();
|
324 | 322 | $output['isCustomerLoginRequired'] = $this->isCustomerLoginRequired();
|
@@ -387,8 +385,7 @@ private function getCustomerData(): array
|
387 | 385 | {
|
388 | 386 | $customerData = [];
|
389 | 387 | if ($this->isCustomerLoggedIn()) {
|
390 |
| - /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */ |
391 |
| - $customer = $this->customerRepository->getById($this->customerSession->getCustomerId()); |
| 388 | + $customer = $this->getCustomer(); |
392 | 389 | $customerData = $customer->__toArray();
|
393 | 390 | $customerData['addresses'] = $this->customerAddressData->getAddressDataByCustomer($customer);
|
394 | 391 | }
|
@@ -731,4 +728,43 @@ private function getQuoteItemsMessages(array $quoteItemData): array
|
731 | 728 |
|
732 | 729 | return $quoteItemsMessages;
|
733 | 730 | }
|
| 731 | + |
| 732 | + /** |
| 733 | + * Get quote address data for checkout |
| 734 | + * |
| 735 | + * @return array |
| 736 | + */ |
| 737 | + private function getQuoteAddressData(): array |
| 738 | + { |
| 739 | + $output = []; |
| 740 | + $quote = $this->checkoutSession->getQuote(); |
| 741 | + $shippingAddressFromData = []; |
| 742 | + if ($quote->getShippingAddress()->getEmail()) { |
| 743 | + $shippingAddressFromData = $this->getAddressFromData($quote->getShippingAddress()); |
| 744 | + if ($shippingAddressFromData) { |
| 745 | + $output['isShippingAddressFromDataValid'] = $quote->getShippingAddress()->validate() === true; |
| 746 | + $output['shippingAddressFromData'] = $shippingAddressFromData; |
| 747 | + } |
| 748 | + } |
| 749 | + |
| 750 | + if ($quote->getBillingAddress()->getEmail()) { |
| 751 | + $billingAddressFromData = $this->getAddressFromData($quote->getBillingAddress()); |
| 752 | + if ($billingAddressFromData && $shippingAddressFromData != $billingAddressFromData) { |
| 753 | + $output['isBillingAddressFromDataValid'] = $quote->getBillingAddress()->validate() === true; |
| 754 | + $output['billingAddressFromData'] = $billingAddressFromData; |
| 755 | + } |
| 756 | + } |
| 757 | + |
| 758 | + return $output; |
| 759 | + } |
| 760 | + |
| 761 | + /** |
| 762 | + * Get logged-in customer |
| 763 | + * |
| 764 | + * @return CustomerInterface |
| 765 | + */ |
| 766 | + private function getCustomer(): CustomerInterface |
| 767 | + { |
| 768 | + return $this->customerRepository->getById($this->customerSession->getCustomerId()); |
| 769 | + } |
734 | 770 | }
|
0 commit comments