Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #21692 #21752 - logic in constructor of address validator and Locale Resolver check #21693

19 changes: 10 additions & 9 deletions app/code/Magento/Sales/Model/Order/Address/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public function __construct(
$this->countryFactory = $countryFactory;
$this->eavConfig = $eavConfig ?: ObjectManager::getInstance()
->get(EavConfig::class);
}

/**
*
* @param \Magento\Sales\Model\Order\Address $address
* @return array
*/
public function validate(Address $address)
{
$warnings = [];

if ($this->isTelephoneRequired()) {
$this->required['telephone'] = 'Phone Number';
Expand All @@ -73,16 +83,7 @@ public function __construct(
if ($this->isFaxRequired()) {
$this->required['fax'] = 'Fax';
}
}

/**
*
* @param \Magento\Sales\Model\Order\Address $address
* @return array
*/
public function validate(Address $address)
{
$warnings = [];
foreach ($this->required as $code => $label) {
if (!$address->hasData($code)) {
$warnings[] = sprintf('"%s" is required. Enter and try again.', $label);
Expand Down
26 changes: 25 additions & 1 deletion lib/internal/Magento/Framework/Locale/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Magento\Framework\Locale;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\ObjectManager;

class Resolver implements ResolverInterface
{
Expand Down Expand Up @@ -52,6 +54,11 @@ class Resolver implements ResolverInterface
*/
private $defaultLocalePath;

/**
* @var DeploymentConfig
*/
private $deploymentConfig;

/**
* @param ScopeConfigInterface $scopeConfig
* @param string $defaultLocalePath
Expand Down Expand Up @@ -93,7 +100,10 @@ public function setDefaultLocale($locale)
public function getDefaultLocale()
{
if (!$this->defaultLocale) {
$locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
$locale = false;
if ($this->getDeploymentConfig()->isAvailable() && $this->getDeploymentConfig()->isDbAvailable()) {
$locale = $this->scopeConfig->getValue($this->getDefaultLocalePath(), $this->scopeType);
}
if (!$locale) {
$locale = self::DEFAULT_LOCALE;
}
Expand Down Expand Up @@ -159,4 +169,18 @@ public function revert()
}
return $result;
}

/**
* Retrieve Deployment Config
*
* @return DeploymentConfig
*/
private function getDeploymentConfig()
{
if (!$this->deploymentConfig) {
$this->deploymentConfig = ObjectManager::getInstance()->get(DeploymentConfig::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move deploymentConfig as last argument in constructor? It's not a good idea to get it through ObjectManager.

See "Adding a constructor parameter" section in https://devdocs.magento.com/guides/v2.3/contributor-guide/backward-compatible-development/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also look at failing unit tests. Please fix them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ihor-sviziev please check again now

}

return $this->deploymentConfig;
}
}