Skip to content

Commit 17ab022

Browse files
committed
Merge remote-tracking branch 'origin/develop' into develop
2 parents b841854 + 4d539ed commit 17ab022

File tree

17 files changed

+221
-48
lines changed

17 files changed

+221
-48
lines changed

app/code/Magento/Catalog/Model/Category/AttributeRepository.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ class AttributeRepository implements CategoryAttributeRepositoryInterface
2525
protected $eavAttributeRepository;
2626

2727
/**
28+
* @param \Magento\Framework\Api\Config\MetadataConfig $metadataConfig
2829
* @param \Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder
2930
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
3031
* @param \Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
3132
*/
3233
public function __construct(
34+
\Magento\Framework\Api\Config\MetadataConfig $metadataConfig,
3335
\Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder,
3436
\Magento\Framework\Api\FilterBuilder $filterBuilder,
3537
\Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
3638
) {
39+
$this->metadataConfig = $metadataConfig;
3740
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
3841
$this->filterBuilder = $filterBuilder;
3942
$this->eavAttributeRepository = $eavAttributeRepository;
@@ -63,7 +66,6 @@ public function get($attributeCode)
6366

6467
/**
6568
* {@inheritdoc}
66-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6769
*/
6870
public function getCustomAttributesMetadata($dataObjectClassName = null)
6971
{
@@ -76,6 +78,12 @@ public function getCustomAttributesMetadata($dataObjectClassName = null)
7678
]
7779
);
7880

79-
return $this->getList($searchCriteria->create())->getItems();
81+
$customAttributes = [];
82+
$entityAttributes = $this->getList($searchCriteria->create())->getItems();
83+
84+
foreach ($entityAttributes as $attributeMetadata) {
85+
$customAttributes[] = $attributeMetadata;
86+
}
87+
return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
8088
}
8189
}

app/code/Magento/Catalog/Model/Product/Attribute/Repository.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class Repository implements \Magento\Catalog\Api\ProductAttributeRepositoryInter
4949
*/
5050
protected $filterManager;
5151

52+
/**
53+
* @var \Magento\Framework\Api\Config\MetadataConfig
54+
*/
55+
protected $metadataConfig;
56+
5257
/**
5358
* @var \Magento\Framework\Api\SearchCriteriaDataBuilder
5459
*/
@@ -67,6 +72,7 @@ class Repository implements \Magento\Catalog\Api\ProductAttributeRepositoryInter
6772
* @param \Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository
6873
* @param \Magento\Eav\Model\Config $eavConfig
6974
* @param \Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory
75+
* @param \Magento\Framework\Api\Config\MetadataConfig $metadataConfig
7076
* @param \Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder
7177
* @param \Magento\Framework\Api\FilterBuilder $filterBuilder
7278
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -79,6 +85,7 @@ public function __construct(
7985
\Magento\Eav\Api\AttributeRepositoryInterface $eavAttributeRepository,
8086
\Magento\Eav\Model\Config $eavConfig,
8187
\Magento\Eav\Model\Adminhtml\System\Config\Source\Inputtype\ValidatorFactory $validatorFactory,
88+
\Magento\Framework\Api\Config\MetadataConfig $metadataConfig,
8289
\Magento\Framework\Api\SearchCriteriaDataBuilder $searchCriteriaBuilder,
8390
\Magento\Framework\Api\FilterBuilder $filterBuilder
8491
) {
@@ -89,6 +96,7 @@ public function __construct(
8996
$this->eavAttributeRepository = $eavAttributeRepository;
9097
$this->eavConfig = $eavConfig;
9198
$this->inputtypeValidatorFactory = $validatorFactory;
99+
$this->metadataConfig = $metadataConfig;
92100
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
93101
$this->filterBuilder = $filterBuilder;
94102
}
@@ -216,7 +224,6 @@ public function deleteById($attributeCode)
216224

217225
/**
218226
* {@inheritdoc}
219-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
220227
*/
221228
public function getCustomAttributesMetadata($dataObjectClassName = null)
222229
{
@@ -229,7 +236,13 @@ public function getCustomAttributesMetadata($dataObjectClassName = null)
229236
]
230237
);
231238

