Skip to content

Commit 6638187

Browse files
ENGCOM-5240: #22934 Improved sitemap product generation logic #23129
2 parents 3263e5a + 9edc2cc commit 6638187

File tree

1 file changed

+27
-4
lines changed
  • app/code/Magento/Sitemap/Model/ResourceModel/Catalog

1 file changed

+27
-4
lines changed

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,11 @@ protected function _joinAttribute($storeId, $attributeCode, $column = null)
257257

258258
// Add attribute value to result set if needed
259259
if (isset($column)) {
260-
$this->_select->columns([
261-
$column => $columnValue
262-
]);
260+
$this->_select->columns(
261+
[
262+
$column => $columnValue
263+
]
264+
);
263265
}
264266
}
265267

@@ -309,6 +311,10 @@ public function getCollection($storeId)
309311
}
310312

311313
$connection = $this->getConnection();
314+
$urlRewriteMetaDataCondition = '';
315+
if (!$this->isCategoryProductURLsConfig($storeId)) {
316+
$urlRewriteMetaDataCondition = ' AND url_rewrite.metadata IS NULL';
317+
}
312318

313319
$this->_select = $connection->select()->from(
314320
['e' => $this->getMainTable()],
@@ -319,7 +325,8 @@ public function getCollection($storeId)
319325
[]
320326
)->joinLeft(
321327
['url_rewrite' => $this->getTable('url_rewrite')],
322-
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1 AND url_rewrite.metadata IS NULL'
328+
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1'
329+
. $urlRewriteMetaDataCondition
323330
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
324331
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE),
325332
['url' => 'request_path']
@@ -483,4 +490,20 @@ private function getProductImageUrl($image)
483490
{
484491
return $this->imageUrlBuilder->getUrl($image, 'product_page_image_large');
485492
}
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+
}
486509
}

0 commit comments

Comments
 (0)