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