|
5 | 5 | */
|
6 | 6 | namespace Magento\Sales\Model;
|
7 | 7 |
|
| 8 | +use Magento\Config\Model\Config\Source\Nooptreq; |
8 | 9 | use Magento\Directory\Model\Currency;
|
9 | 10 | use Magento\Framework\Api\AttributeValueFactory;
|
| 11 | +use Magento\Framework\Api\SearchCriteriaBuilder; |
| 12 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
10 | 13 | use Magento\Framework\App\ObjectManager;
|
11 | 14 | use Magento\Framework\Exception\LocalizedException;
|
12 | 15 | use Magento\Framework\Locale\ResolverInterface;
|
13 | 16 | use Magento\Framework\Pricing\PriceCurrencyInterface;
|
14 | 17 | use Magento\Sales\Api\Data\OrderInterface;
|
15 | 18 | use Magento\Sales\Api\Data\OrderItemInterface;
|
16 | 19 | use Magento\Sales\Api\Data\OrderStatusHistoryInterface;
|
| 20 | +use Magento\Sales\Api\OrderItemRepositoryInterface; |
17 | 21 | use Magento\Sales\Model\Order\Payment;
|
18 | 22 | use Magento\Sales\Model\Order\ProductOption;
|
19 | 23 | use Magento\Sales\Model\ResourceModel\Order\Address\Collection;
|
|
24 | 28 | use Magento\Sales\Model\ResourceModel\Order\Shipment\Collection as ShipmentCollection;
|
25 | 29 | use Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection as TrackCollection;
|
26 | 30 | use Magento\Sales\Model\ResourceModel\Order\Status\History\Collection as HistoryCollection;
|
27 |
| -use Magento\Sales\Api\OrderItemRepositoryInterface; |
28 |
| -use Magento\Framework\Api\SearchCriteriaBuilder; |
| 31 | +use Magento\Store\Model\ScopeInterface; |
29 | 32 |
|
30 | 33 | /**
|
31 | 34 | * Order model
|
@@ -299,6 +302,11 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
|
299 | 302 | */
|
300 | 303 | private $searchCriteriaBuilder;
|
301 | 304 |
|
| 305 | + /** |
| 306 | + * @var ScopeConfigInterface; |
| 307 | + */ |
| 308 | + private $scopeConfig; |
| 309 | + |
302 | 310 | /**
|
303 | 311 | * @param \Magento\Framework\Model\Context $context
|
304 | 312 | * @param \Magento\Framework\Registry $registry
|
@@ -331,6 +339,7 @@ class Order extends AbstractModel implements EntityInterface, OrderInterface
|
331 | 339 | * @param ProductOption|null $productOption
|
332 | 340 | * @param OrderItemRepositoryInterface $itemRepository
|
333 | 341 | * @param SearchCriteriaBuilder $searchCriteriaBuilder
|
| 342 | + * @param ScopeConfigInterface $scopeConfig |
334 | 343 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
335 | 344 | */
|
336 | 345 | public function __construct(
|
@@ -364,7 +373,8 @@ public function __construct(
|
364 | 373 | ResolverInterface $localeResolver = null,
|
365 | 374 | ProductOption $productOption = null,
|
366 | 375 | OrderItemRepositoryInterface $itemRepository = null,
|
367 |
| - SearchCriteriaBuilder $searchCriteriaBuilder = null |
| 376 | + SearchCriteriaBuilder $searchCriteriaBuilder = null, |
| 377 | + ScopeConfigInterface $scopeConfig = null |
368 | 378 | ) {
|
369 | 379 | $this->_storeManager = $storeManager;
|
370 | 380 | $this->_orderConfig = $orderConfig;
|
@@ -392,6 +402,7 @@ public function __construct(
|
392 | 402 | ->get(OrderItemRepositoryInterface::class);
|
393 | 403 | $this->searchCriteriaBuilder = $searchCriteriaBuilder ?: ObjectManager::getInstance()
|
394 | 404 | ->get(SearchCriteriaBuilder::class);
|
| 405 | + $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); |
395 | 406 |
|
396 | 407 | parent::__construct(
|
397 | 408 | $context,
|
@@ -1111,7 +1122,7 @@ public function addStatusHistoryComment($comment, $status = false)
|
1111 | 1122 | {
|
1112 | 1123 | return $this->addCommentToStatusHistory($comment, $status, false);
|
1113 | 1124 | }
|
1114 |
| - |
| 1125 | + |
1115 | 1126 | /**
|
1116 | 1127 | * Add a comment to order status history.
|
1117 | 1128 | *
|
@@ -1965,16 +1976,71 @@ public function getRelatedObjects()
|
1965 | 1976 | *
|
1966 | 1977 | * @return string
|
1967 | 1978 | */
|
1968 |
| - public function getCustomerName() |
| 1979 | + public function getCustomerName(): string |
1969 | 1980 | {
|
1970 |
| - if ($this->getCustomerFirstname()) { |
1971 |
| - $customerName = $this->getCustomerFirstname() . ' ' . $this->getCustomerLastname(); |
1972 |
| - } else { |
1973 |
| - $customerName = (string)__('Guest'); |
| 1981 | + if (null === $this->getCustomerFirstname()) { |
| 1982 | + return (string)__('Guest'); |
| 1983 | + } |
| 1984 | + |
| 1985 | + $customerName = ''; |
| 1986 | + if ($this->isVisibleCustomerPrefix() && strlen($this->getCustomerPrefix())) { |
| 1987 | + $customerName .= $this->getCustomerPrefix() . ' '; |
| 1988 | + } |
| 1989 | + $customerName .= $this->getCustomerFirstname(); |
| 1990 | + if ($this->isVisibleCustomerMiddlename() && strlen($this->getCustomerMiddlename())) { |
| 1991 | + $customerName .= ' ' . $this->getCustomerMiddlename(); |
| 1992 | + } |
| 1993 | + $customerName .= ' ' . $this->getCustomerLastname(); |
| 1994 | + if ($this->isVisibleCustomerSuffix() && strlen($this->getCustomerSuffix())) { |
| 1995 | + $customerName .= ' ' . $this->getCustomerSuffix(); |
1974 | 1996 | }
|
| 1997 | + |
1975 | 1998 | return $customerName;
|
1976 | 1999 | }
|
1977 | 2000 |
|
| 2001 | + /** |
| 2002 | + * Is visible customer middlename |
| 2003 | + * |
| 2004 | + * @return bool |
| 2005 | + */ |
| 2006 | + private function isVisibleCustomerMiddlename(): bool |
| 2007 | + { |
| 2008 | + return $this->scopeConfig->isSetFlag( |
| 2009 | + 'customer/address/middlename_show', |
| 2010 | + ScopeInterface::SCOPE_STORE |
| 2011 | + ); |
| 2012 | + } |
| 2013 | + |
| 2014 | + /** |
| 2015 | + * Is visible customer prefix |
| 2016 | + * |
| 2017 | + * @return bool |
| 2018 | + */ |
| 2019 | + private function isVisibleCustomerPrefix(): bool |
| 2020 | + { |
| 2021 | + $prefixShowValue = $this->scopeConfig->getValue( |
| 2022 | + 'customer/address/prefix_show', |
| 2023 | + ScopeInterface::SCOPE_STORE |
| 2024 | + ); |
| 2025 | + |
| 2026 | + return $prefixShowValue !== Nooptreq::VALUE_NO; |
| 2027 | + } |
| 2028 | + |
| 2029 | + /** |
| 2030 | + * Is visible customer suffix |
| 2031 | + * |
| 2032 | + * @return bool |
| 2033 | + */ |
| 2034 | + private function isVisibleCustomerSuffix(): bool |
| 2035 | + { |
| 2036 | + $prefixShowValue = $this->scopeConfig->getValue( |
| 2037 | + 'customer/address/suffix_show', |
| 2038 | + ScopeInterface::SCOPE_STORE |
| 2039 | + ); |
| 2040 | + |
| 2041 | + return $prefixShowValue !== Nooptreq::VALUE_NO; |
| 2042 | + } |
| 2043 | + |
1978 | 2044 | /**
|
1979 | 2045 | * Add New object to related array
|
1980 | 2046 | *
|
|
0 commit comments