Skip to content

Commit 4b88933

Browse files
Merge branch '2.4-develop' into ACPT-943
2 parents 581a16a + 0b16f58 commit 4b88933

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

app/code/Magento/CustomerGraphQl/Model/Customer/GetAttributesForm.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public function execute(string $formCode): ?array
4242
{
4343
$attributes = [];
4444
foreach ($this->entity->getAttributes($formCode) as $attribute) {
45+
// region_id and country_id returns large datasets that is also not related between each other and
46+
// not filterable. DirectoryGraphQl contains queries that allow to retrieve this information in a
47+
// meaningful way
48+
if ($attribute->getAttributeCode() === 'region_id' || $attribute->getAttributeCode() === 'country_id') {
49+
continue;
50+
}
4551
$attributes[] = ['entity_type' => $this->type, 'attribute_code' => $attribute->getAttributeCode()];
4652
}
4753
return $attributes;

app/code/Magento/EavGraphQl/Model/Output/GetAttributeData.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function execute(
7070
*
7171
* @param AttributeInterface $attribute
7272
* @return string
73+
* @throws RuntimeException
7374
*/
7475
private function getFrontendInput(AttributeInterface $attribute): string
7576
{
@@ -108,12 +109,28 @@ function (AttributeOptionInterface $option) use ($attribute) {
108109
return [
109110
'label' => $label,
110111
'value' => $value,
111-
'is_default' => $attribute->getDefaultValue() ?
112-
in_array($value, explode(',', $attribute->getDefaultValue())) : null
112+
'is_default' => $attribute->getDefaultValue() &&
113+
$this->isDefault($value, $attribute->getDefaultValue())
113114
];
114115
},
115116
$attribute->getOptions()
116117
)
117118
);
118119
}
120+
121+
/**
122+
* Returns true if $value is the default value. Otherwise, false.
123+
*
124+
* @param mixed $value
125+
* @param mixed $defaultValue
126+
* @return bool
127+
*/
128+
private function isDefault(mixed $value, mixed $defaultValue): bool
129+
{
130+
if (is_array($defaultValue)) {
131+
return in_array($value, $defaultValue);
132+
}
133+
134+
return in_array($value, explode(',', $defaultValue));
135+
}
119136
}

app/code/Magento/EavGraphQl/etc/schema.graphqls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type Query {
1111
customAttributeMetadataV2(attributes: [AttributeInput!]): AttributesMetadataOutput! @resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesMetadata") @doc(description: "Retrieve EAV attributes metadata.") @cache(cacheIdentity: "Magento\\EavGraphQl\\Model\\Resolver\\Cache\\CustomAttributeMetadataV2Identity")
1212
attributesForm(formCode: String! @doc(description: "Form code.")): AttributesFormOutput!
1313
@resolver(class: "Magento\\EavGraphQl\\Model\\Resolver\\AttributesForm")
14-
@doc(description: "Retrieve EAV attributes associated to a frontend form.")
14+
@doc(description: "Retrieve EAV attributes associated to a frontend form. For region_id and country_id attributes information use DirectoryGraphQl module.")
1515
@cache(cacheIdentity: "Magento\\Eav\\Model\\Cache\\AttributesFormIdentity")
1616
attributesList(
1717
entityType: AttributeEntityTypeEnum! @doc(description: "Entity type.")
@@ -91,7 +91,7 @@ interface CustomAttributeMetadataInterface @typeResolver(class: "Magento\\EavGra
9191
interface CustomAttributeOptionInterface @typeResolver(class: "Magento\\EavGraphQl\\Model\\TypeResolver\\AttributeOption") {
9292
label: String! @doc(description: "The label assigned to the attribute option.")
9393
value: String! @doc(description: "The attribute option value.")
94-
is_default: Boolean @doc(description: "Is the option value default.")
94+
is_default: Boolean! @doc(description: "Is the option value default.")
9595
}
9696

9797
type AttributeOptionMetadata implements CustomAttributeOptionInterface @doc(description: "Base EAV implementation of CustomAttributeOptionInterface.") {

dev/tests/api-functional/testsuite/Magento/GraphQl/Customer/Attribute/AttributesFormTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public function testAttributesForm(): void
8787
}
8888
$this->assertNotContains($attribute2->getAttributeCode(), $item);
8989
$this->assertNotContains($attribute3->getAttributeCode(), $item);
90+
$this->assertNotContains('region_id', $item);
91+
$this->assertNotContains('country_id', $item);
9092
}
9193
$this->fail(sprintf("Attribute '%s' not found in query response", $attribute1->getAttributeCode()));
9294
}

0 commit comments

Comments
 (0)