Skip to content

Commit 514c6c6

Browse files
committed
ACP2E-2300: allow in sitemap only categories and products from public shared catalog.
1 parent 858a613 commit 514c6c6

File tree

1 file changed

+20
-17
lines changed
  • app/code/Magento/Sitemap/Model/ResourceModel/Catalog

1 file changed

+20
-17
lines changed

app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Category.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
namespace Magento\Sitemap\Model\ResourceModel\Catalog;
77

88
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
9-
use Magento\Framework\DB\Select;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Event\ManagerInterface;
1011

1112
/**
1213
* Sitemap resource catalog collection model
@@ -19,7 +20,7 @@ class Category extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1920
/**
2021
* Collection Zend Db select
2122
*
22-
* @var Select
23+
* @var \Magento\Framework\DB\Select
2324
*/
2425
protected $_select;
2526

@@ -46,24 +47,32 @@ class Category extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4647
*/
4748
protected $metadataPool;
4849

50+
/**
51+
* @var ManagerInterface
52+
*/
53+
private $eventManager;
54+
4955
/**
5056
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
5157
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
5258
* @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource
5359
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
5460
* @param string $connectionName
61+
* @param ManagerInterface|null $eventManager
5562
*/
5663
public function __construct(
5764
\Magento\Framework\Model\ResourceModel\Db\Context $context,
5865
\Magento\Store\Model\StoreManagerInterface $storeManager,
5966
\Magento\Catalog\Model\ResourceModel\Category $categoryResource,
6067
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
61-
$connectionName = null
68+
$connectionName = null,
69+
ManagerInterface $eventManager = null
6270
) {
6371
$this->_storeManager = $storeManager;
6472
$this->_categoryResource = $categoryResource;
6573
parent::__construct($context, $connectionName);
6674
$this->metadataPool = $metadataPool;
75+
$this->eventManager = $eventManager ?? ObjectManager::getInstance()->get(ManagerInterface::class);
6776
}
6877

6978
/**
@@ -123,7 +132,12 @@ public function getCollection($storeId)
123132

124133
$this->_addFilter($storeId, 'is_active', 1);
125134

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);
127141
while ($row = $query->fetch()) {
128142
$category = $this->_prepareCategory($row);
129143
$categories[$category->getId()] = $category;
@@ -132,17 +146,6 @@ public function getCollection($storeId)
132146
return $categories;
133147
}
134148

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-
146149
/**
147150
* Prepare category
148151
*
@@ -167,14 +170,14 @@ protected function _prepareCategory(array $categoryRow)
167170
* @param string $attributeCode
168171
* @param mixed $value
169172
* @param string $type
170-
* @return Select|bool
173+
* @return \Magento\Framework\DB\Select|bool
171174
*/
172175
protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
173176
{
174177
$meta = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\CategoryInterface::class);
175178
$linkField = $meta->getLinkField();
176179

177-
if (!$this->_select instanceof Select) {
180+
if (!$this->_select instanceof \Magento\Framework\DB\Select) {
178181
return false;
179182
}
180183

0 commit comments

Comments
 (0)