Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions app/code/Magento/Sitemap/Model/ResourceModel/Catalog/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
*
* @param int $storeId
* @param string $attributeCode
* @param string $column Add attribute value to given column
* @return void
*/
protected function _joinAttribute($storeId, $attributeCode)
protected function _joinAttribute($storeId, $attributeCode, $column = null)
{
$connection = $this->getConnection();
$attribute = $this->_getAttribute($attributeCode);
Expand All @@ -204,6 +205,8 @@ protected function _joinAttribute($storeId, $attributeCode)
. ' AND ' . $connection->quoteInto($attrTableAlias . '.attribute_id = ?', $attribute['attribute_id']),
[]
);
// Global scope attribute value
$columnValue = 't1_' . $attributeCode . '.value';

if (!$attribute['is_global']) {
$attrTableAlias2 = 't2_' . $attributeCode;
Expand All @@ -214,6 +217,15 @@ protected function _joinAttribute($storeId, $attributeCode)
. ' AND ' . $connection->quoteInto($attrTableAlias2 . '.store_id = ?', $storeId),
[]
);
// Store scope attribute value
$columnValue = $this->getConnection()->getIfNullSql('t2_' . $attributeCode . '.value', $columnValue);
}

// Add attribute value to result set if needed
if (isset($column)) {
$this->_select->columns([
$column => $columnValue
]);
}
}

Expand Down Expand Up @@ -282,30 +294,15 @@ public function getCollection($storeId)
// Join product images required attributes
$imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId());
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'name');
$this->_select->columns(
['name' => $this->getConnection()->getIfNullSql('t2_name.value', 't1_name.value')]
);

$this->_joinAttribute($store->getId(), 'name', 'name');
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'thumbnail');
$this->_select->columns(
[
'thumbnail' => $this->getConnection()->getIfNullSql(
't2_thumbnail.value',
't1_thumbnail.value'
),
]
);
$this->_joinAttribute($store->getId(), 'thumbnail', 'thumbnail');
} elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'image');
$this->_select->columns(
['image' => $this->getConnection()->getIfNullSql('t2_image.value', 't1_image.value')]
);
$this->_joinAttribute($store->getId(), 'image', 'image');
}
}

$query = $connection->query($this->_select);
$query = $connection->query($this->prepareSelectStatement($this->_select));
while ($row = $query->fetch()) {
$product = $this->_prepareProduct($row, $store->getId());
$products[$product->getId()] = $product;
Expand Down Expand Up @@ -422,6 +419,17 @@ protected function _getMediaConfig()
return $this->_mediaConfig;
}

/**
* Allow to modify select statement with plugins
*
* @param \Magento\Framework\DB\Select $select
* @return \Magento\Framework\DB\Select
*/
public function prepareSelectStatement(\Magento\Framework\DB\Select $select)
{
return $select;
}

/**
* Get product image URL from image filename and path
*
Expand Down