232-
return $this->getList($searchCriteria->create())->getItems();
239+
$customAttributes = [];
240+
$entityAttributes = $this->getList($searchCriteria->create())->getItems();
241+
242+
foreach ($entityAttributes as $attributeMetadata) {
243+
$customAttributes[] = $attributeMetadata;
244+
}
245+
return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
233246
}
234247

235248
/**

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Customer\Model\AttributeMetadataConverter;
1111
use Magento\Customer\Model\AttributeMetadataDataProvider;
1212
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
13+
use Magento\Framework\Api\Config\MetadataConfig;
1314
use Magento\Framework\Api\SimpleDataObjectConverter;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516

@@ -23,6 +24,11 @@ class AddressMetadata implements AddressMetadataInterface
2324
*/
2425
private $addressDataObjectMethods;
2526

27+
/**
28+
* @var MetadataConfig
29+
*/
30+
private $metadataConfig;
31+
2632
/**
2733
* @var AttributeMetadataConverter
2834
*/
@@ -34,13 +40,16 @@ class AddressMetadata implements AddressMetadataInterface
3440
private $attributeMetadataDataProvider;
3541

3642
/**
43+
* @param MetadataConfig $metadataConfig
3744
* @param AttributeMetadataConverter $attributeMetadataConverter
3845
* @param AttributeMetadataDataProvider $attributeMetadataDataProvider
3946
*/
4047
public function __construct(
48+
MetadataConfig $metadataConfig,
4149
AttributeMetadataConverter $attributeMetadataConverter,
4250
AttributeMetadataDataProvider $attributeMetadataDataProvider
4351
) {
52+
$this->metadataConfig = $metadataConfig;
4453
$this->attributeMetadataConverter = $attributeMetadataConverter;
4554
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
4655
}
@@ -118,14 +127,14 @@ public function getAllAttributesMetadata()
118127
*/
119128
public function getCustomAttributesMetadata($dataObjectClassName = AddressMetadataInterface::DATA_INTERFACE_NAME)
120129
{
130+
$customAttributes = [];
121131
if (!$this->addressDataObjectMethods) {
122132
$dataObjectMethods = array_flip(get_class_methods($dataObjectClassName));
123133
$baseClassDataObjectMethods = array_flip(
124134
get_class_methods('Magento\Framework\Api\AbstractExtensibleObject')
125135
);
126136
$this->addressDataObjectMethods = array_diff_key($dataObjectMethods, $baseClassDataObjectMethods);
127137
}
128-
$customAttributes = [];
129138
foreach ($this->getAllAttributesMetadata() as $attributeMetadata) {
130139
$attributeCode = $attributeMetadata->getAttributeCode();
131140
$camelCaseKey = SimpleDataObjectConverter::snakeCaseToUpperCamelCase($attributeCode);
@@ -136,6 +145,6 @@ public function getCustomAttributesMetadata($dataObjectClassName = AddressMetada
136145
$customAttributes[] = $attributeMetadata;
137146
}
138147
}
139-
return $customAttributes;
148+
return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
140149
}
141150
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Magento\Customer\Model\AttributeMetadataConverter;
1111
use Magento\Customer\Model\AttributeMetadataDataProvider;
1212
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
13+
use Magento\Framework\Api\Config\MetadataConfig;
1314
use Magento\Framework\Api\SimpleDataObjectConverter;
1415
use Magento\Framework\Exception\NoSuchEntityException;
1516

@@ -23,6 +24,11 @@ class CustomerMetadata implements CustomerMetadataInterface
2324
*/
2425
private $customerDataObjectMethods;
2526

27+
/**
28+
* @var MetadataConfig
29+
*/
30+
private $metadataConfig;
31+
2632
/**
2733
* @var AttributeMetadataConverter
2834
*/
@@ -34,13 +40,16 @@ class CustomerMetadata implements CustomerMetadataInterface
3440
private $attributeMetadataDataProvider;
3541

