Skip to content

Commit f0087b2

Browse files
author
Oleksii Korshenko
authored
MAGETWO-70707: Correctly process global product attributes #5941 #8999
2 parents 7ffd487 + cd45333 commit f0087b2

File tree

1 file changed

+28
-20
lines changed
  • app/code/Magento/Sitemap/Model/ResourceModel/Catalog

1 file changed

+28
-20
lines changed

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

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
189189
*
190190
* @param int $storeId
191191
* @param string $attributeCode
192+
* @param string $column Add attribute value to given column
192193
* @return void
193194
*/
194-
protected function _joinAttribute($storeId, $attributeCode)
195+
protected function _joinAttribute($storeId, $attributeCode, $column = null)
195196
{
196197
$connection = $this->getConnection();
197198
$attribute = $this->_getAttribute($attributeCode);
@@ -204,6 +205,8 @@ protected function _joinAttribute($storeId, $attributeCode)
204205
. ' AND ' . $connection->quoteInto($attrTableAlias . '.attribute_id = ?', $attribute['attribute_id']),
205206
[]
206207
);
208+
// Global scope attribute value
209+
$columnValue = 't1_' . $attributeCode . '.value';
207210

208211
if (!$attribute['is_global']) {
209212
$attrTableAlias2 = 't2_' . $attributeCode;
@@ -214,6 +217,15 @@ protected function _joinAttribute($storeId, $attributeCode)
214217
. ' AND ' . $connection->quoteInto($attrTableAlias2 . '.store_id = ?', $storeId),
215218
[]
216219
);
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+
]);
217229
}
218230
}
219231

@@ -282,30 +294,15 @@ public function getCollection($storeId)
282294
// Join product images required attributes
283295
$imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId());
284296
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');
290298
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');
300300
} 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');
305302
}
306303
}
307304

308-
$query = $connection->query($this->_select);
305+
$query = $connection->query($this->prepareSelectStatement($this->_select));
309306
while ($row = $query->fetch()) {
310307
$product = $this->_prepareProduct($row, $store->getId());
311308
$products[$product->getId()] = $product;
@@ -422,6 +419,17 @@ protected function _getMediaConfig()
422419
return $this->_mediaConfig;
423420
}
424421

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+
425433
/**
426434
* Get product image URL from image filename and path
427435
*

0 commit comments

Comments
 (0)