6
6
namespace Magento \Sitemap \Model \ResourceModel \Catalog ;
7
7
8
8
use Magento \CatalogUrlRewrite \Model \CategoryUrlRewriteGenerator ;
9
- use Magento \Framework \DB \Select ;
9
+ use Magento \Framework \App \ObjectManager ;
10
+ use Magento \Framework \Event \ManagerInterface ;
10
11
11
12
/**
12
13
* Sitemap resource catalog collection model
@@ -19,7 +20,7 @@ class Category extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
19
20
/**
20
21
* Collection Zend Db select
21
22
*
22
- * @var Select
23
+ * @var \Magento\Framework\DB\ Select
23
24
*/
24
25
protected $ _select ;
25
26
@@ -46,24 +47,32 @@ class Category extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
46
47
*/
47
48
protected $ metadataPool ;
48
49
50
+ /**
51
+ * @var ManagerInterface
52
+ */
53
+ private $ eventManager ;
54
+
49
55
/**
50
56
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
51
57
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
52
58
* @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource
53
59
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
54
60
* @param string $connectionName
61
+ * @param ManagerInterface|null $eventManager
55
62
*/
56
63
public function __construct (
57
64
\Magento \Framework \Model \ResourceModel \Db \Context $ context ,
58
65
\Magento \Store \Model \StoreManagerInterface $ storeManager ,
59
66
\Magento \Catalog \Model \ResourceModel \Category $ categoryResource ,
60
67
\Magento \Framework \EntityManager \MetadataPool $ metadataPool ,
61
- $ connectionName = null
68
+ $ connectionName = null ,
69
+ ManagerInterface $ eventManager = null
62
70
) {
63
71
$ this ->_storeManager = $ storeManager ;
64
72
$ this ->_categoryResource = $ categoryResource ;
65
73
parent ::__construct ($ context , $ connectionName );
66
74
$ this ->metadataPool = $ metadataPool ;
75
+ $ this ->eventManager = $ eventManager ?? ObjectManager::getInstance ()->get (ManagerInterface::class);
67
76
}
68
77
69
78
/**
@@ -123,7 +132,12 @@ public function getCollection($storeId)
123
132
124
133
$ this ->_addFilter ($ storeId , 'is_active ' , 1 );
125
134
126
- $ query = $ connection ->query ($ this ->prepareSelectStatement ($ this ->_select ));
135
+ $ this ->eventManager ->dispatch (
136
+ 'sitemap_category_select_init ' ,
137
+ ['select ' => $ this ->_select ]
138
+ );
139
+
140
+ $ query = $ connection ->query ($ this ->_select );
127
141
while ($ row = $ query ->fetch ()) {
128
142
$ category = $ this ->_prepareCategory ($ row );
129
143
$ categories [$ category ->getId ()] = $ category ;
@@ -132,17 +146,6 @@ public function getCollection($storeId)
132
146
return $ categories ;
133
147
}
134
148
135
- /**
136
- * Allow to modify select statement with plugins
137
- *
138
- * @param Select $select
139
- * @return Select
140
- */
141
- public function prepareSelectStatement (Select $ select )
142
- {
143
- return $ select ;
144
- }
145
-
146
149
/**
147
150
* Prepare category
148
151
*
@@ -167,14 +170,14 @@ protected function _prepareCategory(array $categoryRow)
167
170
* @param string $attributeCode
168
171
* @param mixed $value
169
172
* @param string $type
170
- * @return Select|bool
173
+ * @return \Magento\Framework\DB\ Select|bool
171
174
*/
172
175
protected function _addFilter ($ storeId , $ attributeCode , $ value , $ type = '= ' )
173
176
{
174
177
$ meta = $ this ->metadataPool ->getMetadata (\Magento \Catalog \Api \Data \CategoryInterface::class);
175
178
$ linkField = $ meta ->getLinkField ();
176
179
177
- if (!$ this ->_select instanceof Select) {
180
+ if (!$ this ->_select instanceof \ Magento \ Framework \ DB \ Select) {
178
181
return false ;
179
182
}
180
183
0 commit comments