Skip to content

Commit 4336fb0

Browse files
committed
Merge remote-tracking branch 'github-magento/MAGETWO-91517' into EPAM-PR-16
2 parents 57fb307 + 02bdadd commit 4336fb0

File tree

3 files changed

+80
-8
lines changed

3 files changed

+80
-8
lines changed

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

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Customer\Model\Session as CustomerSession;
1515
use Magento\Customer\Model\Url as CustomerUrlManager;
1616
use Magento\Eav\Api\AttributeOptionManagementInterface;
17+
use Magento\Framework\Api\CustomAttributesDataInterface;
1718
use Magento\Framework\App\Config\ScopeConfigInterface;
1819
use Magento\Framework\App\Http\Context as HttpContext;
1920
use Magento\Framework\App\ObjectManager;
@@ -22,9 +23,11 @@
2223
use Magento\Framework\UrlInterface;
2324
use Magento\Quote\Api\CartItemRepositoryInterface as QuoteItemRepository;
2425
use Magento\Quote\Api\CartTotalRepositoryInterface;
26+
use Magento\Quote\Api\Data\AddressInterface;
2527
use Magento\Quote\Api\ShippingMethodManagementInterface as ShippingMethodManager;
2628
use Magento\Quote\Model\QuoteIdMaskFactory;
2729
use Magento\Store\Model\ScopeInterface;
30+
use Magento\Ui\Component\Form\Element\Multiline;
2831

2932
/**
3033
* Default Config Provider
@@ -272,16 +275,28 @@ public function __construct(
272275
*
273276
* @return array|mixed
274277
* @throws \Magento\Framework\Exception\NoSuchEntityException
278+
* @throws \Magento\Framework\Exception\LocalizedException
275279
*/
276280
public function getConfig()
277281
{
278-
$quoteId = $this->checkoutSession->getQuote()->getId();
282+
$quote = $this->checkoutSession->getQuote();
283+
$quoteId = $quote->getId();
284+
$email = $quote->getShippingAddress()->getEmail();
279285
$output['formKey'] = $this->formKey->getFormKey();
280286
$output['customerData'] = $this->getCustomerData();
281287
$output['quoteData'] = $this->getQuoteData();
282288
$output['quoteItemData'] = $this->getQuoteItemData();
283289
$output['isCustomerLoggedIn'] = $this->isCustomerLoggedIn();
284290
$output['selectedShippingMethod'] = $this->getSelectedShippingMethod();
291+
if ($email && !$this->isCustomerLoggedIn()) {
292+
$shippingAddressFromData = $this->getAddressFromData($quote->getShippingAddress());
293+
$billingAddressFromData = $this->getAddressFromData($quote->getBillingAddress());
294+
$output['shippingAddressFromData'] = $shippingAddressFromData;
295+
if ($shippingAddressFromData != $billingAddressFromData) {
296+
$output['billingAddressFromData'] = $billingAddressFromData;
297+
}
298+
$output['validatedEmailValue'] = $email;
299+
}
285300
$output['storeCode'] = $this->getStoreCode();
286301
$output['isGuestCheckoutAllowed'] = $this->isGuestCheckoutAllowed();
287302
$output['isCustomerLoginRequired'] = $this->isCustomerLoginRequired();
@@ -293,11 +308,11 @@ public function getConfig()
293308
$output['staticBaseUrl'] = $this->getStaticBaseUrl();
294309
$output['priceFormat'] = $this->localeFormat->getPriceFormat(
295310
null,
296-
$this->checkoutSession->getQuote()->getQuoteCurrencyCode()
311+
$quote->getQuoteCurrencyCode()
297312
);
298313
$output['basePriceFormat'] = $this->localeFormat->getPriceFormat(
299314
null,
300-
$this->checkoutSession->getQuote()->getBaseCurrencyCode()
315+
$quote->getBaseCurrencyCode()
301316
);
302317
$output['postCodes'] = $this->postCodesConfig->getPostCodes();
303318
$output['imageData'] = $this->imageProvider->getImages($quoteId);
@@ -528,6 +543,38 @@ private function getSelectedShippingMethod()
528543
return $shippingMethodData;
529544
}
530545

