@@ -170,9 +170,10 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
170
170
*
171
171
* @param int $storeId
172
172
* @param string $attributeCode
173
+ * @param string $column Add attribute value to given column
173
174
* @return void
174
175
*/
175
- protected function _joinAttribute ($ storeId , $ attributeCode )
176
+ protected function _joinAttribute ($ storeId , $ attributeCode, $ column = null )
176
177
{
177
178
$ connection = $ this ->getConnection ();
178
179
$ attribute = $ this ->_getAttribute ($ attributeCode );
@@ -185,6 +186,8 @@ protected function _joinAttribute($storeId, $attributeCode)
185
186
. ' AND ' . $ connection ->quoteInto ($ attrTableAlias . '.attribute_id = ? ' , $ attribute ['attribute_id ' ]),
186
187
[]
187
188
);
189
+ // Global scope attribute value
190
+ $ columnValue = 't1_ ' . $ attributeCode . '.value ' ;
188
191
189
192
if (!$ attribute ['is_global ' ]) {
190
193
$ attrTableAlias2 = 't2_ ' . $ attributeCode ;
@@ -195,6 +198,15 @@ protected function _joinAttribute($storeId, $attributeCode)
195
198
. ' AND ' . $ connection ->quoteInto ($ attrTableAlias2 . '.store_id = ? ' , $ storeId ),
196
199
[]
197
200
);
201
+ // Store scope attribute value
202
+ $ columnValue = $ this ->getConnection ()->getIfNullSql ('t2_ ' . $ attributeCode . '.value ' , $ columnValue );
203
+ }
204
+
205
+ // Add attribute value to result set if needed
206
+ if (isset ($ column )) {
207
+ $ this ->_select ->columns ([
208
+ $ column => $ columnValue
209
+ ]);
198
210
}
199
211
}
200
212
@@ -263,30 +275,15 @@ public function getCollection($storeId)
263
275
// Join product images required attributes
264
276
$ imageIncludePolicy = $ this ->_sitemapData ->getProductImageIncludePolicy ($ store ->getId ());
265
277
if (\Magento \Sitemap \Model \Source \Product \Image \IncludeImage::INCLUDE_NONE != $ imageIncludePolicy ) {
266
- $ this ->_joinAttribute ($ store ->getId (), 'name ' );
267
- $ this ->_select ->columns (
268
- ['name ' => $ this ->getConnection ()->getIfNullSql ('t2_name.value ' , 't1_name.value ' )]
269
- );
270
-
278
+ $ this ->_joinAttribute ($ store ->getId (), 'name ' , 'name ' );
271
279
if (\Magento \Sitemap \Model \Source \Product \Image \IncludeImage::INCLUDE_ALL == $ imageIncludePolicy ) {
272
- $ this ->_joinAttribute ($ store ->getId (), 'thumbnail ' );
273
- $ this ->_select ->columns (
274
- [
275
- 'thumbnail ' => $ this ->getConnection ()->getIfNullSql (
276
- 't2_thumbnail.value ' ,
277
- 't1_thumbnail.value '
278
- ),
279
- ]
280
- );
280
+ $ this ->_joinAttribute ($ store ->getId (), 'thumbnail ' , 'thumbnail ' );
281
281
} elseif (\Magento \Sitemap \Model \Source \Product \Image \IncludeImage::INCLUDE_BASE == $ imageIncludePolicy ) {
282
- $ this ->_joinAttribute ($ store ->getId (), 'image ' );
283
- $ this ->_select ->columns (
284
- ['image ' => $ this ->getConnection ()->getIfNullSql ('t2_image.value ' , 't1_image.value ' )]
285
- );
282
+ $ this ->_joinAttribute ($ store ->getId (), 'image ' , 'image ' );
286
283
}
287
284
}
288
285
289
- $ query = $ connection ->query ($ this ->_select );
286
+ $ query = $ connection ->query ($ this ->prepareSelectStatement ( $ this -> _select ) );
290
287
while ($ row = $ query ->fetch ()) {
291
288
$ product = $ this ->_prepareProduct ($ row , $ store ->getId ());
292
289
$ products [$ product ->getId ()] = $ product ;
@@ -401,4 +398,15 @@ protected function _getMediaConfig()
401
398
{
402
399
return $ this ->_mediaConfig ;
403
400
}
401
+
402
+ /**
403
+ * Allow to modify select statement with plugins
404
+ *
405
+ * @param \Magento\Framework\DB\Select $select
406
+ * @return \Magento\Framework\DB\Select
407
+ */
408
+ public function prepareSelectStatement (\Magento \Framework \DB \Select $ select )
409
+ {
410
+ return $ select ;
411
+ }
404
412
}
0 commit comments