Skip to content

Commit 401203a

Browse files
author
Lysenko Olexandr
authored
Merge pull request #3619 from magento-tsg-csl3/2.2-develop-pr19
[TSG-CSL3] For 2.2 (pr19)
2 parents 4c57fe0 + a986ed0 commit 401203a

File tree

13 files changed

+247
-28
lines changed

13 files changed

+247
-28
lines changed

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ protected function duplicate($product)
308308

309309
$this->resourceModel->duplicate(
310310
$this->getAttribute()->getAttributeId(),
311-
isset($mediaGalleryData['duplicate']) ? $mediaGalleryData['duplicate'] : [],
311+
$mediaGalleryData['duplicate'] ?? [],
312312
$product->getOriginalLinkId(),
313313
$product->getData($this->metadata->getLinkField())
314314
);

app/code/Magento/Catalog/Model/ResourceModel/Product/Gallery.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Catalog\Model\ResourceModel\Product;
78

89
use Magento\Store\Model\Store;
@@ -141,7 +142,7 @@ public function loadProductGalleryByAttributeId($product, $attributeId)
141142
*/
142143
protected function createBaseLoadSelect($entityId, $storeId, $attributeId)
143144
{
144-
$select = $this->createBatchBaseSelect($storeId, $attributeId);
145+
$select = $this->createBatchBaseSelect($storeId, $attributeId);
145146

146147
$select = $select->where(
147148
'entity.' . $this->metadata->getLinkField() . ' = ?',
@@ -362,9 +363,9 @@ public function deleteGalleryValueInStore($valueId, $entityId, $storeId)
362363
$conditions = implode(
363364
' AND ',
364365
[
365-
$this->getConnection()->quoteInto('value_id = ?', (int) $valueId),
366-
$this->getConnection()->quoteInto($this->metadata->getLinkField() . ' = ?', (int) $entityId),
367-
$this->getConnection()->quoteInto('store_id = ?', (int) $storeId)
366+
$this->getConnection()->quoteInto('value_id = ?', (int)$valueId),
367+
$this->getConnection()->quoteInto($this->metadata->getLinkField() . ' = ?', (int)$entityId),
368+
$this->getConnection()->quoteInto('store_id = ?', (int)$storeId)
368369
]
369370
);
370371

@@ -392,7 +393,7 @@ public function duplicate($attributeId, $newFiles, $originalProductId, $newProdu
392393

393394
$select = $this->getConnection()->select()->from(
394395
[$this->getMainTableAlias() => $this->getMainTable()],
395-
['value_id', 'value']
396+
['value_id', 'value', 'media_type', 'disabled']
396397
)->joinInner(
397398
['entity' => $this->getTable(self::GALLERY_VALUE_TO_ENTITY_TABLE)],
398399
$this->getMainTableAlias() . '.value_id = entity.value_id',
@@ -409,16 +410,16 @@ public function duplicate($attributeId, $newFiles, $originalProductId, $newProdu
409410

410411
// Duplicate main entries of gallery
411412
foreach ($this->getConnection()->fetchAll($select) as $row) {
412-
$data = [
413-
'attribute_id' => $attributeId,
414-
'value' => isset($newFiles[$row['value_id']]) ? $newFiles[$row['value_id']] : $row['value'],
415-
];
413+
$data = $row;
414+
$data['attribute_id'] = $attributeId;
415+
$data['value'] = $newFiles[$row['value_id']] ?? $row['value'];
416+
unset($data['value_id']);
416417

417418
$valueIdMap[$row['value_id']] = $this->insertGallery($data);
418419
$this->bindValueToEntity($valueIdMap[$row['value_id']], $newProductId);
419420
}
420421

421-
if (count($valueIdMap) == 0) {
422+
if (count($valueIdMap) === 0) {
422423
return [];
423424
}
424425

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
}
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::class)->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": {

app/code/Magento/Customer/view/frontend/web/js/addressValidation.js

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,38 @@
55

66
define([
77
'jquery',
8+
'underscore',
9+
'mageUtils',
10+
'mage/translate',
11+
'Magento_Checkout/js/model/postcode-validator',
812
'jquery/ui',
913
'validation'
10-
], function ($) {
14+
], function ($, __, utils, $t, postCodeValidator) {
1115
'use strict';
1216

1317
$.widget('mage.addressValidation', {
1418
options: {
1519
selectors: {
16-
button: '[data-action=save-address]'
20+
button: '[data-action=save-address]',
21+
zip: '#zip',
22+
country: 'select[name="country_id"]:visible'
1723
}
1824
},
1925

26+
zipInput: null,
27+
countrySelect: null,
28+
2029
/**
2130
* Validation creation
31+
*
2232
* @protected
2333
*/
2434
_create: function () {
2535
var button = $(this.options.selectors.button, this.element);
2636

37+
this.zipInput = $(this.options.selectors.zip, this.element);
38+
this.countrySelect = $(this.options.selectors.country, this.element);
39+
2740
this.element.validation({
2841

2942
/**
@@ -36,6 +49,75 @@ define([
3649
form.submit();
3750
}
3851
});
52+
53+
this._addPostCodeValidation();
54+
},
55+
56+
/**
57+
* Add postcode validation
58+
*
59+
* @protected
60+
*/
61+
_addPostCodeValidation: function () {
62+
var self = this;
63+
64+
this.zipInput.on('keyup', __.debounce(function (event) {
65+
var valid = self._validatePostCode(event.target.value);
66+
67+
self._renderValidationResult(valid);
68+
}, 500)
69+
);
70+
71+
this.countrySelect.on('change', function () {
72+
var valid = self._validatePostCode(self.zipInput.val());
73+
74+
self._renderValidationResult(valid);
75+
});
76+
},
77+
78+
/**
79+
* Validate post code value.
80+
*
81+
* @protected
82+
* @param {String} postCode - post code
83+
* @return {Boolean} Whether is post code valid
84+
*/
85+
_validatePostCode: function (postCode) {
86+
var countryId = this.countrySelect.val();
87+
88+
if (postCode === null) {
89+
return true;
90+
}
91+
92+
return postCodeValidator.validate(postCode, countryId, this.options.postCodes);
93+
},
94+
95+
/**
96+
* Renders warning messages for invalid post code.
97+
*
98+
* @protected
99+
* @param {Boolean} valid
100+
*/
101+
_renderValidationResult: function (valid) {
102+
var warnMessage,
103+
alertDiv = this.zipInput.next();
104+
105+
if (!valid) {
106+
warnMessage = $t('Provided Zip/Postal Code seems to be invalid.');
107+
108+
if (postCodeValidator.validatedPostCodeExample.length) {
109+
warnMessage += $t(' Example: ') + postCodeValidator.validatedPostCodeExample.join('; ') + '. ';
110+
}
111+
warnMessage += $t('If you believe it is the right one you can ignore this notice.');
112+
}
113+
114+
alertDiv.children(':first').text(warnMessage);
115+
116+
if (valid) {
117+
alertDiv.hide();
118+
} else {
119+
alertDiv.show();
120+
}
39121
}
40122
});
41123

app/code/Magento/Multishipping/view/frontend/layout/multishipping_checkout_customer_address.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<block class="Magento\Customer\Block\Address\Edit" name="customer_address_edit" template="Magento_Customer::address/edit.phtml" cacheable="false">
1313
<arguments>
1414
<argument name="attribute_data" xsi:type="object">Magento\Customer\Block\DataProviders\AddressAttributeData</argument>
15+
<argument name="post_code_config" xsi:type="object">Magento\Customer\Block\DataProviders\PostCodesPatternsAttributeData</argument>
1516
</arguments>
1617
</block>
1718
</referenceContainer>

0 commit comments

Comments
 (0)