3642
/**
43+
* @param MetadataConfig $metadataConfig
3744
* @param AttributeMetadataConverter $attributeMetadataConverter
3845
* @param AttributeMetadataDataProvider $attributeMetadataDataProvider
3946
*/
4047
public function __construct(
48+
MetadataConfig $metadataConfig,
4149
AttributeMetadataConverter $attributeMetadataConverter,
4250
AttributeMetadataDataProvider $attributeMetadataDataProvider
4351
) {
52+
$this->metadataConfig = $metadataConfig;
4453
$this->attributeMetadataConverter = $attributeMetadataConverter;
4554
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
4655
}
@@ -139,6 +148,6 @@ public function getCustomAttributesMetadata($dataObjectClassName = self::DATA_IN
139148
$customAttributes[] = $attributeMetadata;
140149
}
141150
}
142-
return $customAttributes;
151+
return array_merge($customAttributes, $this->metadataConfig->getCustomAttributesMetadata($dataObjectClassName));
143152
}
144153
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,26 @@
8383
</argument>
8484
</arguments>
8585
</type>
86+
<virtualType name="Magento\Customer\Api\Config\CustomerMetadataConfig" type="Magento\Framework\Api\Config\MetadataConfig">
87+
<arguments>
88+
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\Customer\Model\AttributeMetadataDataBuilder</argument>
89+
</arguments>
90+
</virtualType>
91+
<type name="Magento\Customer\Model\Metadata\CustomerMetadata">
92+
<arguments>
93+
<argument name="metadataConfig" xsi:type="object">Magento\Customer\Api\Config\CustomerMetadataConfig</argument>
94+
</arguments>
95+
</type>
96+
<virtualType name="Magento\Customer\Api\Config\AddressMetadataConfig" type="Magento\Framework\Api\Config\MetadataConfig">
97+
<arguments>
98+
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\Customer\Model\AttributeMetadataDataBuilder</argument>
99+
</arguments>
100+
</virtualType>
101+
<type name="Magento\Customer\Model\Metadata\AddressMetadata">
102+
<arguments>
103+
<argument name="metadataConfig" xsi:type="object">Magento\Customer\Api\Config\AddressMetadataConfig</argument>
104+
</arguments>
105+
</type>
86106
<type name="Magento\Framework\Model\ActionValidator\RemoveAction">
87107
<arguments>
88108
<argument name="protectedModels" xsi:type="array">

app/etc/di.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<preference for="Magento\Framework\Mview\View\ChangelogInterface" type="Magento\Framework\Mview\View\Changelog" />
8383
<preference for="Magento\Framework\View\Design\FileResolution\Fallback\CacheDataInterface" type="Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Flat"/>
8484
<preference for="Magento\Framework\Api\AttributeMetadataBuilderInterface" type="Magento\Framework\Api\AttributeMetadataBuilder"/>
85-
<preference for="Magento\Framework\Api\MetadataServiceInterface" type="Magento\Framework\Api\DefaultMetadataService"/>
85+
<preference for="Magento\Framework\Api\MetadataServiceInterface" type="Magento\Framework\Api\Config\MetadataConfig"/>
8686
<preference for="Magento\Framework\Api\SearchCriteriaInterface" type="Magento\Framework\Api\SearchCriteria"/>
8787
<preference for="Magento\Framework\App\Rss\UrlBuilderInterface" type="Magento\Framework\App\Rss\UrlBuilder"/>
8888
<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\Null"/>

dev/tests/api-functional/_files/Magento/TestModule1/etc/di.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,16 @@
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd">
99
<preference for="Magento\TestModule1\Service\V1\AllSoapAndRestInterface" type="Magento\TestModule1\Service\V1\AllSoapAndRest" />
1010
<preference for="Magento\TestModule1\Service\V2\AllSoapAndRestInterface" type="Magento\TestModule1\Service\V2\AllSoapAndRest" />
11+
12+
<virtualType name="Magento\TestModule1\Service\Config\TestModule1MetadataConfig" type="Magento\Framework\Api\Config\MetadataConfig">
13+
<arguments>
14+
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\TestModule1\Service\V1\Entity\Eav\AttributeMetadataBuilder</argument>
15+
<argument name="dataObjectClassName" xsi:type="string">Magento\TestModule1\Service\V1\Entity\Item</argument>
16+
</arguments>
17+
</virtualType>
18+
<type name="Magento\TestModule1\Service\V1\Entity\ItemBuilder">
19+
<arguments>
20+
<argument name="metadataService" xsi:type="object">Magento\TestModule1\Service\Config\TestModule1MetadataConfig</argument>
21+
</arguments>
22+
</type>
1123
</config>

