Skip to content

Commit f2ec5f0

Browse files
committed
Always use canonical urls in the sitemap
resolve comments Whitelist URL_REWRITE_IS_AUTOGENERATED_METADATA index Suppress unused parameter warning
1 parent f3a160c commit f2ec5f0

File tree

3 files changed

+9
-49
lines changed

3 files changed

+9
-49
lines changed

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

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
*/
66
namespace Magento\Sitemap\Model\ResourceModel\Catalog;
77

8-
use Magento\Catalog\Helper\Product as HelperProduct;
98
use Magento\Catalog\Model\Product\Image\UrlBuilder;
109
use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
1110
use Magento\Framework\App\ObjectManager;
12-
use Magento\Store\Model\ScopeInterface;
1311
use Magento\Store\Model\Store;
1412

1513
/**
@@ -82,28 +80,11 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
8280
*/
8381
protected $_mediaConfig;
8482

85-
/**
86-
* @var \Magento\Catalog\Model\Product
87-
*/
88-
private $productModel;
89-
90-
/**
91-
* @var \Magento\Catalog\Helper\Image
92-
*/
93-
private $catalogImageHelper;
94-
9583
/**
9684
* @var UrlBuilder
9785
*/
9886
private $imageUrlBuilder;
9987

100-
/**
101-
* Scope Config
102-
*
103-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
104-
*/
105-
private $scopeConfig;
106-
10788
/**
10889
* Product constructor.
10990
*
@@ -122,6 +103,7 @@ class Product extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
122103
* @param \Magento\Framework\App\Config\ScopeConfigInterface|null $scopeConfig
123104
* @param UrlBuilder $urlBuilder
124105
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
106+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
125107
*/
126108
public function __construct(
127109
\Magento\Framework\Model\ResourceModel\Db\Context $context,
@@ -147,13 +129,7 @@ public function __construct(
147129
$this->mediaGalleryReadHandler = $mediaGalleryReadHandler;
148130
$this->_mediaConfig = $mediaConfig;
149131
$this->_sitemapData = $sitemapData;
150-
$this->productModel = $productModel ?: ObjectManager::getInstance()->get(\Magento\Catalog\Model\Product::class);
151-
$this->catalogImageHelper = $catalogImageHelper;
152132
$this->imageUrlBuilder = $urlBuilder ?? ObjectManager::getInstance()->get(UrlBuilder::class);
153-
$this->catalogImageHelper = $catalogImageHelper ?: ObjectManager::getInstance()
154-
->get(\Magento\Catalog\Helper\Image::class);
155-
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()
156-
->get(\Magento\Framework\App\Config\ScopeConfigInterface::class);
157133

158134
parent::__construct($context, $connectionName);
159135
}
@@ -311,11 +287,6 @@ public function getCollection($storeId)
311287
}
312288

313289
$connection = $this->getConnection();
314-
$urlRewriteMetaDataCondition = '';
315-
if (!$this->isCategoryProductURLsConfig($storeId)) {
316-
$urlRewriteMetaDataCondition = ' AND url_rewrite.metadata IS NULL';
317-
}
318-
319290
$this->_select = $connection->select()->from(
320291
['e' => $this->getMainTable()],
321292
[$this->getIdFieldName(), $this->_productResource->getLinkField(), 'updated_at']
@@ -326,7 +297,7 @@ public function getCollection($storeId)
326297
)->joinLeft(
327298
['url_rewrite' => $this->getTable('url_rewrite')],
328299
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
329-
. $urlRewriteMetaDataCondition
300+
. ' AND url_rewrite.metadata IS NULL'
330301
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
331302
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE),
332303
['url' => 'request_path']
@@ -490,20 +461,4 @@ private function getProductImageUrl($image)
490461
{
491462
return $this->imageUrlBuilder->getUrl($image, 'product_page_image_large');
492463
}
493-
494-
/**
495-
* Return Use Categories Path for Product URLs config value
496-
*
497-
* @param null|string $storeId
498-
*
499-
* @return bool
500-
*/
501-
private function isCategoryProductURLsConfig($storeId)
502-
{
503-
return $this->scopeConfig->isSetFlag(
504-
HelperProduct::XML_PATH_PRODUCT_URL_USE_CATEGORY,
505-
ScopeInterface::SCOPE_STORE,
506-
$storeId
507-
);
508-
}
509464
}

app/code/Magento/UrlRewrite/etc/db_schema.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@
4040
<index referenceId="URL_REWRITE_ENTITY_ID" indexType="btree">
4141
<column name="entity_id"/>
4242
</index>
43+
<index referenceId="URL_REWRITE_IS_AUTOGENERATED_METADATA" indexType="btree">
44+
<column name="is_autogenerated"/>
45+
<column name="metadata"/>
46+
</index>
4347
</table>
4448
</schema>

app/code/Magento/UrlRewrite/etc/db_schema_whitelist.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
"index": {
1616
"URL_REWRITE_TARGET_PATH": true,
1717
"URL_REWRITE_STORE_ID_ENTITY_ID": true,
18-
"URL_REWRITE_ENTITY_ID": true
18+
"URL_REWRITE_ENTITY_ID": true,
19+
"URL_REWRITE_IS_AUTOGENERATED_METADATA": true
1920
},
2021
"constraint": {
2122
"PRIMARY": true,
2223
"URL_REWRITE_REQUEST_PATH_STORE_ID": true
2324
}
2425
}
25-
}
26+
}

0 commit comments

Comments
 (0)