@@ -257,9 +257,11 @@ protected function _joinAttribute($storeId, $attributeCode, $column = null)
257
257
258
258
// Add attribute value to result set if needed
259
259
if (isset ($ column )) {
260
- $ this ->_select ->columns ([
261
- $ column => $ columnValue
262
- ]);
260
+ $ this ->_select ->columns (
261
+ [
262
+ $ column => $ columnValue
263
+ ]
264
+ );
263
265
}
264
266
}
265
267
@@ -309,6 +311,10 @@ public function getCollection($storeId)
309
311
}
310
312
311
313
$ connection = $ this ->getConnection ();
314
+ $ urlRewriteMetaDataCondition = '' ;
315
+ if (!$ this ->isCategoryProductURLsConfig ($ storeId )) {
316
+ $ urlRewriteMetaDataCondition = ' AND url_rewrite.metadata IS NULL ' ;
317
+ }
312
318
313
319
$ this ->_select = $ connection ->select ()->from (
314
320
['e ' => $ this ->getMainTable ()],
@@ -319,7 +325,8 @@ public function getCollection($storeId)
319
325
[]
320
326
)->joinLeft (
321
327
['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
323
330
. $ connection ->quoteInto (' AND url_rewrite.store_id = ? ' , $ store ->getId ())
324
331
. $ connection ->quoteInto (' AND url_rewrite.entity_type = ? ' , ProductUrlRewriteGenerator::ENTITY_TYPE ),
325
332
['url ' => 'request_path ' ]
@@ -483,4 +490,20 @@ private function getProductImageUrl($image)
483
490
{
484
491
return $ this ->imageUrlBuilder ->getUrl ($ image , 'product_page_image_large ' );
485
492
}
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
+ }
486
509
}
0 commit comments