19
19
*/
20
20
class CreateHandler implements AttributeInterface
21
21
{
22
+ /** Name of ATTRIBUTE_SET_ID field */
23
+ const ATTRIBUTE_SET_ID = 'attribute_set_id ' ;
24
+
22
25
/**
23
26
* @var AttributeRepository
24
27
*/
@@ -88,21 +91,35 @@ private function getAttributeCache()
88
91
* @return \Magento\Eav\Api\Data\AttributeInterface[]
89
92
* @throws \Exception
90
93
*/
91
- protected function getAttributes ($ entityType )
94
+ protected function getAttributes ($ entityType, $ attributeSetId = null )
92
95
{
93
96
/** @var AttributeCache $cache */
94
97
$ cache = $ this ->getAttributeCache ();
95
- if ($ attributes = $ cache ->getAttributes ($ entityType )) {
98
+ $ suffix = 'attribute_set_id- ' . ($ attributeSetId ?: 'all ' );
99
+ if ($ attributes = $ cache ->getAttributes ($ entityType , $ suffix )) {
96
100
return $ attributes ;
97
101
}
98
102
99
103
$ metadata = $ this ->metadataPool ->getMetadata ($ entityType );
100
104
105
+ if ($ attributeSetId === null ) {
106
+ $ criteria = $ this ->searchCriteriaBuilder ->addFilter (self ::ATTRIBUTE_SET_ID . '' , null , 'neq ' )->create ();
107
+ } else {
108
+ $ criteria = $ this ->searchCriteriaBuilder ->addFilter (self ::ATTRIBUTE_SET_ID , $ attributeSetId )->create ();
109
+ }
110
+
101
111
$ searchResult = $ this ->attributeRepository ->getList (
102
112
$ metadata ->getEavEntityType (),
103
- $ this ->searchCriteriaBuilder ->addFilter ('attribute_set_id ' , null , 'neq ' )->create ()
113
+ $ criteria
114
+ );
115
+ $ attributes = $ searchResult ->getItems ();
116
+
117
+ $ this ->attributeCache ->saveAttributes (
118
+ $ entityType ,
119
+ $ attributes ,
120
+ $ suffix
104
121
);
105
- return $ searchResult -> getItems () ;
122
+ return $ attributes ;
106
123
}
107
124
108
125
/**
@@ -120,8 +137,9 @@ public function execute($entityType, $entityData, $arguments = [])
120
137
if ($ metadata ->getEavEntityType ()) {
121
138
$ processed = [];
122
139
$ entityLinkField = $ metadata ->getLinkField ();
140
+ $ attributeSetId = isset ($ entityData [self ::ATTRIBUTE_SET_ID ]) ? $ entityData [self ::ATTRIBUTE_SET_ID ] : null ;
123
141
/** @var \Magento\Eav\Model\Entity\Attribute\AbstractAttribute $attribute */
124
- foreach ($ this ->getAttributes ($ entityType ) as $ attribute ) {
142
+ foreach ($ this ->getAttributes ($ entityType, $ attributeSetId ) as $ attribute ) {
125
143
if ($ attribute ->isStatic ()) {
126
144
continue ;
127
145
}
0 commit comments