Skip to content

Commit 1ef000c

Browse files
committed
MC-42903: GraphQL returns empty address if optional telephone is set as empty string
1 parent 2c94da6 commit 1ef000c

File tree

1 file changed

+40
-13
lines changed
  • app/code/Magento/Customer/Model/Config/Backend/Show

1 file changed

+40
-13
lines changed

app/code/Magento/Customer/Model/Config/Backend/Show/Customer.php

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Customer\Model\Config\Backend\Show;
77

88
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
910

1011
/**
1112
* Customer Show Customer Model
@@ -24,6 +25,21 @@ class Customer extends \Magento\Framework\App\Config\Value
2425
*/
2526
protected $storeManager;
2627

28+
/**
29+
* @var string
30+
*/
31+
private $telephoneShowDefaultValue = 'req';
32+
33+
/**
34+
* @var array
35+
*/
36+
private $valueConfig = [
37+
'' => ['is_required' => 0, 'is_visible' => 0],
38+
'opt' => ['is_required' => 0, 'is_visible' => 1],
39+
'1' => ['is_required' => 0, 'is_visible' => 1],
40+
'req' => ['is_required' => 1, 'is_visible' => 1],
41+
];
42+
2743
/**
2844
* @param \Magento\Framework\Model\Context $context
2945
* @param \Magento\Framework\Registry $registry
@@ -80,20 +96,8 @@ public function afterSave()
8096
{
8197
$result = parent::afterSave();
8298

83-
$valueConfig = [
84-
'' => ['is_required' => 0, 'is_visible' => 0],
85-
'opt' => ['is_required' => 0, 'is_visible' => 1],
86-
'1' => ['is_required' => 0, 'is_visible' => 1],
87-
'req' => ['is_required' => 1, 'is_visible' => 1],
88-
];
89-
9099
$value = $this->getValue();
91-
if (isset($valueConfig[$value])) {
92-
$data = $valueConfig[$value];
93-
} else {
94-
$data = $valueConfig[''];
95-
}
96-
100+
$data = $this->getValueConfig($value);
97101
if ($this->getScope() == 'websites') {
98102
$website = $this->storeManager->getWebsite($this->getScopeCode());
99103
$dataFieldPrefix = 'scope_';
@@ -133,8 +137,31 @@ public function afterDelete()
133137
$attributeObject->setData('scope_is_visible', null);
134138
$attributeObject->save();
135139
}
140+
} else if ($this->getScope() == ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
141+
$valueConfig = $this->getValueConfig($this->telephoneShowDefaultValue);
142+
foreach ($this->_getAttributeObjects() as $attributeObject) {
143+
$attributeObject->setData('is_required', $valueConfig['is_required']);
144+
$attributeObject->setData('is_visible', $valueConfig['is_visible']);
145+
$attributeObject->save();
146+
}
136147
}
137148

138149
return $result;
139150
}
151+
152+
/**
153+
* Get value config
154+
*
155+
* @param string|int $value
156+
* @return array
157+
*/
158+
private function getValueConfig($value): array
159+
{
160+
if (isset($this->valueConfig[$value])) {
161+
$config = $this->valueConfig[$value];
162+
} else {
163+
$config = $this->valueConfig[''];
164+
}
165+
return $config;
166+
}
140167
}

0 commit comments

Comments
 (0)