Skip to content

Commit 83c5895

Browse files
committed
Merge branch 'ACP2E-2300' of https://github.com/magento-l3/magento2ce into 2.4-develop
2 parents a16ed5e + 5a6836e commit 83c5895

File tree

4 files changed

+170
-35
lines changed

4 files changed

+170
-35
lines changed

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

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

88
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
9+
use Magento\Framework\App\ObjectManager;
910

1011
/**
1112
* Sitemap resource catalog collection model
@@ -45,27 +46,38 @@ class Category extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4546
*/
4647
protected $metadataPool;
4748

49+
/**
50+
* @var CategorySelectBuilder
51+
*/
52+
private $categorySelectBuilder;
53+
4854
/**
4955
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
5056
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
5157
* @param \Magento\Catalog\Model\ResourceModel\Category $categoryResource
5258
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
5359
* @param string $connectionName
60+
* @param CategorySelectBuilder|null $categorySelectBuilder
5461
*/
5562
public function __construct(
5663
\Magento\Framework\Model\ResourceModel\Db\Context $context,
5764
\Magento\Store\Model\StoreManagerInterface $storeManager,
5865
\Magento\Catalog\Model\ResourceModel\Category $categoryResource,
5966
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
60-
$connectionName = null
67+
$connectionName = null,
68+
CategorySelectBuilder $categorySelectBuilder = null
6169
) {
6270
$this->_storeManager = $storeManager;
6371
$this->_categoryResource = $categoryResource;
6472
parent::__construct($context, $connectionName);
6573
$this->metadataPool = $metadataPool;
74+
$this->categorySelectBuilder = $categorySelectBuilder ??
75+
ObjectManager::getInstance()->get(CategorySelectBuilder::class);
6676
}
6777

6878
/**
79+
* Initialize catalog category entity resource model
80+
*
6981
* @return void
7082
*/
7183
protected function _construct()
@@ -104,23 +116,17 @@ public function getCollection($storeId)
104116
return false;
105117
}
106118

107-
$this->_select = $connection->select()->from(
108-
['e' => $this->getMainTable()],
109-
[$this->getIdFieldName(), 'updated_at']
110-
)->joinLeft(
111-
['url_rewrite' => $this->getTable('url_rewrite')],
112-
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
113-
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
114-
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', CategoryUrlRewriteGenerator::ENTITY_TYPE),
115-
['url' => 'request_path']
116-
)->where(
117-
'e.path LIKE ?',
118-
$categoryRow['path'] . '/%'
119+
$this->_select = $this->categorySelectBuilder->execute(
120+
$this->getMainTable(),
121+
$this->getIdFieldName(),
122+
$store,
123+
$categoryRow['path']
119124
);
120125

121126
$this->_addFilter($storeId, 'is_active', 1);
122127

123128
$query = $connection->query($this->_select);
129+
124130
while ($row = $query->fetch()) {
125131
$category = $this->_prepareCategory($row);
126132
$categories[$category->getId()] = $category;
@@ -186,7 +192,6 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
186192
break;
187193
default:
188194
return false;
189-
break;
190195
}
191196

192197
if ($attribute['backend_type'] == 'static') {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
/**
27+
* @param ResourceConnection $resource
28+
*/
29+
public function __construct(
30+
private readonly ResourceConnection $resource
31+
) {
32+
}
33+
34+
/**
35+
* Allow to modify a select statement with plugins
36+
*
37+
* @param string $mainTableName
38+
* @param string $idField
39+
* @param StoreInterface $store
40+
* @param string $path
41+
* @return Select
42+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
43+
*/
44+
public function execute(string $mainTableName, string $idField, StoreInterface $store, string $path)
45+
{
46+
$connection = $this->resource->getConnection();
47+
48+
return $connection->select()->from(
49+
['e' => $mainTableName],
50+
[$idField, 'updated_at']
51+
)->joinLeft(
52+
['url_rewrite' => $this->resource->getTableName('url_rewrite')],
53+
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
54+
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
55+
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', CategoryUrlRewriteGenerator::ENTITY_TYPE),
56+
['url' => 'request_path']
57+
)->where(
58+
'e.path LIKE ?',
59+
$path . '/%'
60+
);
61+
}
62+
}

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
2121
{
22-
const NOT_SELECTED_IMAGE = 'no_selection';
22+
public const NOT_SELECTED_IMAGE = 'no_selection';
2323

2424
/**
2525
* Collection Zend Db select
@@ -42,8 +42,6 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
4242
protected $mediaGalleryReadHandler;
4343

4444
/**
45-
* Sitemap data
46-
*
4745
* @var \Magento\Sitemap\Helper\Data
4846
*/
4947
protected $_sitemapData = null;
@@ -77,6 +75,7 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
7775
/**
7876
* @var \Magento\Catalog\Model\Product\Media\Config
7977
* @deprecated 100.2.0 unused
78+
* @see getProductImageUrl
8079
*/
8180
protected $_mediaConfig;
8281

@@ -85,6 +84,11 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
8584
*/
8685
private $imageUrlBuilder;
8786

87+
/**
88+
* @var ProductSelectBuilder
89+
*/
90+
private $productSelectBuilder;
91+
8892
/**
8993
* Product constructor.
9094
*
@@ -102,6 +106,7 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
102106
* @param \Magento\Catalog\Helper\Image $catalogImageHelper
103107
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
104108
* @param UrlBuilder $urlBuilder
109+
* @param ProductSelectBuilder $productSelectBuilder
105110
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
106111
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
107112
*/
@@ -119,7 +124,8 @@ public function __construct(
119124
\Magento\Catalog\Model\Product $productModel = null,
120125
\Magento\Catalog\Helper\Image $catalogImageHelper = null,
121126
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null,
122-
UrlBuilder $urlBuilder = null
127+
UrlBuilder $urlBuilder = null,
128+
ProductSelectBuilder $productSelectBuilder = null
123129
) {
124130
$this->_productResource = $productResource;
125131
$this->_storeManager = $storeManager;
@@ -130,6 +136,8 @@ public function __construct(
130136
$this->_mediaConfig = $mediaConfig;
131137
$this->_sitemapData = $sitemapData;
132138
$this->imageUrlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlBuilder::class);
139+
$this->productSelectBuilder = $productSelectBuilder ??
140+
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: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
/**
28+
* @param ResourceConnection $resource
29+
*/
30+
public function __construct(
31+
private readonly ResourceConnection $resource
32+
) {
33+
}
34+
35+
/**
36+
* Allow to modify a select statement with plugins
37+
*
38+
* @param string $mainTableName
39+
* @param string $idField
40+
* @param string $linkField
41+
* @param StoreInterface $store
42+
* @return Select
43+
*/
44+
public function execute(
45+
string $mainTableName,
46+
string $idField,
47+
string $linkField,
48+
StoreInterface $store
49+
): Select {
50+
$connection = $this->resource->getConnection();
51+
52+
return $connection->select()->from(
53+
['e' => $mainTableName],
54+
[$idField, $linkField, 'updated_at']
55+
)->joinInner(
56+
['w' => $this->resource->getTableName('catalog_product_website')],
57+
'e.entity_id = w.product_id',
58+
[]
59+
)->joinLeft(
60+
['url_rewrite' => $this->resource->getTableName('url_rewrite')],
61+
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
62+
. ' AND url_rewrite.metadata IS NULL'
63+
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
64+
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE),
65+
['url' => 'request_path']
66+
)->where(
67+
'w.website_id = ?',
68+
$store->getWebsiteId()
69+
);
70+
}
71+
}

0 commit comments

Comments
 (0)