Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 43dd32b

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-75459' into 2.2-pr-bugfixes
2 parents 61bd520 + f8a91f4 commit 43dd32b

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ protected function _addFilter($storeId, $attributeCode, $value, $type = '=')
192192
*
193193
* @param int $storeId
194194
* @param string $attributeCode
195+
* @param string $column Add attribute value to given column
195196
* @return void
196197
*/
197-
protected function _joinAttribute($storeId, $attributeCode)
198+
protected function _joinAttribute($storeId, $attributeCode, $column = null)
198199
{
199200
$connection = $this->getConnection();
200201
$attribute = $this->_getAttribute($attributeCode);
@@ -207,6 +208,8 @@ protected function _joinAttribute($storeId, $attributeCode)
207208
. ' AND ' . $connection->quoteInto($attrTableAlias . '.attribute_id = ?', $attribute['attribute_id']),
208209
[]
209210
);
211+
// Global scope attribute value
212+
$columnValue = 't1_' . $attributeCode . '.value';
210213

211214
if (!$attribute['is_global']) {
212215
$attrTableAlias2 = 't2_' . $attributeCode;
@@ -217,6 +220,15 @@ protected function _joinAttribute($storeId, $attributeCode)
217220
. ' AND ' . $connection->quoteInto($attrTableAlias2 . '.store_id = ?', $storeId),
218221
[]
219222
);
223+
// Store scope attribute value
224+
$columnValue = $this->getConnection()->getIfNullSql('t2_' . $attributeCode . '.value', $columnValue);
225+
}
226+
227+
// Add attribute value to result set if needed
228+
if (isset($column)) {
229+
$this->_select->columns([
230+
$column => $columnValue
231+
]);
220232
}
221233
}
222234

@@ -285,30 +297,16 @@ public function getCollection($storeId)
285297
// Join product images required attributes
286298
$imageIncludePolicy = $this->_sitemapData->getProductImageIncludePolicy($store->getId());
287299
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_NONE != $imageIncludePolicy) {
288-
$this->_joinAttribute($store->getId(), 'name');
289-
$this->_select->columns(
290-
['name' => $this->getConnection()->getIfNullSql('t2_name.value', 't1_name.value')]
291-
);
300+
$this->_joinAttribute($store->getId(), 'name', 'name');
292301

293302
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) {
294-
$this->_joinAttribute($store->getId(), 'thumbnail');
295-
$this->_select->columns(
296-
[
297-
'thumbnail' => $this->getConnection()->getIfNullSql(
298-
't2_thumbnail.value',
299-
't1_thumbnail.value'
300-
),
301-
]
302-
);
303+
$this->_joinAttribute($store->getId(), 'thumbnail', 'thumbnail');
303304
} elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) {
304-
$this->_joinAttribute($store->getId(), 'image');
305-
$this->_select->columns(
306-
['image' => $this->getConnection()->getIfNullSql('t2_image.value', 't1_image.value')]
307-
);
305+
$this->_joinAttribute($store->getId(), 'image', 'image');
308306
}
309307
}
310308

311-
$query = $connection->query($this->_select);
309+
$query = $connection->query($this->prepareSelectStatement($this->_select));
312310
while ($row = $query->fetch()) {
313311
$product = $this->_prepareProduct($row, $store->getId());
314312
$products[$product->getId()] = $product;
@@ -425,6 +423,17 @@ protected function _getMediaConfig()
425423
return $this->_mediaConfig;
426424
}
427425

426+
/**
427+
* Allow to modify select statement with plugins
428+
*
429+
* @param \Magento\Framework\DB\Select $select
430+
* @return \Magento\Framework\DB\Select
431+
*/
432+
public function prepareSelectStatement(\Magento\Framework\DB\Select $select)
433+
{
434+
return $select;
435+
}
436+
428437
/**
429438
* Get product image URL from image filename and path
430439
*

dev/tests/integration/testsuite/Magento/Sitemap/_files/sitemap_products.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
// Copy images to tmp media path
8+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
9+
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
810
use Magento\Framework\App\Filesystem\DirectoryList;
911

1012
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -199,3 +201,12 @@
199201
)->setRelatedLinkData(
200202
[$productLink]
201203
)->save();
204+
205+
// Move "name" attribute of the product to the global scope
206+
$attributesRepository = $objectManager->create(ProductAttributeRepositoryInterface::class);
207+
$attributes = $product->getAttributes();
208+
209+
if (isset($attributes['name'])) {
210+
$attributes['name']->setScope(Attribute::SCOPE_GLOBAL_TEXT);
211+
$attributesRepository->save($attributes['name']);
212+
}

0 commit comments

Comments
 (0)