546+
/**
547+
* Create address data appropriate to fill checkout address form
548+
*
549+
* @param AddressInterface $address
550+
* @return array
551+
* @throws \Magento\Framework\Exception\LocalizedException
552+
*/
553+
private function getAddressFromData(AddressInterface $address)
554+
{
555+
$addressData = [];
556+
$attributesMetadata = $this->addressMetadata->getAllAttributesMetadata();
557+
foreach ($attributesMetadata as $attributeMetadata) {
558+
if (!$attributeMetadata->isVisible()) {
559+
continue;
560+
}
561+
$attributeCode = $attributeMetadata->getAttributeCode();
562+
$attributeData = $address->getData($attributeCode);
563+
if ($attributeData) {
564+
if ($attributeMetadata->getFrontendInput() === Multiline::NAME) {
565+
$attributeData = \is_array($attributeData) ? $attributeData : explode("\n", $attributeData);
566+
$attributeData = (object)$attributeData;
567+
}
568+
if ($attributeMetadata->isUserDefined()) {
569+
$addressData[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES][$attributeCode] = $attributeData;
570+
continue;
571+
}
572+
$addressData[$attributeCode] = $attributeData;
573+
}
574+
}
575+
return $addressData;
576+
}
577+
531578
/**
532579
* Retrieve store code
533580
*

app/code/Magento/Checkout/view/frontend/web/js/model/checkout-data-resolver.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,21 @@ define([
6060
this.resolveBillingAddress();
6161
}
6262
}
63-
6463
},
6564

6665
/**
6766
* Resolve shipping address. Used local storage
6867
*/
6968
resolveShippingAddress: function () {
70-
var newCustomerShippingAddress = checkoutData.getNewCustomerShippingAddress();
69+
var newCustomerShippingAddress;
70+
71+
if (!checkoutData.getShippingAddressFromData() &&
72+
window.checkoutConfig.shippingAddressFromData
73+
) {
74+
checkoutData.setShippingAddressFromData(window.checkoutConfig.shippingAddressFromData);
75+
}
76+
77+
newCustomerShippingAddress = checkoutData.getNewCustomerShippingAddress();
7178

7279
if (newCustomerShippingAddress) {
7380
createShippingAddress(newCustomerShippingAddress);
@@ -196,8 +203,17 @@ define([
196203
* Resolve billing address. Used local storage
197204
*/
198205
resolveBillingAddress: function () {
199-
var selectedBillingAddress = checkoutData.getSelectedBillingAddress(),
200-
newCustomerBillingAddressData = checkoutData.getNewCustomerBillingAddress();
206+
var selectedBillingAddress,
207+
newCustomerBillingAddressData;
208+
209+
if (!checkoutData.getBillingAddressFromData() &&
210+
window.checkoutConfig.billingAddressFromData
211+
) {
212+
checkoutData.setBillingAddressFromData(window.checkoutConfig.billingAddressFromData);
213+
}
214+
215+
selectedBillingAddress = checkoutData.getSelectedBillingAddress();
216+
newCustomerBillingAddressData = checkoutData.getNewCustomerBillingAddress();
201217

202218
if (selectedBillingAddress) {
203219
if (selectedBillingAddress == 'new-customer-address' && newCustomerBillingAddressData) { //eslint-disable-line

app/code/Magento/Checkout/view/frontend/web/js/view/form/element/email.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ define([
1717
], function ($, Component, ko, customer, checkEmailAvailability, loginAction, quote, checkoutData, fullScreenLoader) {
1818
'use strict';
1919

20-
var validatedEmail = checkoutData.getValidatedEmailValue();
20+
var validatedEmail;
21+
22+
if (!checkoutData.getValidatedEmailValue() &&
23+
window.checkoutConfig.validatedEmailValue
24+
) {
25+
checkoutData.setInputFieldEmailValue(window.checkoutConfig.validatedEmailValue);
26+
checkoutData.setValidatedEmailValue(window.checkoutConfig.validatedEmailValue);
27+
}
28+
29+
validatedEmail = checkoutData.getValidatedEmailValue();
2130

2231
if (validatedEmail && !customer.isLoggedIn()) {
2332
quote.guestEmail = validatedEmail;

0 commit comments

Comments
 (0)