From d4c7ca0d4aeac15b8961e0e8a582fe716a088972 Mon Sep 17 00:00:00 2001 From: Magento EngCom Team Date: Wed, 24 Jan 2018 12:12:48 -0600 Subject: [PATCH] :arrow_double_up: Forwardport of magento/magento2#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. 11e38f68a9956cbdc1d7c48284bc712729f43a90 2. 7800e5dd8aac704da3f2b1799baadf2a01269c61 3. 252529f0819d2792982452ed9d929d5fb526996d 4. 519b805c2853f895d804c49e08bd7a23b108c38c 5. eb79b38beb6b79411fe95d30e324d7d094ab5874 6. fce3afe6390be6c0eb2d5fcdb2f76108d6a44e77 7. 3e38118c1e7f92e77963a6ae4f42e66520e6f58f Fixed GitHub Issues in 2.3-develop branch: - magento/magento2#7241: No option to start with blank option for prefix and suffix in checkout. (reported by @spyrule) --- .../Config/Model/Config/Source/Nooptreq.php | 10 ++++-- .../Magento/Customer/Block/Widget/Name.php | 14 +++++--- app/code/Magento/Customer/Model/Options.php | 32 +++++++++++++++++-- .../Magento/Customer/etc/adminhtml/system.xml | 4 +-- app/code/Magento/Customer/i18n/en_US.csv | 4 +-- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/Config/Model/Config/Source/Nooptreq.php b/app/code/Magento/Config/Model/Config/Source/Nooptreq.php index 03fe5ca2abccc..1c9eb801dfec7 100644 --- a/app/code/Magento/Config/Model/Config/Source/Nooptreq.php +++ b/app/code/Magento/Config/Model/Config/Source/Nooptreq.php @@ -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')] ]; } } diff --git a/app/code/Magento/Customer/Block/Widget/Name.php b/app/code/Magento/Customer/Block/Widget/Name.php index ecd09319cd85e..35f3bbefb8f00 100644 --- a/app/code/Magento/Customer/Block/Widget/Name.php +++ b/app/code/Magento/Customer/Block/Widget/Name.php @@ -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; } @@ -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; } diff --git a/app/code/Magento/Customer/Model/Options.php b/app/code/Magento/Customer/Model/Options.php index ee109dac08104..7747e309d82a6 100644 --- a/app/code/Magento/Customer/Model/Options.php +++ b/app/code/Magento/Customer/Model/Options.php @@ -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; @@ -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 + ); } /** @@ -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)) { @@ -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; } } diff --git a/app/code/Magento/Customer/etc/adminhtml/system.xml b/app/code/Magento/Customer/etc/adminhtml/system.xml index daf9240677588..46d7f589022b8 100644 --- a/app/code/Magento/Customer/etc/adminhtml/system.xml +++ b/app/code/Magento/Customer/etc/adminhtml/system.xml @@ -209,7 +209,7 @@ - Put semicolon in the beginning for empty first option.
Leave empty for open text field.]]> + Leave empty for open text field.]]>
@@ -227,7 +227,7 @@ - Put semicolon in the beginning for empty first option.
Leave empty for open text field.]]> + Leave empty for open text field.]]>
diff --git a/app/code/Magento/Customer/i18n/en_US.csv b/app/code/Magento/Customer/i18n/en_US.csv index 1db22ebf2d93a..5d7d8b2bf30a4 100644 --- a/app/code/Magento/Customer/i18n/en_US.csv +++ b/app/code/Magento/Customer/i18n/en_US.csv @@ -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.
Put semicolon in the beginning for empty first option.
Leave empty for open text field. + Semicolon (;) separated values.
Leave empty for open text field. "," - Semicolon (;) separated values.
Put semicolon in the beginning for empty first option.
Leave empty for open text field. + Semicolon (;) separated values.
Leave empty for open text field. " "Show Middle Name (initial)","Show Middle Name (initial)" "Always optional.","Always optional."