Skip to content

Commit

Permalink
Issue 36196: Customer attribute and customer address attribute alway …
Browse files Browse the repository at this point in the history
…require when select 'Use Default' in config
  • Loading branch information
rogerdz committed Oct 4, 2022
1 parent bfd457c commit 9197c28
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/code/Magento/Customer/Model/Config/Backend/Show/Customer.php
Expand Up @@ -3,15 +3,20 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Customer\Model\Config\Backend\Show;

use Magento\Config\App\Config\Source\ModularConfigSource;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ObjectManager;

/**
* Customer Show Customer Model
*
* @author Magento Core Team <core@magentocommerce.com>
* @SuppressWarnings(PHPMD.UnusedPrivateField)
*/
class Customer extends \Magento\Framework\App\Config\Value
{
Expand All @@ -30,6 +35,11 @@ class Customer extends \Magento\Framework\App\Config\Value
*/
private $telephoneShowDefaultValue = 'req';

/**
* @var ModularConfigSource
*/
private $configSource;

/**
* @var array
*/
Expand All @@ -50,6 +60,8 @@ class Customer extends \Magento\Framework\App\Config\Value
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param ModularConfigSource|null $configSource
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Framework\Model\Context $context,
Expand All @@ -60,11 +72,13 @@ public function __construct(
\Magento\Eav\Model\Config $eavConfig,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
ModularConfigSource $configSource = null
) {
$this->_eavConfig = $eavConfig;
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
$this->storeManager = $storeManager;
$this->configSource = $configSource ?: ObjectManager::getInstance()->get(ModularConfigSource::class);
}

/**
Expand Down Expand Up @@ -138,7 +152,8 @@ public function afterDelete()
$attributeObject->save();
}
} elseif ($this->getScope() == ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
$valueConfig = $this->getValueConfig($this->telephoneShowDefaultValue);
$defaulValue = $this->configSource->get(ScopeConfigInterface::SCOPE_TYPE_DEFAULT . '/' . $this->getPath());
$valueConfig = $this->getValueConfig($defaulValue === [] ? '' : $defaulValue);
foreach ($this->_getAttributeObjects() as $attributeObject) {
$attributeObject->setData('is_required', $valueConfig['is_required']);
$attributeObject->setData('is_visible', $valueConfig['is_visible']);
Expand Down

0 comments on commit 9197c28

Please sign in to comment.