dev/tests/api-functional/_files/Magento/TestModuleMSC/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,16 @@
1313
<preference for="Magento\TestModuleMSC\Api\Data\CustomAttributeDataObjectInterface" type="Magento\TestModuleMSC\Model\Data\CustomAttributeDataObject" />
1414
<preference for="Magento\TestModuleMSC\Api\Data\CustomAttributeNestedDataObjectInterface" type="Magento\TestModuleMSC\Model\Data\CustomAttributeNestedDataObject" />
1515

16+
<virtualType name="Magento\TestModuleMSC\Service\Config\TestModuleMSCMetadataConfig" type="Magento\Framework\Api\Config\MetadataConfig">
17+
<arguments>
18+
<argument name="attributeMetadataBuilder" xsi:type="object">Magento\TestModuleMSC\Model\Data\Eav\AttributeMetadataBuilder</argument>
19+
<argument name="dataObjectClassName" xsi:type="string">Magento\TestModuleMSC\Model\Data\Item</argument>
20+
</arguments>
21+
</virtualType>
1622
<type name="Magento\TestModuleMSC\Model\Data\Item">
1723
<arguments>
1824
<argument name="resource" xsi:type="object">Magento\TestModuleMSC\Model\Resource\Item</argument>
25+
<argument name="metadataService" xsi:type="object">Magento\TestModuleMSC\Service\Config\TestModuleMSCMetadataConfig</argument>
1926
</arguments>
2027
</type>
2128
<type name="Magento\TestModuleMSC\Model\Data\CustomAttributeDataObject">

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ protected function setUp()
3131
public function testGetCustomAttributesMetadata()
3232
{
3333
$customAttributesMetadata = $this->_service->getCustomAttributesMetadata();
34-
$this->assertCount(0, $customAttributesMetadata, "Invalid number of attributes returned.");
34+
$this->assertCount(2, $customAttributesMetadata, "Invalid number of attributes returned.");
35+
$configAttributeCode = 'address_attribute_1';
36+
$configAttributeFound = false;
37+
foreach ($customAttributesMetadata as $attribute) {
38+
if ($attribute->getAttributeCode() == $configAttributeCode) {
39+
$configAttributeFound = true;
40+
break;
41+
}
42+
}
43+
if (!$configAttributeFound) {
44+
$this->fail("Custom attribute declared in the config not found.");
45+
}
3546
}
3647

3748
/**
@@ -58,7 +69,7 @@ public function testGetCustomAttributesMetadataWithAttributeNamedCustomAttribute
5869
if (!$customAttributesFound) {
5970
$this->fail("Custom attributes declared in the config not found.");
6071
}
61-
$this->assertCount(2, $customAttributesMetadata, "Invalid number of attributes returned.");
72+
$this->assertCount(4, $customAttributesMetadata, "Invalid number of attributes returned.");
6273
}
6374

6475
public function testGetAddressAttributeMetadata()

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,18 @@ protected function setUp()
4747
public function testGetCustomAttributesMetadata()
4848
{
4949
$customAttributesMetadata = $this->_service->getCustomAttributesMetadata();
50-
$this->assertCount(1, $customAttributesMetadata, "Invalid number of attributes returned.");
50+
$this->assertCount(3, $customAttributesMetadata, "Invalid number of attributes returned.");
51+
$configAttributeCode = 'customer_attribute_1';
52+
$configAttributeFound = false;
53+
foreach ($customAttributesMetadata as $attribute) {
54+
if ($attribute->getAttributeCode() == $configAttributeCode) {
55+
$configAttributeFound = true;
56+
break;
57+
}
58+
}
59+
if (!$configAttributeFound) {
60+
$this->fail("Custom attribute declared in the config not found.");
61+
}
5162
}
5263

5364
public function testGetNestedOptionsCustomAttributesMetadata()
@@ -93,7 +104,7 @@ public function testGetCustomAttributesMetadataWithAttributeNamedCustomAttribute
93104
if (!$customAttributesFound) {
94105
$this->fail("Custom attributes declared in the config not found.");
95106
}
96-
$this->assertCount(3, $customAttributesMetadata, "Invalid number of attributes returned.");
107+
$this->assertCount(5, $customAttributesMetadata, "Invalid number of attributes returned.");
97108
}
98109

99110
/**

0 commit comments

Comments
 (0)