Skip to content

Commit 9c9ed91

Browse files
Merge forwardport of #11462 to 2.3-develop branch
Applied pull request patch https://github.com/magento/magento2/pull/11462.patch (created by @avstudnitz) based on commit(s): 1. 11e38f6 2. 7800e5d 3. 252529f 4. 519b805 5. eb79b38 6. fce3afe 7. 3e38118 Fixed GitHub Issues in 2.3-develop branch: - #7241: No option to start with blank option for prefix and suffix in checkout. (reported by @spyrule)
2 parents 9354bb9 + d4c7ca0 commit 9c9ed91

File tree

5 files changed

+50
-14
lines changed

5 files changed

+50
-14
lines changed

app/code/Magento/Config/Model/Config/Source/Nooptreq.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
*/
1212
class Nooptreq implements \Magento\Framework\Option\ArrayInterface
1313
{
14+
const VALUE_NO = '';
15+
const VALUE_OPTIONAL = 'opt';
16+
const VALUE_REQUIRED = 'req';
17+
1418
/**
1519
* @return array
1620
*/
1721
public function toOptionArray()
1822
{
1923
return [
20-
['value' => '', 'label' => __('No')],
21-
['value' => 'opt', 'label' => __('Optional')],
22-
['value' => 'req', 'label' => __('Required')]
24+
['value' => self::VALUE_NO, 'label' => __('No')],
25+
['value' => self::VALUE_OPTIONAL, 'label' => __('Optional')],
26+
['value' => self::VALUE_REQUIRED, 'label' => __('Required')]
2327
];
2428
}
2529
}

app/code/Magento/Customer/Block/Widget/Name.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ public function getPrefixOptions()
106106
$prefixOptions = $this->options->getNamePrefixOptions();
107107

108108
if ($this->getObject() && !empty($prefixOptions)) {
109-
$oldPrefix = $this->escapeHtml(trim($this->getObject()->getPrefix()));
110-
$prefixOptions[$oldPrefix] = $oldPrefix;
109+
$prefixOption = $this->getObject()->getPrefix();
110+
$oldPrefix = $this->escapeHtml(trim($prefixOption));
111+
if ($prefixOption !== null && !isset($prefixOptions[$oldPrefix]) && !isset($prefixOptions[$prefixOption])) {
112+
$prefixOptions[$oldPrefix] = $oldPrefix;
113+
}
111114
}
112115
return $prefixOptions;
113116
}
@@ -161,8 +164,11 @@ public function getSuffixOptions()
161164
{
162165
$suffixOptions = $this->options->getNameSuffixOptions();
163166
if ($this->getObject() && !empty($suffixOptions)) {
164-
$oldSuffix = $this->escapeHtml(trim($this->getObject()->getSuffix()));
165-
$suffixOptions[$oldSuffix] = $oldSuffix;
167+
$suffixOption = $this->getObject()->getSuffix();
168+
$oldSuffix = $this->escapeHtml(trim($suffixOption));
169+
if ($suffixOption !== null && !isset($suffixOptions[$oldSuffix]) && !isset($suffixOptions[$suffixOption])) {
170+
$suffixOptions[$oldSuffix] = $oldSuffix;
171+
}
166172
}
167173
return $suffixOptions;
168174
}

app/code/Magento/Customer/Model/Options.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Customer\Model;
77

8+
use Magento\Config\Model\Config\Source\Nooptreq as NooptreqSource;
89
use Magento\Customer\Helper\Address as AddressHelper;
910
use Magento\Framework\Escaper;
1011

