Skip to content

Commit b885a91

Browse files
committed
ACP2E-2300: addressed CR comments
1 parent d3630d6 commit b885a91

File tree

5 files changed

+156
-71
lines changed

5 files changed

+156
-71
lines changed

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

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,31 @@ class Category extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4747
protected $metadataPool;
4848

4949
/**
50-
* @var SelectWrapper
50+
* @var CategorySelectBuilder
5151
*/
52-
private $selectWrapper;
52+
private $categorySelectBuilder;
5353

5454
/**
5555
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
5656
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
5757
* @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource
5858
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
5959
* @param string $connectionName
60-
* @param SelectWrapper|null $selectWrapper
60+
* @param CategorySelectBuilder|null $categorySelectBuilder
6161
*/
6262
public function __construct(
6363
\Magento\Framework\Model\ResourceModel\Db\Context $context,
6464
\Magento\Store\Model\StoreManagerInterface $storeManager,
6565
\Magento\Catalog\Model\ResourceModel\Category $categoryResource,
6666
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
6767
$connectionName = null,
68-
SelectWrapper $selectWrapper = null
68+
CategorySelectBuilder $categorySelectBuilder = null
6969
) {
7070
$this->_storeManager = $storeManager;
7171
$this->_categoryResource = $categoryResource;
7272
parent::__construct($context, $connectionName);
7373
$this->metadataPool = $metadataPool;
74-
$this->selectWrapper = $selectWrapper ?? ObjectManager::getInstance()->get(SelectWrapper::class);
74+
$this->categorySelectBuilder = $selectWrapper ?? ObjectManager::getInstance()->get(CategorySelectBuilder::class);
7575
}
7676

7777
/**
@@ -115,25 +115,17 @@ public function getCollection($storeId)
115115
return false;
116116
}
117117

118-
$this->_select = $connection->select()->from(
119-
['e' => $this->getMainTable()],
120-
[$this->getIdFieldName(), 'updated_at']
121-
)->joinLeft(
122-
['url_rewrite' => $this->getTable('url_rewrite')],
123-
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
124-
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
125-
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', CategoryUrlRewriteGenerator::ENTITY_TYPE),
126-
['url' => 'request_path']
127-
)->where(
128-
'e.path LIKE ?',
129-
$categoryRow['path'] . '/%'
118+
$this->_select = $this->categorySelectBuilder->execute(
119+
$this->getMainTable(),
120+
$this->getIdFieldName(),
121+
$store,
122+
$categoryRow['path']
130123
);
131124

132125
$this->_addFilter($storeId, 'is_active', 1);
133126

134-
$query = $connection->query(
135-
$this->selectWrapper->getSelectStatement($this->_select)
136-
);
127+
$query = $connection->query($this->_select);
128+
137129
while ($row = $query->fetch()) {
138130
$category = $this->_prepareCategory($row);
139131
$categories[$category->getId()] = $category;
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\Sitemap\Model\ResourceModel\Catalog;
18+
19+
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
20+
use Magento\Framework\App\ResourceConnection;
21+
use Magento\Framework\DB\Select;
22+
use Magento\Store\Api\Data\StoreInterface;
23+
24+
class CategorySelectBuilder
25+
{
26+
public function __construct(
27+
private readonly ResourceConnection $resource
28+
) {
29+
30+
}
31+
32+
/**
33+
* Allow to modify a select statement with plugins
34+
*
35+
* @param string $mainTableName
36+
* @param string $idField
37+
* @param StoreInterface $store
38+
* @param string $path
39+
* @return Select
40+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
41+
*/
42+
public function execute(string $mainTableName, string $idField, StoreInterface $store, string $path)
43+
{
44+
$connection = $this->resource->getConnection();
45+
46+
return $connection->select()->from(
47+
['e' => $mainTableName],
48+
[$idField, 'updated_at']
49+
)->joinLeft(
50+
['url_rewrite' => $this->resource->getTableName('url_rewrite')],
51+
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
52+
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
53+
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', CategoryUrlRewriteGenerator::ENTITY_TYPE),
54+
['url' => 'request_path']
55+
)->where(
56+
'e.path LIKE ?',
57+
$path . '/%'
58+
);
59+
}
60+
}

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

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
8585
*/
8686
private $imageUrlBuilder;
8787

