1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Helper;
use Magento\Customer\Api\CustomerNameGenerationInterface;
use Magento\Customer\Api\CustomerMetadataInterface;
use Magento\Customer\Api\Data\CustomerInterface;
/**
* Customer helper for view.
*/
class View extends \Magento\Framework\App\Helper\AbstractHelper implements CustomerNameGenerationInterface
{
/**
* @var CustomerMetadataInterface
*/
protected $_customerMetadataService;
/**
* Initialize dependencies.
*
* @param \Magento\Framework\App\Helper\Context $context
* @param CustomerMetadataInterface $customerMetadataService
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
CustomerMetadataInterface $customerMetadataService
) {
$this->_customerMetadataService = $customerMetadataService;
parent::__construct($context);
}
/**
* {@inheritdoc}
*/
public function getCustomerName(CustomerInterface $customerData)
{
$name = '';
$prefixMetadata = $this->_customerMetadataService->getAttributeMetadata('prefix');
if ($prefixMetadata->isVisible() && $customerData->getPrefix()) {
$name .= $customerData->getPrefix() . ' ';
}
$name .= $customerData->getFirstname();
$middleNameMetadata = $this->_customerMetadataService->getAttributeMetadata('middlename');
if ($middleNameMetadata->isVisible() && $customerData->getMiddlename()) {
$name .= ' ' . $customerData->getMiddlename();
}
$name .= ' ' . $customerData->getLastname();
$suffixMetadata = $this->_customerMetadataService->getAttributeMetadata('suffix');
if ($suffixMetadata->isVisible() && $customerData->getSuffix()) {
$name .= ' ' . $customerData->getSuffix();
}
return $name;
}
}