Skip to content

Commit 3bb7ca3

Browse files
committed
Merge branch 'MAGETWO-34253' into PR
2 parents ca7b047 + 9e733aa commit 3bb7ca3

File tree

6 files changed

+113
-3
lines changed

6 files changed

+113
-3
lines changed

app/code/Magento/Customer/etc/data_source/customer_address.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848
</constraints>
4949
</field>
5050
<field name="region" source="eav" formElement="input" visible="false"/>
51-
<field name="postcode" source="eav">
51+
52+
<field name="postcode" source="eav" formElement="post_code_fix" >
5253
<constraints>
5354
<validate name="required-entry"/>
5455
</constraints>
5556
</field>
57+
5658
<field name="telephone" source="eav" label="Phone Number">
5759
<constraints>
5860
<validate name="required-entry"/>

app/code/Magento/Directory/Model/Resource/Country/Collection.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class Collection extends \Magento\Framework\Model\Resource\Db\Collection\Abstrac
4444
*/
4545
protected $_localeResolver;
4646

47+
/**
48+
* @var \Magento\Directory\Helper\Data
49+
*/
50+
protected $helperData;
51+
4752
/**
4853
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
4954
* @param \Psr\Log\LoggerInterface $logger
@@ -68,6 +73,7 @@ public function __construct(
6873
\Magento\Directory\Model\Resource\CountryFactory $countryFactory,
6974
\Magento\Framework\Stdlib\ArrayUtils $arrayUtils,
7075
\Magento\Framework\Locale\ResolverInterface $localeResolver,
76+
\Magento\Framework\App\Helper\AbstractHelper $helperData,
7177
$connection = null,
7278
\Magento\Framework\Model\Resource\Db\AbstractDb $resource = null
7379
) {
@@ -77,6 +83,7 @@ public function __construct(
7783
$this->_localeResolver = $localeResolver;
7884
$this->_countryFactory = $countryFactory;
7985
$this->_arrayUtils = $arrayUtils;
86+
$this->helperData = $helperData;
8087
}
8188

8289
/**
@@ -208,7 +215,11 @@ public function toOptionArray($emptyLabel = ' ')
208215
}
209216
$options = [];
210217
foreach ($sort as $label => $value) {
211-
$options[] = ['value' => $value, 'label' => $label];
218+
$option = ['value' => $value, 'label' => $label];
219+
if ($this->helperData->isRegionRequired($value)) {
220+
$option['is_region_required'] = 'true';
221+
}
222+
$options[] = $option;
212223
}
213224

214225
if (count($options) > 0 && $emptyLabel !== false) {

app/code/Magento/Directory/etc/di.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
9-
<type name="Magento\Directory\Model\Resource\Country\Collection" shared="false" />
109
<type name="Magento\Directory\Model\Currency\Import\Config">
1110
<arguments>
1211
<argument name="servicesConfig" xsi:type="array">
@@ -17,4 +16,15 @@
1716
</argument>
1817
</arguments>
1918
</type>
19+
20+
<virtualType name="DirectoryHelperDataProxy" type="Magento\Directory\Helper\Data\Proxy">
21+
<arguments>
22+
<argument name="instanceName" xsi:type="string">Magento\Directory\Helper\Data</argument>
23+
</arguments>
24+
</virtualType>
25+
<type name="Magento\Directory\Model\Resource\Country\Collection" shared="false">
26+
<arguments>
27+
<argument name="helperData" xsi:type="object">DirectoryHelperDataProxy</argument>
28+
</arguments>
29+
</type>
2030
</config>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Ui\Component\Form\Element\DataType;
7+
8+
/**
9+
* Class Number
10+
*/
11+
class PostCodeFix extends AbstractDataType
12+
{
13+
//
14+
}

app/code/Magento/Ui/view/base/layout/ui_components.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,13 @@
233233
</argument>
234234
</arguments>
235235
</block>
236+
237+
<block class="Magento\Ui\Component\Form\Element\DataType\PostCodeFix" name="post_code_fix">
238+
<arguments>
239+
<argument name="js_config" xsi:type="array">
240+
<item name="component" xsi:type="string">Magento_Ui/js/form/element/post-code-fix</item>
241+
<item name="dependentFiled" xsi:type="string">country_id</item>
242+
</argument>
243+
</arguments>
244+
</block>
236245
</layout>
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright © 2015 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'underscore',
7+
'Magento_Ui/js/lib/registry/registry',
8+
'./abstract'
9+
], function (_, registry, Abstract) {
10+
'use strict';
11+
12+
return Abstract.extend({
13+
/**
14+
* Extended list of Listeners
15+
*
16+
* @return {this}
17+
*/
18+
initListeners: function(){
19+
this._super()
20+
.update()
21+
.provider.data.on('update:'+this.parentScope+'.country_id', this.update.bind(this));
22+
23+
return this;
24+
},
25+
26+
/**
27+
* Fix _postcode_ depend on _country_id_ change:
28+
* - If country in list "Zip/Postal Code is Optional countries" then
29+
* - field "postcode" should not be required
30+
*
31+
* @returns {this}
32+
*/
33+
update: function(){
34+
var parentScope = this.getPart(this.getPart(this.name, -2), -2),
35+
option,
36+
postcode = this;
37+
38+
registry.get(parentScope + '.country_id.0', function (countryComponent) {
39+
var value = countryComponent.value();
40+
41+
if (!value) { // empty value discard logic
42+
return;
43+
}
44+
45+
countryComponent
46+
.options()
47+
.some(function (el) {
48+
option = el;
49+
return el.value === value;
50+
});
51+
52+
if(!option.is_region_required) {
53+
postcode.error(false);
54+
postcode.validation = _.omit(postcode.validation, 'required-entry');
55+
} else {
56+
postcode.validation['required-entry'] = true;
57+
}
58+
postcode.required(!!option.is_region_required);
59+
});
60+
61+
return this;
62+
}
63+
});
64+
});

0 commit comments

Comments
 (0)