diff --git a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php index dcfe1cd5e2038..63bb40867fcb3 100644 --- a/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php +++ b/app/code/Magento/Checkout/Block/Checkout/AttributeMerger.php @@ -315,24 +315,15 @@ protected function getMultilineFieldConfig($attributeCode, array $attributeConfi */ protected function getDefaultValue($attributeCode) { - switch ($attributeCode) { - case 'firstname': - if ($this->getCustomer()) { - return $this->getCustomer()->getFirstname(); - } - break; - case 'middlename': - if ($this->getCustomer()) { - return $this->getCustomer()->getMiddlename(); - } - break; - case 'lastname': - if ($this->getCustomer()) { - return $this->getCustomer()->getLastname(); - } - break; - case 'country_id': - return $this->directoryHelper->getDefaultCountry(); + if ($attributeCode === 'country_id') { + return $this->directoryHelper->getDefaultCountry(); + } + if (!$this->getCustomer()) { + return null; + } + if (in_array($attributeCode, ['prefix', 'firstname', 'middlename', 'lastname', 'suffix'])) { + $methodName = 'get' . str_replace(' ', '', ucwords(str_replace('_', ' ', $attributeCode))); + return $this->getCustomer()->{$methodName}(); } return null; }