@@ -55,7 +55,7 @@ class Category extends AbstractResource
55
55
protected $ _isActiveAttributeId = null ;
56
56
57
57
/**
58
- * Store id
58
+ * Id of store
59
59
*
60
60
* @var int
61
61
*/
@@ -69,14 +69,14 @@ class Category extends AbstractResource
69
69
protected $ _eventManager = null ;
70
70
71
71
/**
72
- * Category collection factory
72
+ * Collection factory of category
73
73
*
74
74
* @var \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory
75
75
*/
76
76
protected $ _categoryCollectionFactory ;
77
77
78
78
/**
79
- * Category tree factory
79
+ * Tree factory of category
80
80
*
81
81
* @var \Magento\Catalog\Model\ResourceModel\Category\TreeFactory
82
82
*/
@@ -103,7 +103,6 @@ class Category extends AbstractResource
103
103
private $ metadataPool ;
104
104
105
105
/**
106
- * Category constructor.
107
106
* @param \Magento\Eav\Model\Entity\Context $context
108
107
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
109
108
* @param \Magento\Catalog\Model\Factory $modelFactory
@@ -114,6 +113,8 @@ class Category extends AbstractResource
114
113
* @param array $data
115
114
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
116
115
* @param MetadataPool|null $metadataPool
116
+ * @param EntityManager|null $entityManager
117
+ * @param Category\AggregateCount|null $aggregateCount
117
118
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
118
119
*/
119
120
public function __construct (
@@ -126,7 +127,9 @@ public function __construct(
126
127
Processor $ indexerProcessor ,
127
128
$ data = [],
128
129
\Magento \Framework \Serialize \Serializer \Json $ serializer = null ,
129
- MetadataPool $ metadataPool = null
130
+ MetadataPool $ metadataPool = null ,
131
+ \Magento \Framework \EntityManager \EntityManager $ entityManager = null ,
132
+ \Magento \Catalog \Model \ResourceModel \Category \AggregateCount $ aggregateCount = null
130
133
) {
131
134
parent ::__construct (
132
135
$ context ,
@@ -142,6 +145,10 @@ public function __construct(
142
145
$ this ->serializer = $ serializer ?: ObjectManager::getInstance ()
143
146
->get (\Magento \Framework \Serialize \Serializer \Json::class);
144
147
$ this ->metadataPool = $ metadataPool ?: ObjectManager::getInstance ()->get (MetadataPool::class);
148
+ $ this ->entityManager = $ entityManager ?: ObjectManager::getInstance ()
149
+ ->get (\Magento \Framework \EntityManager \EntityManager::class);
150
+ $ this ->aggregateCount = $ aggregateCount ?: ObjectManager::getInstance ()
151
+ ->get (\Magento \Catalog \Model \ResourceModel \Category \AggregateCount::class);
145
152
}
146
153
147
154
/**
@@ -220,7 +227,7 @@ protected function _getTree()
220
227
protected function _beforeDelete (\Magento \Framework \DataObject $ object )
221
228
{
222
229
parent ::_beforeDelete ($ object );
223
- $ this ->getAggregateCount () ->processDelete ($ object );
230
+ $ this ->aggregateCount ->processDelete ($ object );
224
231
$ this ->deleteChildren ($ object );
225
232
}
226
233
@@ -1092,8 +1099,8 @@ public function load($object, $entityId, $attributes = [])
1092
1099
}
1093
1100
1094
1101
$ this ->loadAttributesForObject ($ attributes , $ object );
1095
- $ object = $ this ->getEntityManager () ->load ($ object , $ entityId );
1096
- if (!$ this ->getEntityManager () ->has ($ object )) {
1102
+ $ object = $ this ->entityManager ->load ($ object , $ entityId );
1103
+ if (!$ this ->entityManager ->has ($ object )) {
1097
1104
$ object ->isObjectNew (true );
1098
1105
}
1099
1106
return $ this ;
@@ -1104,7 +1111,7 @@ public function load($object, $entityId, $attributes = [])
1104
1111
*/
1105
1112
public function delete ($ object )
1106
1113
{
1107
- $ this ->getEntityManager () ->delete ($ object );
1114
+ $ this ->entityManager ->delete ($ object );
1108
1115
$ this ->_eventManager ->dispatch (
1109
1116
'catalog_category_delete_after_done ' ,
1110
1117
['product ' => $ object , 'category ' => $ object ]
@@ -1121,38 +1128,10 @@ public function delete($object)
1121
1128
*/
1122
1129
public function save (\Magento \Framework \Model \AbstractModel $ object )
1123
1130
{
1124
- $ this ->getEntityManager () ->save ($ object );
1131
+ $ this ->entityManager ->save ($ object );
1125
1132
return $ this ;
1126
1133
}
1127
1134
1128
- /**
1129
- * Returns EntityManager object
1130
- *
1131
- * @return EntityManager
1132
- */
1133
- private function getEntityManager ()
1134
- {
1135
- if (null === $ this ->entityManager ) {
1136
- $ this ->entityManager = \Magento \Framework \App \ObjectManager::getInstance ()
1137
- ->get (\Magento \Framework \EntityManager \EntityManager::class);
1138
- }
1139
- return $ this ->entityManager ;
1140
- }
1141
-
1142
- /**
1143
- * Returns AggregateCount object
1144
- *
1145
- * @return Category\AggregateCount
1146
- */
1147
- private function getAggregateCount ()
1148
- {
1149
- if (null === $ this ->aggregateCount ) {
1150
- $ this ->aggregateCount = \Magento \Framework \App \ObjectManager::getInstance ()
1151
- ->get (\Magento \Catalog \Model \ResourceModel \Category \AggregateCount::class);
1152
- }
1153
- return $ this ->aggregateCount ;
1154
- }
1155
-
1156
1135
/**
1157
1136
* Get category with children.
1158
1137
*
0 commit comments