Skip to content

Commit

Permalink
Merge forwardport of #11462 to 2.3-develop branch
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
magento-engcom-team authored Jan 24, 2018
2 parents 9354bb9 + d4c7ca0 commit 9c9ed91
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
10 changes: 7 additions & 3 deletions app/code/Magento/Config/Model/Config/Source/Nooptreq.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@
*/
class Nooptreq implements \Magento\Framework\Option\ArrayInterface
{
const VALUE_NO = '';
const VALUE_OPTIONAL = 'opt';
const VALUE_REQUIRED = 'req';

/**
* @return array
*/
public function toOptionArray()
{
return [
['value' => '', 'label' => __('No')],
['value' => 'opt', 'label' => __('Optional')],
['value' => 'req', 'label' => __('Required')]
['value' => self::VALUE_NO, 'label' => __('No')],
['value' => self::VALUE_OPTIONAL, 'label' => __('Optional')],
['value' => self::VALUE_REQUIRED, 'label' => __('Required')]
];
}
}
14 changes: 10 additions & 4 deletions app/code/Magento/Customer/Block/Widget/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ public function getPrefixOptions()
$prefixOptions = $this->options->getNamePrefixOptions();

if ($this->getObject() && !empty($prefixOptions)) {
$oldPrefix = $this->escapeHtml(trim($this->getObject()->getPrefix()));
$prefixOptions[$oldPrefix] = $oldPrefix;
$prefixOption = $this->getObject()->getPrefix();
$oldPrefix = $this->escapeHtml(trim($prefixOption));
if ($prefixOption !== null && !isset($prefixOptions[$oldPrefix]) && !isset($prefixOptions[$prefixOption])) {
$prefixOptions[$oldPrefix] = $oldPrefix;
}
}
return $prefixOptions;
}
Expand Down Expand Up @@ -161,8 +164,11 @@ public function getSuffixOptions()
{
$suffixOptions = $this->options->getNameSuffixOptions();
if ($this->getObject() && !empty($suffixOptions)) {
$oldSuffix = $this->escapeHtml(trim($this->getObject()->getSuffix()));
$suffixOptions[$oldSuffix] = $oldSuffix;
$suffixOption = $this->getObject()->getSuffix();
$oldSuffix = $this->escapeHtml(trim($suffixOption));
if ($suffixOption !== null && !isset($suffixOptions[$oldSuffix]) && !isset($suffixOptions[$suffixOption])) {
$suffixOptions[$oldSuffix] = $oldSuffix;
}
}
return $suffixOptions;
}
Expand Down
32 changes: 29 additions & 3 deletions app/code/Magento/Customer/Model/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Customer\Model;

use Magento\Config\Model\Config\Source\Nooptreq as NooptreqSource;
use Magento\Customer\Helper\Address as AddressHelper;
use Magento\Framework\Escaper;

Expand Down Expand Up @@ -42,7 +43,10 @@ public function __construct(
*/
public function getNamePrefixOptions($store = null)
{
return $this->_prepareNamePrefixSuffixOptions($this->addressHelper->getConfig('prefix_options', $store));
return $this->prepareNamePrefixSuffixOptions(
$this->addressHelper->getConfig('prefix_options', $store),
$this->addressHelper->getConfig('prefix_show', $store) == NooptreqSource::VALUE_OPTIONAL
);
}

/**
Expand All @@ -53,16 +57,34 @@ public function getNamePrefixOptions($store = null)
*/
public function getNameSuffixOptions($store = null)
{
return $this->_prepareNamePrefixSuffixOptions($this->addressHelper->getConfig('suffix_options', $store));
return $this->prepareNamePrefixSuffixOptions(
$this->addressHelper->getConfig('suffix_options', $store),
$this->addressHelper->getConfig('suffix_show', $store) == NooptreqSource::VALUE_OPTIONAL
);
}

/**
* @param $options
* @param bool $isOptional
* @return array|bool
*
* @deprecated
* @see prepareNamePrefixSuffixOptions()
*/
protected function _prepareNamePrefixSuffixOptions($options, $isOptional = false)
{
return $this->prepareNamePrefixSuffixOptions($options, $isOptional);
}

/**
* Unserialize and clear name prefix or suffix options
* If field is optional, add an empty first option.
*
* @param string $options
* @param bool $isOptional
* @return array|bool
*/
protected function _prepareNamePrefixSuffixOptions($options)
private function prepareNamePrefixSuffixOptions($options, $isOptional = false)
{
$options = trim($options);
if (empty($options)) {
Expand All @@ -74,6 +96,10 @@ protected function _prepareNamePrefixSuffixOptions($options)
$value = $this->escaper->escapeHtml(trim($value));
$result[$value] = $value;
}
if ($isOptional && trim(current($options))) {
$result = array_merge([' ' => ' '], $result);
}

return $result;
}
}
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
<field id="prefix_options" translate="label comment" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Prefix Dropdown Options</label>
<comment>
<![CDATA[Semicolon (;) separated values.<br/>Put semicolon in the beginning for empty first option.<br/>Leave empty for open text field.]]>
<![CDATA[Semicolon (;) separated values.<br/>Leave empty for open text field.]]>
</comment>
</field>
<field id="middlename_show" translate="label comment" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
Expand All @@ -227,7 +227,7 @@
<field id="suffix_options" translate="label comment" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Suffix Dropdown Options</label>
<comment>
<![CDATA[Semicolon (;) separated values.<br/>Put semicolon in the beginning for empty first option.<br/>Leave empty for open text field.]]>
<![CDATA[Semicolon (;) separated values.<br/>Leave empty for open text field.]]>
</comment>
</field>
<field id="dob_show" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Customer/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ Strong,Strong
"The title that goes before name (Mr., Mrs., etc.)","The title that goes before name (Mr., Mrs., etc.)"
"Prefix Dropdown Options","Prefix Dropdown Options"
"
Semicolon (;) separated values.<br/>Put semicolon in the beginning for empty first option.<br/>Leave empty for open text field.
Semicolon (;) separated values.<br/>Leave empty for open text field.
","
Semicolon (;) separated values.<br/>Put semicolon in the beginning for empty first option.<br/>Leave empty for open text field.
Semicolon (;) separated values.<br/>Leave empty for open text field.
"
"Show Middle Name (initial)","Show Middle Name (initial)"
"Always optional.","Always optional."
Expand Down

0 comments on commit 9c9ed91

Please sign in to comment.