@@ -42,7 +43,10 @@ public function __construct(
4243
*/
4344
public function getNamePrefixOptions($store = null)
4445
{
45-
return $this->_prepareNamePrefixSuffixOptions($this->addressHelper->getConfig('prefix_options', $store));
46+
return $this->prepareNamePrefixSuffixOptions(
47+
$this->addressHelper->getConfig('prefix_options', $store),
48+
$this->addressHelper->getConfig('prefix_show', $store) == NooptreqSource::VALUE_OPTIONAL
49+
);
4650
}
4751

4852
/**
@@ -53,16 +57,34 @@ public function getNamePrefixOptions($store = null)
5357
*/
5458
public function getNameSuffixOptions($store = null)
5559
{
56-
return $this->_prepareNamePrefixSuffixOptions($this->addressHelper->getConfig('suffix_options', $store));
60+
return $this->prepareNamePrefixSuffixOptions(
61+
$this->addressHelper->getConfig('suffix_options', $store),
62+
$this->addressHelper->getConfig('suffix_show', $store) == NooptreqSource::VALUE_OPTIONAL
63+
);
64+
}
65+
66+
/**
67+
* @param $options
68+
* @param bool $isOptional
69+
* @return array|bool
70+
*
71+
* @deprecated
72+
* @see prepareNamePrefixSuffixOptions()
73+
*/
74+
protected function _prepareNamePrefixSuffixOptions($options, $isOptional = false)
75+
{
76+
return $this->prepareNamePrefixSuffixOptions($options, $isOptional);
5777
}
5878

5979
/**
6080
* Unserialize and clear name prefix or suffix options
81+
* If field is optional, add an empty first option.
6182
*
6283
* @param string $options
84+
* @param bool $isOptional
6385
* @return array|bool
6486
*/
65-
protected function _prepareNamePrefixSuffixOptions($options)
87+
private function prepareNamePrefixSuffixOptions($options, $isOptional = false)
6688
{
6789
$options = trim($options);
6890
if (empty($options)) {
@@ -74,6 +96,10 @@ protected function _prepareNamePrefixSuffixOptions($options)
7496
$value = $this->escaper->escapeHtml(trim($value));
7597
$result[$value] = $value;
7698
}
99+
if ($isOptional && trim(current($options))) {
100+
$result = array_merge([' ' => ' '], $result);
101+
}
102+
77103
return $result;
78104
}
79105
}

app/code/Magento/Customer/etc/adminhtml/system.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@
209209
<field id="prefix_options" translate="label comment" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
210210
<label>Prefix Dropdown Options</label>
211211
<comment>
212-
<![CDATA[Semicolon (;) separated values.<br/>Put semicolon in the beginning for empty first option.<br/>Leave empty for open text field.]]>
212+
<![CDATA[Semicolon (;) separated values.<br/>Leave empty for open text field.]]>
213213
</comment>
214214
</field>
215215
<field id="middlename_show" translate="label comment" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
@@ -227,7 +227,7 @@
227227
<field id="suffix_options" translate="label comment" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
228228
<label>Suffix Dropdown Options</label>
229229
<comment>
230-
<![CDATA[Semicolon (;) separated values.<br/>Put semicolon in the beginning for empty first option.<br/>Leave empty for open text field.]]>
230+
<![CDATA[Semicolon (;) separated values.<br/>Leave empty for open text field.]]>
231231
</comment>
232232
</field>
233233
<field id="dob_show" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">

app/code/Magento/Customer/i18n/en_US.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ Strong,Strong
479479
"The title that goes before name (Mr., Mrs., etc.)","The title that goes before name (Mr., Mrs., etc.)"
480480
"Prefix Dropdown Options","Prefix Dropdown Options"
481481
"
482-
Semicolon (;) separated values.<br/>Put semicolon in the beginning for empty first option.<br/>Leave empty for open text field.
482+
Semicolon (;) separated values.<br/>Leave empty for open text field.
483483
","
484-
Semicolon (;) separated values.<br/>Put semicolon in the beginning for empty first option.<br/>Leave empty for open text field.
484+
Semicolon (;) separated values.<br/>Leave empty for open text field.
485485
"
486486
"Show Middle Name (initial)","Show Middle Name (initial)"
487487
"Always optional.","Always optional."

0 commit comments

Comments
 (0)