|
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 | *
|
@@ -1503,7 +1514,7 @@ public function getItemById($itemId)
|
1503 | 1514 | * Get item by quote item id
|
1504 | 1515 | *
|
1505 | 1516 | * @param mixed $quoteItemId
|
1506 |
| - * @return \Magento\Framework\DataObject|null |
| 1517 | + * @return \Magento\Framework\DataObject|null |
1507 | 1518 | */
|
1508 | 1519 | public function getItemByQuoteItemId($quoteItemId)
|
1509 | 1520 | {
|
@@ -1967,11 +1978,23 @@ public function getRelatedObjects()
|
1967 | 1978 | */
|
1968 | 1979 | public function getCustomerName()
|
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'); |
1974 | 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(); |
| 1996 | + } |
| 1997 | + |
1975 | 1998 | return $customerName;
|
1976 | 1999 | }
|
1977 | 2000 |
|
@@ -4534,5 +4557,48 @@ public function setShippingMethod($shippingMethod)
|
4534 | 4557 | return $this->setData('shipping_method', $shippingMethod);
|
4535 | 4558 | }
|
4536 | 4559 |
|
| 4560 | + /** |
| 4561 | + * Is visible customer middlename |
| 4562 | + * |
| 4563 | + * @return bool |
| 4564 | + */ |
| 4565 | + private function isVisibleCustomerMiddlename(): bool |
| 4566 | + { |
| 4567 | + return $this->scopeConfig->isSetFlag( |
| 4568 | + 'customer/address/middlename_show', |
| 4569 | + ScopeInterface::SCOPE_STORE |
| 4570 | + ); |
| 4571 | + } |
| 4572 | + |
| 4573 | + /** |
| 4574 | + * Is visible customer prefix |
| 4575 | + * |
| 4576 | + * @return bool |
| 4577 | + */ |
| 4578 | + private function isVisibleCustomerPrefix(): bool |
| 4579 | + { |
| 4580 | + $prefixShowValue = $this->scopeConfig->getValue( |
| 4581 | + 'customer/address/prefix_show', |
| 4582 | + ScopeInterface::SCOPE_STORE |
| 4583 | + ); |
| 4584 | + |
| 4585 | + return $prefixShowValue !== Nooptreq::VALUE_NO; |
| 4586 | + } |
| 4587 | + |
| 4588 | + /** |
| 4589 | + * Is visible customer suffix |
| 4590 | + * |
| 4591 | + * @return bool |
| 4592 | + */ |
| 4593 | + private function isVisibleCustomerSuffix(): bool |
| 4594 | + { |
| 4595 | + $prefixShowValue = $this->scopeConfig->getValue( |
| 4596 | + 'customer/address/suffix_show', |
| 4597 | + ScopeInterface::SCOPE_STORE |
| 4598 | + ); |
| 4599 | + |
| 4600 | + return $prefixShowValue !== Nooptreq::VALUE_NO; |
| 4601 | + } |
| 4602 | + |
4537 | 4603 | //@codeCoverageIgnoreEnd
|
4538 | 4604 | }
|
0 commit comments