6
6
*/
7
7
namespace Magento \Eav \Model ;
8
8
9
+ use Magento \Framework \App \ObjectManager ;
9
10
use Magento \Framework \Exception \InputException ;
10
11
use Magento \Framework \Exception \NoSuchEntityException ;
11
12
use Magento \Framework \Exception \StateException ;
12
13
14
+ /**
15
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
16
+ */
13
17
class AttributeManagement implements \Magento \Eav \Api \AttributeManagementInterface
14
18
{
15
19
/**
@@ -19,6 +23,7 @@ class AttributeManagement implements \Magento\Eav\Api\AttributeManagementInterfa
19
23
20
24
/**
21
25
* @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection
26
+ * @deprecated please use instead \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
22
27
*/
23
28
protected $ attributeCollection ;
24
29
@@ -47,6 +52,11 @@ class AttributeManagement implements \Magento\Eav\Api\AttributeManagementInterfa
47
52
*/
48
53
protected $ attributeResource ;
49
54
55
+ /**
56
+ * @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
57
+ */
58
+ private $ attributeCollectionFactory ;
59
+
50
60
/**
51
61
* @param \Magento\Eav\Api\AttributeSetRepositoryInterface $setRepository
52
62
* @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection
@@ -154,11 +164,26 @@ public function getAttributes($entityType, $attributeSetId)
154
164
if (!$ attributeSet ->getAttributeSetId () || $ attributeSet ->getEntityTypeId () != $ requiredEntityTypeId ) {
155
165
throw NoSuchEntityException::singleField ('attributeSetId ' , $ attributeSetId );
156
166
}
157
-
158
- $ attributeCollection = $ this ->attributeCollection
159
- ->setAttributeSetFilter ($ attributeSet ->getAttributeSetId ())
160
- ->load ();
167
+ /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $attributeCollection */
168
+ $ attributeCollection = $ this ->getCollectionFactory ()->create ();
169
+ $ attributeCollection ->setAttributeSetFilter ($ attributeSet ->getAttributeSetId ())->load ();
161
170
162
171
return $ attributeCollection ->getItems ();
163
172
}
173
+
174
+ /**
175
+ * Retrieve collection factory
176
+ *
177
+ * @deprecated
178
+ * @return \Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory
179
+ */
180
+ private function getCollectionFactory ()
181
+ {
182
+ if ($ this ->attributeCollectionFactory === null ) {
183
+ $ this ->attributeCollectionFactory = ObjectManager::getInstance ()->create (
184
+ \Magento \Eav \Model \ResourceModel \Entity \Attribute \CollectionFactory::class
185
+ );
186
+ }
187
+ return $ this ->attributeCollectionFactory ;
188
+ }
164
189
}
0 commit comments