Skip to content

Commit 9a701f2

Browse files
🔃 [EngCom] Public Pull Requests - 2.2-develop
Accepted Public Pull Requests: - #21719: [Backport] Fix #21692 #21752 - logic in constructor of address validator and Locale Resolver check (by @Bartlomiejsz) Fixed GitHub Issues: - #21692: Incorrect constructor of Magento\Sales\Model\Order\Address\Validator (reported by @Bartlomiejsz) has been fixed in #21719 by @Bartlomiejsz in 2.2-develop branch Related commits: 1. 068eedf 2. 8a4cfa4 3. 43cc9a4 4. f77f54d 5. cece086 6. 67b1d0a
2 parents 49ca099 + cb07a58 commit 9a701f2

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-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
@@ -48,8 +48,8 @@ class Validator
4848

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

6475
if ($this->isTelephoneRequired()) {
6576
$this->required['telephone'] = 'Phone Number';
@@ -72,16 +83,7 @@ public function __construct(
7283
if ($this->isFaxRequired()) {
7384
$this->required['fax'] = 'Fax';
7485
}
75-
}
7686

77-
/**
78-
*
79-
* @param \Magento\Sales\Model\Order\Address $address
80-
* @return array
81-
*/
82-
public function validate(Address $address)
83-
{
84-
$warnings = [];
8587
foreach ($this->required as $code => $label) {
8688
if (!$address->hasData($code)) {
8789
$warnings[] = sprintf('%s is a required field', $label);
@@ -194,23 +196,32 @@ protected function isStateRequired($countryId)
194196
}
195197

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

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

212220
/**
221+
* Check whether fax is required for address.
222+
*
213223
* @return bool
224+
* @throws \Magento\Framework\Exception\LocalizedException
214225
*/
215226
protected function isFaxRequired()
216227
{

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
/**
@@ -47,34 +52,42 @@ class Resolver implements ResolverInterface
4752
*/
4853
protected $emulatedLocales = [];
4954

55+
/**
56+
* @var DeploymentConfig
57+
*/
58+
private $deploymentConfig;
59+
5060
/**
5161
* @param ScopeConfigInterface $scopeConfig
5262
* @param string $defaultLocalePath
5363
* @param string $scopeType
5464
* @param mixed $locale
65+
* @param DeploymentConfig|null $deploymentConfig
5566
*/
5667
public function __construct(
5768
ScopeConfigInterface $scopeConfig,
5869
$defaultLocalePath,
5970
$scopeType,
60-
$locale = null
71+
$locale = null,
72+
DeploymentConfig $deploymentConfig = null
6173
) {
6274
$this->scopeConfig = $scopeConfig;
6375
$this->defaultLocalePath = $defaultLocalePath;
6476
$this->scopeType = $scopeType;
77+
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->create(DeploymentConfig::class);
6578
$this->setLocale($locale);
6679
}
6780

6881
/**
69-
* {@inheritdoc}
82+
* @inheritdoc
7083
*/
7184
public function getDefaultLocalePath()
7285
{
7386
return $this->defaultLocalePath;
7487
}
7588

7689
/**
77-
* {@inheritdoc}
90+
* @inheritdoc
7891
*/
7992
public function setDefaultLocale($locale)
8093
{
@@ -83,12 +96,15 @@ public function setDefaultLocale($locale)
8396
}
8497

8598
/**
86-
* {@inheritdoc}
99+
* @inheritdoc
87100
*/
88101
public function getDefaultLocale()
89102
{
90103
if (!$this->defaultLocale) {
91-
$locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
104+
$locale = false;
105+
if ($this->deploymentConfig->isAvailable() && $this->deploymentConfig->isDbAvailable()) {
106+
$locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
107+
}
92108
if (!$locale) {
93109
$locale = self::DEFAULT_LOCALE;
94110
}
@@ -98,7 +114,7 @@ public function getDefaultLocale()
98114
}
99115

100116
/**
101-
* {@inheritdoc}
117+
* @inheritdoc
102118
*/
103119
public function setLocale($locale = null)
104120
{
@@ -111,7 +127,7 @@ public function setLocale($locale = null)
111127
}
112128

113129
/**
114-
* {@inheritdoc}
130+
* @inheritdoc
115131
*/
116132
public function getLocale()
117133
{
@@ -122,7 +138,7 @@ public function getLocale()
122138
}
123139

124140
/**
125-
* {@inheritdoc}
141+
* @inheritdoc
126142
*/
127143
public function emulate($scopeId)
128144
{
@@ -142,7 +158,7 @@ public function emulate($scopeId)
142158
}
143159

144160
/**
145-
* {@inheritdoc}
161+
* @inheritdoc
146162
*/
147163
public function revert()
148164
{

lib/internal/Magento/Framework/Locale/Test/Unit/FormatTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected function setUp()
5353

5454
/** @var \Magento\Directory\Model\CurrencyFactory|\PHPUnit_Framework_MockObject_MockObject $currencyFactory */
5555
$currencyFactory = $this->getMockBuilder(\Magento\Directory\Model\CurrencyFactory::class)
56+
->disableOriginalConstructor()
5657
->getMock();
5758

5859
$this->formatModel = new \Magento\Framework\Locale\Format(

0 commit comments

Comments
 (0)