Skip to content

Commit 02eb60c

Browse files
committed
AC-15074: Show prefix/suffix setting ignored when set to No
1 parent b9f5d6f commit 02eb60c

File tree

2 files changed

+104
-4
lines changed

2 files changed

+104
-4
lines changed

app/code/Magento/Sales/Model/Order.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4703,12 +4703,12 @@ private function isVisibleCustomerMiddlename(): bool
47034703
*/
47044704
private function isVisibleCustomerPrefix(): bool
47054705
{
4706-
$prefixShowValue = $this->scopeConfig->getValue(
4706+
$value = $this->scopeConfig->getValue(
47074707
'customer/address/prefix_show',
47084708
ScopeInterface::SCOPE_STORE
47094709
);
47104710

4711-
return $prefixShowValue !== Nooptreq::VALUE_NO;
4711+
return in_array($value, [Nooptreq::VALUE_OPTIONAL, Nooptreq::VALUE_REQUIRED], true);
47124712
}
47134713

47144714
/**
@@ -4718,12 +4718,12 @@ private function isVisibleCustomerPrefix(): bool
47184718
*/
47194719
private function isVisibleCustomerSuffix(): bool
47204720
{
4721-
$prefixShowValue = $this->scopeConfig->getValue(
4721+
$value = $this->scopeConfig->getValue(
47224722
'customer/address/suffix_show',
47234723
ScopeInterface::SCOPE_STORE
47244724
);
47254725

4726-
return $prefixShowValue !== Nooptreq::VALUE_NO;
4726+
return in_array($value, [Nooptreq::VALUE_OPTIONAL, Nooptreq::VALUE_REQUIRED], true);
47274727
}
47284728

47294729
//@codeCoverageIgnoreEnd
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Sales\Model;
9+
10+
use Magento\Config\Model\Config\Source\Nooptreq;
11+
use Magento\Framework\App\Config\MutableScopeConfigInterface;
12+
use Magento\Framework\ObjectManagerInterface;
13+
use Magento\Store\Model\ScopeInterface;
14+
use Magento\TestFramework\Helper\Bootstrap;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Tests visibility of customer prefix/suffix via Order::getCustomerName(),
19+
* covering null (unset), empty string, optional and required config values.
20+
*
21+
* @magentoDbIsolation enabled
22+
*/
23+
class OrderPrefixSuffixVisibilityTest extends TestCase
24+
{
25+
private const XML_PATH_PREFIX_SHOW = 'customer/address/prefix_show';
26+
private const XML_PATH_SUFFIX_SHOW = 'customer/address/suffix_show';
27+
28+
private ObjectManagerInterface $om;
29+
30+
protected function setUp(): void
31+
{
32+
$this->om = Bootstrap::getObjectManager();
33+
}
34+
35+
/**
36+
* @dataProvider visibilityCases
37+
*/
38+
public function testPrefixVisibility(?string $value, bool $setValue, bool $expectedVisible): void
39+
{
40+
// Ensure suffix never interferes in this test
41+
$this->setConfig(self::XML_PATH_SUFFIX_SHOW, Nooptreq::VALUE_NO);
42+
43+
if ($setValue) {
44+
$this->setConfig(self::XML_PATH_PREFIX_SHOW, $value);
45+
}
46+
// If not set, path remains unset (null), simulating the reported case.
47+
48+
$order = $this->makeOrder('Dr', 'John', 'Doe', 'Jr'); // suffix ignored here
49+
$expected = $expectedVisible ? 'Dr John Doe' : 'John Doe';
50+
51+
$this->assertSame($expected, $order->getCustomerName());
52+
}
53+
54+
/**
55+
* @dataProvider visibilityCases
56+
*/
57+
public function testSuffixVisibility(?string $value, bool $setValue, bool $expectedVisible): void
58+
{
59+
// Ensure prefix never interferes in this test
60+
$this->setConfig(self::XML_PATH_PREFIX_SHOW, Nooptreq::VALUE_NO);
61+
62+
if ($setValue) {
63+
$this->setConfig(self::XML_PATH_SUFFIX_SHOW, $value);
64+
}
65+
// If not set, path remains unset (null), simulating the reported case.
66+
67+
$order = $this->makeOrder('Dr', 'John', 'Doe', 'Jr'); // prefix ignored here
68+
$expected = $expectedVisible ? 'John Doe Jr' : 'John Doe';
69+
70+
$this->assertSame($expected, $order->getCustomerName());
71+
}
72+
73+
public static function visibilityCases(): array
74+
{
75+
return [
76+
// value, setValue, expectedVisible
77+
'unset_null_defaults_to_no' => [null, false, false], // path not set → null
78+
'explicit_empty_string_no' => [Nooptreq::VALUE_NO, true, false], // ''
79+
'optional_visible' => [Nooptreq::VALUE_OPTIONAL, true, true], // 'opt'
80+
'required_visible' => [Nooptreq::VALUE_REQUIRED, true, true], // 'req'
81+
];
82+
}
83+
84+
private function makeOrder(string $prefix, string $first, string $last, string $suffix): Order
85+
{
86+
/** @var Order $order */
87+
$order = $this->om->create(Order::class);
88+
$order->setCustomerPrefix($prefix);
89+
$order->setCustomerFirstname($first);
90+
$order->setCustomerLastname($last);
91+
$order->setCustomerSuffix($suffix);
92+
// Middlename left null to avoid affecting formatting.
93+
return $order;
94+
}
95+
96+
private function setConfig(string $path, ?string $value, string $scope = ScopeInterface::SCOPE_STORE, string $scopeCode = 'default'): void
97+
{
98+
$this->om->get(MutableScopeConfigInterface::class)->setValue($path, $value, $scope, $scopeCode);
99+
}
100+
}

0 commit comments

Comments
 (0)