88+
/**
89+
* @var ProductSelectBuilder
90+
*/
91+
private $productSelectBuilder;
92+
8893
/**
8994
* Product constructor.
9095
*
@@ -102,6 +107,7 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
102107
* @param \Magento\Catalog\Helper\Image $catalogImageHelper
103108
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
104109
* @param UrlBuilder $urlBuilder
110+
* @param ProductSelectBuilder $productSelectBuilder
105111
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
106112
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
107113
*/
@@ -119,7 +125,8 @@ public function __construct(
119125
\Magento\Catalog\Model\Product $productModel = null,
120126
\Magento\Catalog\Helper\Image $catalogImageHelper = null,
121127
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null,
122-
UrlBuilder $urlBuilder = null
128+
UrlBuilder $urlBuilder = null,
129+
ProductSelectBuilder $productSelectBuilder = null
123130
) {
124131
$this->_productResource = $productResource;
125132
$this->_storeManager = $storeManager;
@@ -130,6 +137,7 @@ public function __construct(
130137
$this->_mediaConfig = $mediaConfig;
131138
$this->_sitemapData = $sitemapData;
132139
$this->imageUrlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlBuilder::class);
140+
$this->productSelectBuilder = $productSelectBuilder ?? ObjectManager::getInstance()->get(ProductSelectBuilder::class);
133141

134142
parent::__construct($context, $connectionName);
135143
}
@@ -287,23 +295,12 @@ public function getCollection($storeId)
287295
}
288296

289297
$connection = $this->getConnection();
290-
$this->_select = $connection->select()->from(
291-
['e' => $this->getMainTable()],
292-
[$this->getIdFieldName(), $this->_productResource->getLinkField(), 'updated_at']
293-
)->joinInner(
294-
['w' => $this->getTable('catalog_product_website')],
295-
'e.entity_id = w.product_id',
296-
[]
297-
)->joinLeft(
298-
['url_rewrite' => $this->getTable('url_rewrite')],
299-
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
300-
. ' AND url_rewrite.metadata IS NULL'
301-
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
302-
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE),
303-
['url' => 'request_path']
304-
)->where(
305-
'w.website_id = ?',
306-
$store->getWebsiteId()
298+
299+
$this->_select = $this->productSelectBuilder->execute(
300+
$this->getMainTable(),
301+
$this->getIdFieldName(),
302+
$this->_productResource->getLinkField(),
303+
$store
307304
);
308305

309306
$this->_addFilter($store->getId(), 'visibility', $this->_productVisibility->getVisibleInSiteIds(), 'in');
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright 2023 Adobe
4+
* All Rights Reserved.
5+
*
6+
* NOTICE: All information contained herein is, and remains
7+
* the property of Adobe and its suppliers, if any. The intellectual
8+
* and technical concepts contained herein are proprietary to Adobe
9+
* and its suppliers and are protected by all applicable intellectual
10+
* property laws, including trade secret and copyright laws.
11+
* Dissemination of this information or reproduction of this material
12+
* is strictly forbidden unless prior written permission is obtained
13+
* from Adobe.
14+
*/
15+
declare(strict_types=1);
16+
17+
namespace Magento\Sitemap\Model\ResourceModel\Catalog;
18+
19+
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
20+
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
21+
use Magento\Framework\App\ResourceConnection;
22+
use Magento\Framework\DB\Select;
23+
use Magento\Store\Api\Data\StoreInterface;
24+
25+
class ProductSelectBuilder
26+
{
27+
public function __construct(
28+
private readonly ResourceConnection $resource
29+
) {
30+
31+
}
32+
33+
/**
34+
* Allow to modify a select statement with plugins
35+
*
36+
* @param string $mainTableName
37+
* @param string $idField
38+
* @param string $linkField
39+
* @param StoreInterface $store
40+
* @return Select
41+
*/
42+
public function execute(
43+
string $mainTableName,
44+
string $idField,
45+
string $linkField,
46+
StoreInterface $store
47+
): Select {
48+
$connection = $this->resource->getConnection();
49+
50+
return $connection->select()->from(
51+
['e' => $mainTableName],
52+
[$idField, $linkField, 'updated_at']
53+
)->joinInner(
54+
['w' => $this->resource->getTableName('catalog_product_website')],
55+
'e.entity_id = w.product_id',
56+
[]
57+
)->joinLeft(
58+
['url_rewrite' => $this->resource->getTableName('url_rewrite')],
59+
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
60+
. ' AND url_rewrite.metadata IS NULL'
61+
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
62+
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE),
63+
['url' => 'request_path']
64+
)->where(
65+
'w.website_id = ?',
66+
$store->getWebsiteId()
67+
);
68+
}
69+
}

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

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)