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

Commerce Settings #93

Open
jaymarvels opened this issue Sep 15, 2023 · 5 comments
Open

Commerce Settings #93

jaymarvels opened this issue Sep 15, 2023 · 5 comments

Comments

@jaymarvels
Copy link

Are there any additional configuration to get this to work with commerce apart from adding:

services.AddSitemapsCommerce();

In the configuration docs (https://github.com/Geta/geta-optimizely-sitemaps/blob/master/docs/editor-guide.md) it talks about the format and how its currently standard or mobile. If I do check the "standard and commerce" option and run the scheduled job my commerce product pages still do not show in the sitemap.xml.

Is something missing?

@jaymarvels
Copy link
Author

@marisks Any input?

@marisks
Copy link
Member

marisks commented Sep 21, 2023

As I remember, it is enough to follow configuration documentation here: https://github.com/Geta/geta-optimizely-sitemaps/tree/master#configuration
So call AddSitemaps, AddSitemapsCommerce, and make sure that razor pages are mapped.

@jaymarvels
Copy link
Author

@marisks Yeah unfortunately its not working. I am guessing it could be due to it being multi site, multi language, multi catalog it can't get the correct one.

If I create my own sitemap and commerce generator by implementing the public virtual member, eg:

public class StandardAndCommerceSitemapXmlGenerator : CommerceSitemapXmlGenerator, ICommerceAndStandardSitemapXmlGenerator
{
//
}

And just use the default from the repo as an override:

        protected override IEnumerable<XElement> GetSitemapXmlElements()
        {
            var rootContentReference = _referenceConverter.GetRootLink();

            if (SitemapData.RootPageId != Constants.DefaultRootPageId)
            {
                rootContentReference = new ContentReference(SitemapData.RootPageId)
                {
                    ProviderName = "CatalogContent"
                };
            }

            var descendants = ContentRepository.GetDescendents(rootContentReference);

            return GenerateXmlElements(descendants);
        }

Then descendants is always empty.

@marisks
Copy link
Member

marisks commented Sep 25, 2023

Have you configured RootPageId for the catalog you want to generate a sitemap?

@alex-finnigan-mando
Copy link

Bumping this issue as I've also run into the same problem but I think I've found the cause.

This bug only manifests when the user sets the Root page ID to anything other than -1 (which could be the case in a multisite scenario).

In CommerceAndStandardSitemapXmlGenerator, the GetSitemapXmlElements method gets the CMS content then calls the base method from CommerceSitemapXmlGenerator. In this base method, we get the Catalog Root using ReferenceConverter and then the problem occurs in the following IF statement:

if (SitemapData.RootPageId != Constants.DefaultRootPageId)
{
    rootContentReference = new ContentReference(SitemapData.RootPageId)
    {
        ProviderName = "CatalogContent"
    };
}

this will be evalutated as true since we have defined a specific page instead of the default root. This will then override the Catalog Root to -1, and since -1 does not exist in the Commerce tree, we get no descendants.

I assume the fix for this would be to remove this IF statement because I can't see why we would need to do this?

Current workaround for anyone searching for answers would be to follow @jaymarvels' lead and override the CommerceAndStandardSitemapXmlGenerator service with a copy in your solution, then remove the IF statement (unless there's a good reason why we shouldn't?).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants