Occurring in CE 2.1.0
If the scope of the name attribute is set to global, the sitemap will crash, showing the message "We can't generate the sitemap right now."
This is because the _joinAttribute function inside \Magento\Sitemap\Model\ResourceModel\Catalog\Product only adds a 't2_name' alias if the attribute provided is not global. However, the getCollection function assumes name will never be global as it has hardcoded references to 't2_name.value'.
@AirmanAJK Thanks for reporting this issue.
We've created internal ticket MAGETWO-56482 to fix it.
Where Can I see the fix? I have the same issue in my project. Thanks!
Any update to this? It's a quick fix and I reported it over 4 months ago. CE 2.1.3 came out and it hasn't changed. If I wasn't a developer, Magento would be unusable due to these small but site-breaking bugs.
$nameAttr = $this->_getAttribute('name');
if (!$nameAttr['is_global']) {
$this->_select->columns(
['name' => $this->getConnection()->getIfNullSql('t2_name.value', 't1_name.value')]
);
}
I've changed the function 'getCollection' inside this Product.php to: (and this fixed the problem for me)
public function getCollection($storeId)
{
$products = [];
/* @var $store Store */
$store = $this->_storeManager->getStore($storeId);
if (!$store) {
return false;
}
$connection = $this->getConnection();
$this->_select = $connection->select()->from(
['e' => $this->getMainTable()],
[$this->getIdFieldName(), $this->_productResource->getLinkField(), 'updated_at']
)->joinInner(
['w' => $this->getTable('catalog_product_website')],
'e.entity_id = w.product_id',
[]
)->joinLeft(
['url_rewrite' => $this->getTable('url_rewrite')],
'e.entity_id = url_rewrite.entity_id AND url_rewrite.is_autogenerated = 1 AND url_rewrite.metadata IS NULL'
. $connection->quoteInto(' AND url_rewrite.store_id = ?', $store->getId())
. $connection->quoteInto(' AND url_rewrite.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE),
['url' => 'request_path']
)->where(
'w.website_id = ?',
$store->getWebsiteId()
);
$this->_addFilter($store->getId(), 'visibility', $this->_productVisibility->getVisibleInSiteIds(), 'in');
$this->_addFilter($store->getId(), 'status', $this->_productStatus->getVisibleStatusIds(), 'in');
// 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');
$__attribute = $this->_productResource->getAttribute('name');
if (!$__attribute['is_global']) {
$this->_select->columns(
['name' => $this->getConnection()->getIfNullSql('t2_name.value', 't1_name.value')]
);
}else{
$this->_select->columns(['name' => 't1_name.value']);
}
if (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_ALL == $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'thumbnail');
$__attribute = $this->_productResource->getAttribute('thumbnail');
if (!$__attribute['is_global']) {
$this->_select->columns(
[
'thumbnail' => $this->getConnection()->getIfNullSql(
't2_thumbnail.value',
't1_thumbnail.value'
),
]
);
}else{
$this->_select->columns(['thumbnail' => 't1_thumbnail.value']);
}
} elseif (\Magento\Sitemap\Model\Source\Product\Image\IncludeImage::INCLUDE_BASE == $imageIncludePolicy) {
$this->_joinAttribute($store->getId(), 'image');
$__attribute = $this->_productResource->getAttribute('image');
if (!$__attribute['is_global']) {
$this->_select->columns(
['image' => $this->getConnection()->getIfNullSql('t2_image.value', 't1_image.value')]
);
}else{
$this->_select->columns(['image' => 't1_image.value']);
}
}
}
$query = $connection->query($this->_select);
while ($row = $query->fetch()) {
$product = $this->_prepareProduct($row, $store->getId());
$products[$product->getId()] = $product;
}
return $products;
}
I made a workaround module based on the fix above. May save someone some time.
Internal ticket to track issue progress: MAGETWO-70707
Hi @AirmanAJK
Looks like this issue has already been fixed with this PR: https://github.com/magento/magento2/pull/8999
Please see the PR and commits, referenced in this ticket to see the fix.
Thank you for collaboration
Most helpful comment
Any update to this? It's a quick fix and I reported it over 4 months ago. CE 2.1.3 came out and it hasn't changed. If I wasn't a developer, Magento would be unusable due to these small but site-breaking bugs.