Skip to content

Commit c10bf9c

Browse files
authored
ENGCOM-4482: Fix #21692 - logic in constructor of address validator #21693
2 parents 23bfd35 + 2a3e5dd commit c10bf9c

File tree

3 files changed

+53
-22
lines changed

3 files changed

+53
-22
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ class Validator
4949

5050
/**
5151
* @param DirectoryHelper $directoryHelper
52-
* @param CountryFactory $countryFactory
53-
* @param EavConfig $eavConfig
52+
* @param CountryFactory $countryFactory
53+
* @param EavConfig $eavConfig
5454
*/
5555
public function __construct(
5656
DirectoryHelper $directoryHelper,
@@ -61,6 +61,17 @@ public function __construct(
6161
$this->countryFactory = $countryFactory;
6262
$this->eavConfig = $eavConfig ?: ObjectManager::getInstance()
6363
->get(EavConfig::class);
64+
}
65+
66+
/**
67+
* Validate address.
68+
*
69+
* @param \Magento\Sales\Model\Order\Address $address
70+
* @return array
71+
*/
72+
public function validate(Address $address)
73+
{
74+
$warnings = [];
6475

6576
if ($this->isTelephoneRequired()) {
6677
$this->required['telephone'] = 'Phone Number';
@@ -73,16 +84,7 @@ public function __construct(
7384
if ($this->isFaxRequired()) {
7485
$this->required['fax'] = 'Fax';
7586
}
76-
}
7787

78-
/**
79-
*
80-
* @param \Magento\Sales\Model\Order\Address $address
81-
* @return array
82-
*/
83-
public function validate(Address $address)
84-
{
85-
$warnings = [];
8688
foreach ($this->required as $code => $label) {
8789
if (!$address->hasData($code)) {
8890
$warnings[] = sprintf('"%s" is required. Enter and try again.', $label);
@@ -195,23 +197,32 @@ protected function isStateRequired($countryId)
195197
}
196198

197199
/**
200+
* Check whether telephone is required for address.
201+
*
198202
* @return bool
203+
* @throws \Magento\Framework\Exception\LocalizedException
199204
*/
200205
protected function isTelephoneRequired()
201206
{
202207
return ($this->eavConfig->getAttribute('customer_address', 'telephone')->getIsRequired());
203208
}
204209

205210
/**
211+
* Check whether company is required for address.
212+
*
206213
* @return bool
214+
* @throws \Magento\Framework\Exception\LocalizedException
207215
*/
208216
protected function isCompanyRequired()
209217
{
210218
return ($this->eavConfig->getAttribute('customer_address', 'company')->getIsRequired());
211219
}
212220

213221
/**
222+
* Check whether telephone is required for address.
223+
*
214224
* @return bool
225+
* @throws \Magento\Framework\Exception\LocalizedException
215226
*/
216227
protected function isFaxRequired()
217228
{

lib/internal/Magento/Framework/Locale/Format.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Framework\Locale;
77

8+
/**
9+
* Price locale format.
10+
*/
811
class Format implements \Magento\Framework\Locale\FormatInterface
912
{
1013
/**
@@ -38,7 +41,8 @@ public function __construct(
3841
}
3942

4043
/**
41-
* Returns the first found number from a string
44+
* Returns the first found number from a string.
45+
*
4246
* Parsing depends on given locale (grouping and decimal)
4347
*
4448
* Examples for input:
@@ -100,7 +104,7 @@ public function getPriceFormat($localeCode = null, $currencyCode = null)
100104
}
101105

102106
$formatter = new \NumberFormatter(
103-
$localeCode . '@currency=' . $currency->getCode(),
107+
$currency->getCode() ? $localeCode . '@currency=' . $currency->getCode() : $localeCode,
104108
\NumberFormatter::CURRENCY
105109
);
106110
$format = $formatter->getPattern();

lib/internal/Magento/Framework/Locale/Resolver.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
namespace Magento\Framework\Locale;
77

88
use Magento\Framework\App\Config\ScopeConfigInterface;
9+
use Magento\Framework\App\DeploymentConfig;
10+
use Magento\Framework\App\ObjectManager;
911

12+
/**
13+
* Manages locale config information.
14+
*/
1015
class Resolver implements ResolverInterface
1116
{
1217
/**
@@ -52,34 +57,42 @@ class Resolver implements ResolverInterface
5257
*/
5358
private $defaultLocalePath;
5459

60+
/**
61+
* @var DeploymentConfig
62+
*/
63+
private $deploymentConfig;
64+
5565
/**
5666
* @param ScopeConfigInterface $scopeConfig
5767
* @param string $defaultLocalePath
5868
* @param string $scopeType
5969
* @param mixed $locale
70+
* @param DeploymentConfig|null $deploymentConfig
6071
*/
6172
public function __construct(
6273
ScopeConfigInterface $scopeConfig,
6374
$defaultLocalePath,
6475
$scopeType,
65-
$locale = null
76+
$locale = null,
77+
DeploymentConfig $deploymentConfig = null
6678
) {
6779
$this->scopeConfig = $scopeConfig;
6880
$this->defaultLocalePath = $defaultLocalePath;
6981
$this->scopeType = $scopeType;
82+
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->create(DeploymentConfig::class);
7083
$this->setLocale($locale);
7184
}
7285

7386
/**
74-
* {@inheritdoc}
87+
* @inheritdoc
7588
*/
7689
public function getDefaultLocalePath()
7790
{
7891
return $this->defaultLocalePath;
7992
}
8093

8194
/**
82-
* {@inheritdoc}
95+
* @inheritdoc
8396
*/
8497
public function setDefaultLocale($locale)
8598
{
@@ -88,12 +101,15 @@ public function setDefaultLocale($locale)
88101
}
89102

90103
/**
91-
* {@inheritdoc}
104+
* @inheritdoc
92105
*/
93106
public function getDefaultLocale()
94107
{
95108
if (!$this->defaultLocale) {
96-
$locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
109+
$locale = false;
110+
if ($this->deploymentConfig->isAvailable() && $this->deploymentConfig->isDbAvailable()) {
111+
$locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
112+
}
97113
if (!$locale) {
98114
$locale = self::DEFAULT_LOCALE;
99115
}
@@ -103,7 +119,7 @@ public function getDefaultLocale()
103119
}
104120

105121
/**
106-
* {@inheritdoc}
122+
* @inheritdoc
107123
*/
108124
public function setLocale($locale = null)
109125
{
@@ -116,7 +132,7 @@ public function setLocale($locale = null)
116132
}
117133

118134
/**
119-
* {@inheritdoc}
135+
* @inheritdoc
120136
*/
121137
public function getLocale()
122138
{
@@ -127,7 +143,7 @@ public function getLocale()
127143
}
128144

129145
/**
130-
* {@inheritdoc}
146+
* @inheritdoc
131147
*/
132148
public function emulate($scopeId)
133149
{
@@ -147,7 +163,7 @@ public function emulate($scopeId)
147163
}
148164

149165
/**
150-
* {@inheritdoc}
166+
* @inheritdoc
151167
*/
152168
public function revert()
153169
{

0 commit comments

Comments
 (0)