Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If name attribute scope is changed to global, sitemap crashes #5941

Closed
AirmanAJK opened this issue Aug 2, 2016 · 7 comments
Closed

If name attribute scope is changed to global, sitemap crashes #5941

AirmanAJK opened this issue Aug 2, 2016 · 7 comments
Labels
bug report Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release

Comments

@AirmanAJK
Copy link

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'.

@duhon
Copy link
Contributor

duhon commented Aug 5, 2016

@AirmanAJK Thanks for reporting this issue.
We've created internal ticket MAGETWO-56482 to fix it.

@duhon duhon added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Aug 5, 2016
@karice11
Copy link

Where Can I see the fix? I have the same issue in my project. Thanks!

@AirmanAJK
Copy link
Author

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')]
	);
}

@WMV-SYSTEMS
Copy link

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;
}

@nbjohan
Copy link

nbjohan commented Mar 13, 2017

SitemapFix.zip

I made a workaround module based on the fix above. May save someone some time.

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-70707

@magento-team magento-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report develop labels Jul 31, 2017
@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report develop Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
magento-team pushed a commit that referenced this issue Oct 10, 2017
@magento-engcom-team magento-engcom-team added Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed 2.1.x Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release labels Oct 13, 2017
@magento-engcom-team magento-engcom-team added the Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release label Oct 13, 2017
@magento-engcom-team magento-engcom-team added the Event: distributed-cd Distributed Contribution Day label Mar 19, 2018
@magento-engcom-team magento-engcom-team removed the Event: distributed-cd Distributed Contribution Day label Apr 14, 2018
@magento-engcom-team
Copy link
Contributor

Hi @AirmanAJK
Looks like this issue has already been fixed with this PR: #8999

Please see the PR and commits, referenced in this ticket to see the fix.
Thank you for collaboration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release
Projects
None yet
Development

No branches or pull requests

9 participants