From 6bf365feaf2186b8b9e4108e3e16921723b9d282 Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Tue, 13 Jun 2017 11:37:57 +0600 Subject: [PATCH 1/5] Fix #9924, prefill prefix and suffix in checkout shipping address --- .../Checkout/Block/Checkout/AttributeMerger.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php index a2880c28844ac..01a1df671a47e 100644 --- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php +++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php @@ -316,6 +316,11 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi protected function getDefaultValue($attributeCode) { switch ($attributeCode) { + case 'prefix': + if ($this->getCustomer()) { + return $this->getCustomer()->getPrefix(); + } + break; case 'firstname': if ($this->getCustomer()) { return $this->getCustomer()->getFirstname(); @@ -326,6 +331,11 @@ protected function getDefaultValue($attributeCode) return $this->getCustomer()->getLastname(); } break; + case 'suffix': + if ($this->getCustomer()) { + return $this->getCustomer()->getSuffix(); + } + break; case 'country_id': return $this->directoryHelper->getDefaultCountry(); } From 8b8c2fe49511e54efe401dba5a5e4d819253d075 Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Tue, 13 Jun 2017 18:27:41 +0600 Subject: [PATCH 2/5] Simplify the getDefaultValue method in an attempt to pass PHP Mess Detection checks --- .../Block/Checkout/AttributeMerger.php | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php index 01a1df671a47e..47e9a3ac7b7bf 100644 --- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php +++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php @@ -317,29 +317,18 @@ protected function getDefaultValue($attributeCode) { switch ($attributeCode) { case 'prefix': - if ($this->getCustomer()) { - return $this->getCustomer()->getPrefix(); - } - break; + return $this->getCustomer() ? $this->getCustomer()->getPrefix() : null; case 'firstname': - if ($this->getCustomer()) { - return $this->getCustomer()->getFirstname(); - } - break; + return $this->getCustomer() ? $this->getCustomer()->getFirstname() : null; case 'lastname': - if ($this->getCustomer()) { - return $this->getCustomer()->getLastname(); - } - break; + return $this->getCustomer() ? $this->getCustomer()->getLastname() : null; case 'suffix': - if ($this->getCustomer()) { - return $this->getCustomer()->getSuffix(); - } - break; + return $this->getCustomer() ? $this->getCustomer()->getSuffix() : null; case 'country_id': return $this->directoryHelper->getDefaultCountry(); + default: + return null; } - return null; } /** From ff2319eab22cb5bfe887cf8d5da91641253ec46e Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Tue, 13 Jun 2017 19:32:17 +0600 Subject: [PATCH 3/5] Bring cyclomatic complexity down from 10 to 6 --- .../Block/Checkout/AttributeMerger.php | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php index 47e9a3ac7b7bf..3a2e11d9a2ed0 100644 --- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php +++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php @@ -317,13 +317,13 @@ protected function getDefaultValue($attributeCode) { switch ($attributeCode) { case 'prefix': - return $this->getCustomer() ? $this->getCustomer()->getPrefix() : null; + return $this->getDefaultPrefix(); case 'firstname': - return $this->getCustomer() ? $this->getCustomer()->getFirstname() : null; + return $this->getDefaultFirstname(); case 'lastname': - return $this->getCustomer() ? $this->getCustomer()->getLastname() : null; + return $this->getDefaultLastname(); case 'suffix': - return $this->getCustomer() ? $this->getCustomer()->getSuffix() : null; + return $this->getDefaultSuffix(); case 'country_id': return $this->directoryHelper->getDefaultCountry(); default: @@ -387,4 +387,36 @@ protected function orderCountryOptions(array $countryOptions) } return array_merge($headOptions, $tailOptions); } + + /** + * @return null|string + */ + protected function getDefaultPrefix() + { + return $this->getCustomer() ? $this->getCustomer()->getPrefix() : null; + } + + /** + * @return null|string + */ + protected function getDefaultFirstname() + { + return $this->getCustomer() ? $this->getCustomer()->getFirstname() : null; + } + + /** + * @return null|string + */ + protected function getDefaultLastname() + { + return $this->getCustomer() ? $this->getCustomer()->getLastname() : null; + } + + /** + * @return null|string + */ + protected function getDefaultSuffix() + { + return $this->getCustomer() ? $this->getCustomer()->getSuffix() : null; + } } From 95b16840004d923272bec62ceaf3485d84143348 Mon Sep 17 00:00:00 2001 From: Anton Evers Date: Tue, 13 Jun 2017 21:36:57 +0600 Subject: [PATCH 4/5] Bring cyclomatic complexity down from 6 to 4 --- .../Block/Checkout/AttributeMerger.php | 55 ++++--------------- 1 file changed, 10 insertions(+), 45 deletions(-) diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php index 3a2e11d9a2ed0..63eed9762d580 100644 --- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php +++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php @@ -315,20 +315,17 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi */ protected function getDefaultValue($attributeCode) { - switch ($attributeCode) { - case 'prefix': - return $this->getDefaultPrefix(); - case 'firstname': - return $this->getDefaultFirstname(); - case 'lastname': - return $this->getDefaultLastname(); - case 'suffix': - return $this->getDefaultSuffix(); - case 'country_id': - return $this->directoryHelper->getDefaultCountry(); - default: - return null; + if ($attributeCode === 'country_id') { + return $this->directoryHelper->getDefaultCountry(); + } + if (!$this->getCustomer()) { + return null; } + if (in_array($attributeCode, ['prefix', 'firstname', 'lastname', 'suffix'])) { + $methodName = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $attributeCode))); + return $this->getCustomer()->{$methodName}(); + } + return null; } /** @@ -387,36 +384,4 @@ protected function orderCountryOptions(array $countryOptions) } return array_merge($headOptions, $tailOptions); } - - /** - * @return null|string - */ - protected function getDefaultPrefix() - { - return $this->getCustomer() ? $this->getCustomer()->getPrefix() : null; - } - - /** - * @return null|string - */ - protected function getDefaultFirstname() - { - return $this->getCustomer() ? $this->getCustomer()->getFirstname() : null; - } - - /** - * @return null|string - */ - protected function getDefaultLastname() - { - return $this->getCustomer() ? $this->getCustomer()->getLastname() : null; - } - - /** - * @return null|string - */ - protected function getDefaultSuffix() - { - return $this->getCustomer() ? $this->getCustomer()->getSuffix() : null; - } } From c0994b475d80d090ddaa9527bf998b40ab530460 Mon Sep 17 00:00:00 2001 From: Ievgen Shakhsuvarov Date: Wed, 14 Jun 2017 12:30:36 +0300 Subject: [PATCH 5/5] MAGETWO-69848: Fix #9924, prefill prefix and suffix in checkout shipping address #9925 --- .../Block/Checkout/AttributeMerger.php | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php index 63bb40867fcb3..888b7fdbd0945 100644 --- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php +++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php @@ -318,14 +318,32 @@ protected function getDefaultValue($attributeCode) if ($attributeCode === 'country_id') { return $this->directoryHelper->getDefaultCountry(); } - if (!$this->getCustomer()) { + + $customer = $this->getCustomer(); + if ($customer === null) { return null; } - if (in_array($attributeCode, ['prefix', 'firstname', 'middlename', 'lastname', 'suffix'])) { - $methodName = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $attributeCode))); - return $this->getCustomer()->{$methodName}(); + + $attributeValue = null; + switch ($attributeCode) { + case 'prefix': + $attributeValue = $customer->getPrefix(); + break; + case 'firstname': + $attributeValue = $customer->getFirstname(); + break; + case 'middlename': + $attributeValue = $customer->getMiddlename(); + break; + case 'lastname': + $attributeValue = $customer->getLastname(); + break; + case 'suffix': + $attributeValue = $customer->getSuffix(); + break; } - return null; + + return $attributeValue; } /**