@@ -192,9 +192,10 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
192
192
*
193
193
* @param int $storeId
194
194
* @param string $attributeCode
195
+ * @param string $column Add attribute value to given column
195
196
* @return void
196
197
*/
197
- protected function _joinAttribute ($ storeId , $ attributeCode )
198
+ protected function _joinAttribute ($ storeId , $ attributeCode, $ column = null )
198
199
{
199
200
$ connection = $ this ->getConnection ();
200
201
$ attribute = $ this ->_getAttribute ($ attributeCode );
@@ -207,6 +208,8 @@ protected function _joinAttribute($storeId, $attributeCode)
207
208
. ' AND ' . $ connection ->quoteInto ($ attrTableAlias . '.attribute_id = ? ' , $ attribute ['attribute_id ' ]),
208
209
[]
209
210
);
211
+ // Global scope attribute value
212
+ $ columnValue = 't1_ ' . $ attributeCode . '.value ' ;
210
213
211
214
if (!$ attribute ['is_global ' ]) {
212
215
$ attrTableAlias2 = 't2_ ' . $ attributeCode ;
@@ -217,6 +220,15 @@ protected function _joinAttribute($storeId, $attributeCode)
217
220
. ' AND ' . $ connection ->quoteInto ($ attrTableAlias2 . '.store_id = ? ' , $ storeId ),
218
221
[]
219
222
);
223
+ // Store scope attribute value
224
+ $ columnValue = $ this ->getConnection ()->getIfNullSql ('t2_ ' . $ attributeCode . '.value ' , $ columnValue );
225
+ }
226
+
227
+ // Add attribute value to result set if needed
228
+ if (isset ($ column )) {
229
+ $ this ->_select ->columns ([
230
+ $ column => $ columnValue
231
+ ]);
220
232
}
221
233
}
222
234
@@ -285,30 +297,16 @@ public function getCollection($storeId)
285
297
// Join product images required attributes
286
298
$ imageIncludePolicy = $ this ->_sitemapData ->getProductImageIncludePolicy ($ store ->getId ());
287
299
if (\Magento \Sitemap \Model \Source \Product \Image \IncludeImage::INCLUDE_NONE != $ imageIncludePolicy ) {
288
- $ this ->_joinAttribute ($ store ->getId (), 'name ' );
289
- $ this ->_select ->columns (
290
- ['name ' => $ this ->getConnection ()->getIfNullSql ('t2_name.value ' , 't1_name.value ' )]
291
- );
300
+ $ this ->_joinAttribute ($ store ->getId (), 'name ' , 'name ' );
292
301
293
302
if (\Magento \Sitemap \Model \Source \Product \Image \IncludeImage::INCLUDE_ALL == $ imageIncludePolicy ) {
294
- $ this ->_joinAttribute ($ store ->getId (), 'thumbnail ' );
295
- $ this ->_select ->columns (
296
- [
297
- 'thumbnail ' => $ this ->getConnection ()->getIfNullSql (
298
- 't2_thumbnail.value ' ,
299
- 't1_thumbnail.value '
300
- ),
301
- ]
302
- );
303
+ $ this ->_joinAttribute ($ store ->getId (), 'thumbnail ' , 'thumbnail ' );
303
304
} elseif (\Magento \Sitemap \Model \Source \Product \Image \IncludeImage::INCLUDE_BASE == $ imageIncludePolicy ) {
304
- $ this ->_joinAttribute ($ store ->getId (), 'image ' );
305
- $ this ->_select ->columns (
306
- ['image ' => $ this ->getConnection ()->getIfNullSql ('t2_image.value ' , 't1_image.value ' )]
307
- );
305
+ $ this ->_joinAttribute ($ store ->getId (), 'image ' , 'image ' );
308
306
}
309
307
}
310
308
311
- $ query = $ connection ->query ($ this ->_select );
309
+ $ query = $ connection ->query ($ this ->prepareSelectStatement ( $ this -> _select ) );
312
310
while ($ row = $ query ->fetch ()) {
313
311
$ product = $ this ->_prepareProduct ($ row , $ store ->getId ());
314
312
$ products [$ product ->getId ()] = $ product ;
@@ -425,6 +423,17 @@ protected function _getMediaConfig()
425
423
return $ this ->_mediaConfig ;
426
424
}
427
425
426
+ /**
427
+ * Allow to modify select statement with plugins
428
+ *
429
+ * @param \Magento\Framework\DB\Select $select
430
+ * @return \Magento\Framework\DB\Select
431
+ */
432
+ public function prepareSelectStatement (\Magento \Framework \DB \Select $ select )
433
+ {
434
+ return $ select ;
435
+ }
436
+
428
437
/**
429
438
* Get product image URL from image filename and path
430
439
*
0 commit comments