Skip to content

Commit 9b0608e

Browse files
committed
Correctly process global product attributes #5941
1 parent ed9edb1 commit 9b0608e

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
@@ -170,9 +170,10 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
170170
*
171171
* @param int $storeId
172172
* @param string $attributeCode
173+
* @param string $column Add attribute value to given column
173174
* @return void
174175
*/
175-
protected function _joinAttribute($storeId, $attributeCode)
176+
protected function _joinAttribute($storeId, $attributeCode, $column = null)
176177
{
177178
$connection = $this->getConnection();
178179
$attribute = $this->_getAttribute($attributeCode);
@@ -185,6 +186,8 @@ protected function _joinAttribute($storeId, $attributeCode)
185186
. ' AND ' . $connection->quoteInto($attrTableAlias . '.attribute_id = ?', $attribute['attribute_id']),
186187
[]
187188
);
189+
// Global scope attribute value
190+
$columnValue = 't1_' . $attributeCode . '.value';
188191

189192
if (!$attribute['is_global']) {
190193
$attrTableAlias2 = 't2_' . $attributeCode;
@@ -195,6 +198,15 @@ protected function _joinAttribute($storeId, $attributeCode)
195198
. ' AND ' . $connection->quoteInto($attrTableAlias2 . '.store_id = ?', $storeId),
196199
[]
197200
);
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+
]);
198210
}
199211
}
200212

@@ -263,30 +275,15 @@ public function getCollection($storeId)
263275
// Join product images required attributes
264276
$imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId());
265277
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');
271279
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');
281281
} 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');
286283
}
287284
}
288285

289-
$query = $connection->query($this->_select);
286+
$query = $connection->query($this->prepareSelectStatement($this->_select));
290287
while ($row = $query->fetch()) {
291288
$product = $this->_prepareProduct($row, $store->getId());
292289
$products[$product->getId()] = $product;
@@ -401,4 +398,15 @@ protected function _getMediaConfig()
401398
{
402399
return $this->_mediaConfig;
403400
}
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+
}
404412
}

0 commit comments

Comments
 (0)