Skip to content

Commit 1f77329

Browse files
authored
Merge pull request #3628 from magento-tsg-csl3/2.3-develop-pr14
[TSG-CSL3] For 2.3 (pr14)
2 parents 8e2ca94 + 7934809 commit 1f77329

File tree

13 files changed

+198
-75
lines changed

13 files changed

+198
-75
lines changed

app/code/Magento/Catalog/view/base/web/js/price-box.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,7 @@ define([
7878
pricesCode = [],
7979
priceValue, origin, finalPrice;
8080

81-
if (typeof newPrices !== 'undefined' && newPrices.hasOwnProperty('prices')) {
82-
this.cache.additionalPriceObject = {};
83-
} else {
84-
this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
85-
}
81+
this.cache.additionalPriceObject = this.cache.additionalPriceObject || {};
8682

8783
if (newPrices) {
8884
$.extend(this.cache.additionalPriceObject, newPrices);

app/code/Magento/Checkout/etc/frontend/sections.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
</action>
4747
<action name="rest/*/V1/guest-carts/*/payment-information">
4848
<section name="cart"/>
49-
<section name="checkout-data"/>
5049
</action>
5150
<action name="rest/*/V1/guest-carts/*/selected-payment-method">
5251
<section name="cart"/>

app/code/Magento/Checkout/view/frontend/web/js/model/place-order.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ define(
99
[
1010
'mage/storage',
1111
'Magento_Checkout/js/model/error-processor',
12-
'Magento_Checkout/js/model/full-screen-loader'
12+
'Magento_Checkout/js/model/full-screen-loader',
13+
'Magento_Customer/js/customer-data'
1314
],
14-
function (storage, errorProcessor, fullScreenLoader) {
15+
function (storage, errorProcessor, fullScreenLoader, customerData) {
1516
'use strict';
1617

1718
return function (serviceUrl, payload, messageContainer) {
@@ -23,6 +24,23 @@ define(
2324
function (response) {
2425
errorProcessor.process(response, messageContainer);
2526
}
27+
).success(
28+
function (response) {
29+
var clearData = {
30+
'selectedShippingAddress': null,
31+
'shippingAddressFromData': null,
32+
'newCustomerShippingAddress': null,
33+
'selectedShippingRate': null,
34+
'selectedPaymentMethod': null,
35+
'selectedBillingAddress': null,
36+
'billingAddressFromData': null,
37+
'newCustomerBillingAddress': null
38+
};
39+
40+
if (response.responseType !== 'error') {
41+
customerData.set('checkout-data', clearData);
42+
}
43+
}
2644
).always(
2745
function () {
2846
fullScreenLoader.stopLoader();

app/code/Magento/Checkout/view/frontend/web/js/model/postcode-validator.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ define([
1414
/**
1515
* @param {*} postCode
1616
* @param {*} countryId
17+
* @param {Array} postCodesPatterns
1718
* @return {Boolean}
1819
*/
19-
validate: function (postCode, countryId) {
20-
var patterns = window.checkoutConfig.postCodes[countryId],
21-
pattern, regex;
20+
validate: function (postCode, countryId, postCodesPatterns) {
21+
var pattern, regex,
22+
patterns = postCodesPatterns ? postCodesPatterns[countryId] :
23+
window.checkoutConfig.postCodes[countryId];
2224

2325
this.validatedPostCodeExample = [];
2426

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ define([
4242

4343
return {
4444
validateAddressTimeout: 0,
45+
validateZipCodeTimeout: 0,
4546
validateDelay: 2000,
4647

4748
/**
@@ -133,16 +134,20 @@ define([
133134
});
134135
} else {
135136
element.on('value', function () {
137+
clearTimeout(self.validateZipCodeTimeout);
138+
self.validateZipCodeTimeout = setTimeout(function () {
139+
if (element.index === postcodeElementName) {
140+
self.postcodeValidation(element);
141+
} else {
142+
$.each(postcodeElements, function (index, elem) {
143+
self.postcodeValidation(elem);
144+
});
145+
}
146+
}, delay);
147+
136148
if (!formPopUpState.isVisible()) {
137149
clearTimeout(self.validateAddressTimeout);
138150
self.validateAddressTimeout = setTimeout(function () {
139-
if (element.index === postcodeElementName) {
140-
self.postcodeValidation(element);
141-
} else {
142-
$.each(postcodeElements, function (index, elem) {
143-
self.postcodeValidation(elem);
144-
});
145-
}
146151
self.validateFields();
147152
}, delay);
148153
}

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ define([
376376
basePrice = parseFloat(this.options.spConfig.prices.basePrice.amount),
377377
optionFinalPrice,
378378
optionPriceDiff,
379-
optionPrices = this.options.spConfig.optionPrices;
379+
optionPrices = this.options.spConfig.optionPrices,
380+
allowedProductMinPrice;
380381

381382
this._clearSelect(element);
382383
element.options[0] = new Option('', '');
@@ -407,8 +408,8 @@ define([
407408

408409
if (typeof allowedProducts[0] !== 'undefined' &&
409410
typeof optionPrices[allowedProducts[0]] !== 'undefined') {
410-
411-
optionFinalPrice = parseFloat(optionPrices[allowedProducts[0]].finalPrice.amount);
411+
allowedProductMinPrice = this._getAllowedProductWithMinPrice(allowedProducts);
412+
optionFinalPrice = parseFloat(optionPrices[allowedProductMinPrice].finalPrice.amount);
412413
optionPriceDiff = optionFinalPrice - basePrice;
413414

414415
if (optionPriceDiff !== 0) {
@@ -489,36 +490,27 @@ define([
489490
_getPrices: function () {
490491
var prices = {},
491492
elements = _.toArray(this.options.settings),
492-
hasProductPrice = false,
493-
optionPriceDiff = 0,
494-
allowedProduct, optionPrices, basePrice, optionFinalPrice;
493+
allowedProduct;
495494

496495
_.each(elements, function (element) {
497496
var selected = element.options[element.selectedIndex],
498497
config = selected && selected.config,
499498
priceValue = {};
500499

501-
if (config && config.allowedProducts.length === 1 && !hasProductPrice) {
502-
prices = {};
500+
if (config && config.allowedProducts.length === 1) {
503501
priceValue = this._calculatePrice(config);
504-
hasProductPrice = true;
505502
} else if (element.value) {
506503
allowedProduct = this._getAllowedProductWithMinPrice(config.allowedProducts);
507-
optionPrices = this.options.spConfig.optionPrices;
508-
basePrice = parseFloat(this.options.spConfig.prices.basePrice.amount);
509-
510-
if (!_.isEmpty(allowedProduct)) {
511-
optionFinalPrice = parseFloat(optionPrices[allowedProduct].finalPrice.amount);
512-
optionPriceDiff = optionFinalPrice - basePrice;
513-
}
514-
515-
if (optionPriceDiff !== 0) {
516-
prices = {};
517-
priceValue = this._calculatePriceDifference(allowedProduct);
518-
}
504+
priceValue = this._calculatePrice({
505+
'allowedProducts': [
506+
allowedProduct
507+
]
508+
});
519509
}
520510

521-
prices[element.attributeId] = priceValue;
511+
if (!_.isEmpty(priceValue)) {
512+
prices.prices = priceValue;
513+
}
522514
}, this);
523515

524516
return prices;
@@ -539,40 +531,15 @@ define([
539531
_.each(allowedProducts, function (allowedProduct) {
540532
optionFinalPrice = parseFloat(optionPrices[allowedProduct].finalPrice.amount);
541533

542-
if (_.isEmpty(product)) {
534+
if (_.isEmpty(product) || optionFinalPrice < optionMinPrice) {
543535
optionMinPrice = optionFinalPrice;
544536
product = allowedProduct;
545537
}
546-
547-
if (optionFinalPrice < optionMinPrice) {
548-
product = allowedProduct;
549-
}
550538
}, this);
551539

552540
return product;
553541
},
554542

555-
/**
556-
* Calculate price difference for allowed product
557-
*
558-
* @param {*} allowedProduct - Product
559-
* @returns {*}
560-
* @private
561-
*/
562-
_calculatePriceDifference: function (allowedProduct) {
563-
var displayPrices = $(this.options.priceHolderSelector).priceBox('option').prices,
564-
newPrices = this.options.spConfig.optionPrices[allowedProduct];
565-
566-
_.each(displayPrices, function (price, code) {
567-
568-
if (newPrices[code]) {
569-
displayPrices[code].amount = newPrices[code].amount - displayPrices[code].amount;
570-
}
571-
});
572-
573-
return displayPrices;
574-
},
575-
576543
/**
577544
* Returns prices for configured products
578545
*
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Block\DataProviders;
9+
10+
use Magento\Framework\Serialize\SerializerInterface;
11+
use Magento\Framework\View\Element\Block\ArgumentInterface;
12+
use Magento\Directory\Model\Country\Postcode\Config as PostCodeConfig;
13+
14+
/**
15+
* Provides postcodes patterns into template.
16+
*/
17+
class PostCodesPatternsAttributeData implements ArgumentInterface
18+
{
19+
/**
20+
* @var PostCodeConfig
21+
*/
22+
private $postCodeConfig;
23+
24+
/**
25+
* @var SerializerInterface
26+
*/
27+
private $serializer;
28+
29+
/**
30+
* Constructor
31+
*
32+
* @param PostCodeConfig $postCodeConfig
33+
* @param SerializerInterface $serializer
34+
*/
35+
public function __construct(PostCodeConfig $postCodeConfig, SerializerInterface $serializer)
36+
{
37+
$this->postCodeConfig = $postCodeConfig;
38+
$this->serializer = $serializer;
39+
}
40+
41+
/**
42+
* Get serialized post codes
43+
*
44+
* @return string
45+
*/
46+
public function getSerializedPostCodes(): string
47+
{
48+
return $this->serializer->serialize($this->postCodeConfig->getPostCodes());
49+
}
50+
}

app/code/Magento/Customer/view/frontend/layout/customer_address_form.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<block class="Magento\Customer\Block\Address\Edit" name="customer_address_edit" template="Magento_Customer::address/edit.phtml" cacheable="false">
2121
<arguments>
2222
<argument name="attribute_data" xsi:type="object">Magento\Customer\Block\DataProviders\AddressAttributeData</argument>
23+
<argument name="post_code_config" xsi:type="object">Magento\Customer\Block\DataProviders\PostCodesPatternsAttributeData</argument>
2324
</arguments>
2425
</block>
2526
</referenceContainer>

app/code/Magento/Customer/view/frontend/templates/address/edit.phtml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
title="<?= /* @noEscape */ $block->getAttributeData()->getFrontendLabel('postcode') ?>"
127127
id="zip"
128128
class="input-text validate-zip-international <?= $block->escapeHtmlAttr($this->helper('Magento\Customer\Helper\Address')->getAttributeValidationClass('postcode')) ?>">
129+
<div role="alert" class="message warning" style="display:none">
130+
<span></span>
131+
</div>
129132
</div>
130133
</div>
131134
<div class="field country required">
@@ -184,7 +187,9 @@
184187
<script type="text/x-magento-init">
185188
{
186189
"#form-validate": {
187-
"addressValidation": {}
190+
"addressValidation": {
191+
"postCodes": <?= /* @noEscape */ $block->getPostCodeConfig()->getSerializedPostCodes(); ?>
192+
}
188193
},
189194
"#country": {
190195
"regionUpdater": {

0 commit comments

Comments
 (0)