Skip to content

Commit b2d5f02

Browse files
Merge branch 'MAGETWO-91725' of https://github.com/magento-epam/magento2ce into MAGETWO-91725
2 parents 6481cec + 9c19879 commit b2d5f02

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

app/code/Magento/Customer/Model/Metadata/CustomerMetadata.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,30 @@ class CustomerMetadata implements CustomerMetadataInterface
3333
*/
3434
private $attributeMetadataDataProvider;
3535

36+
/**
37+
* List of system attributes which should be available to the clients.
38+
*
39+
* @var string[]
40+
*/
41+
private $systemAttributes;
42+
3643
/**
3744
* @param AttributeMetadataConverter $attributeMetadataConverter
3845
* @param AttributeMetadataDataProvider $attributeMetadataDataProvider
46+
* @param string[] $systemAttributes
3947
*/
4048
public function __construct(
4149
AttributeMetadataConverter $attributeMetadataConverter,
42-
AttributeMetadataDataProvider $attributeMetadataDataProvider
50+
AttributeMetadataDataProvider $attributeMetadataDataProvider,
51+
array $systemAttributes = []
4352
) {
4453
$this->attributeMetadataConverter = $attributeMetadataConverter;
4554
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
55+
$this->systemAttributes = $systemAttributes;
4656
}
4757

4858
/**
49-
* {@inheritdoc}
59+
* @inheritdoc
5060
*/
5161
public function getAttributes($formCode)
5262
{
@@ -67,7 +77,7 @@ public function getAttributes($formCode)
6777
}
6878

6979
/**
70-
* {@inheritdoc}
80+
* @inheritdoc
7181
*/
7282
public function getAttributeMetadata($attributeCode)
7383
{
@@ -92,7 +102,7 @@ public function getAttributeMetadata($attributeCode)
92102
}
93103

94104
/**
95-
* {@inheritdoc}
105+
* @inheritdoc
96106
*/
97107
public function getAllAttributesMetadata()
98108
{
@@ -116,7 +126,7 @@ public function getAllAttributesMetadata()
116126
}
117127

118128
/**
119-
* {@inheritdoc}
129+
* @inheritdoc
120130
*/
121131
public function getCustomAttributesMetadata($dataObjectClassName = self::DATA_INTERFACE_NAME)
122132
{
@@ -134,9 +144,10 @@ public function getCustomAttributesMetadata($dataObjectClassName = self::DATA_IN
134144
$isDataObjectMethod = isset($this->customerDataObjectMethods['get' . $camelCaseKey])
135145
|| isset($this->customerDataObjectMethods['is' . $camelCaseKey]);
136146

137-
/** Even though disable_auto_group_change is system attribute, it should be available to the clients */
138147
if (!$isDataObjectMethod
139-
&& (!$attributeMetadata->isSystem() || $attributeCode == 'disable_auto_group_change')
148+
&& (!$attributeMetadata->isSystem()
149+
|| in_array($attributeCode, $this->systemAttributes)
150+
)
140151
) {
141152
$customAttributes[] = $attributeMetadata;
142153
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@
127127
<argument name="groupManagement" xsi:type="object">Magento\Customer\Api\GroupManagementInterface\Proxy</argument>
128128
</arguments>
129129
</type>
130+
<type name="Magento\Customer\Model\Metadata\CustomerMetadata">
131+
<arguments>
132+
<argument name="systemAttributes" xsi:type="array">
133+
<item name="disable_auto_group_change" xsi:type="string">disable_auto_group_change</item>
134+
</argument>
135+
</arguments>
136+
</type>
130137
<virtualType name="SectionInvalidationConfigReader" type="Magento\Framework\Config\Reader\Filesystem">
131138
<arguments>
132139
<argument name="idAttributes" xsi:type="array">

dev/tests/integration/testsuite/Magento/Customer/Model/CustomerMetadataTest.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,23 @@ protected function setUp()
5151

5252
public function testGetCustomAttributesMetadata()
5353
{
54-
$customAttributesMetadata = $this->service->getCustomAttributesMetadata();
55-
$this->assertCount(0, $customAttributesMetadata, "Invalid number of attributes returned.");
54+
$customAttributesMetadataQty = count($this->service->getCustomAttributesMetadata()) ;
5655

5756
// Verify the consistency of getCustomerAttributeMetadata() function from the 2nd call of the same service
58-
$customAttributesMetadata1 = $this->service->getCustomAttributesMetadata();
59-
$this->assertCount(0, $customAttributesMetadata1, "Invalid number of attributes returned.");
57+
$customAttributesMetadata1Qty = count($this->service->getCustomAttributesMetadata());
58+
$this->assertEquals(
59+
$customAttributesMetadataQty,
60+
$customAttributesMetadata1Qty,
61+
"Invalid number of attributes returned."
62+
);
6063

6164
// Verify the consistency of getCustomAttributesMetadata() function from the 2nd service
62-
$customAttributesMetadata2 = $this->serviceTwo->getCustomAttributesMetadata();
63-
$this->assertCount(0, $customAttributesMetadata2, "Invalid number of attributes returned.");
65+
$customAttributesMetadata2Qty = count($this->serviceTwo->getCustomAttributesMetadata());
66+
$this->assertEquals(
67+
$customAttributesMetadataQty,
68+
$customAttributesMetadata2Qty,
69+
"Invalid number of attributes returned."
70+
);
6471
}
6572

6673
public function testGetNestedOptionsCustomerAttributesMetadata()

0 commit comments

Comments
 (0)