Developer forum

Forum » Templates » hreflang-tags for ecom

hreflang-tags for ecom

Anders Ebdrup
Anders Ebdrup
Reply

Hello,

 

We are trying to output hreflangs, which works fine for normal content pages, and we can get the search engine friendly url by this method: SearchEngineFriendlyURLs.GetFriendlyUrl().

But for ecommerce paths the query parameters for GroupID and ProductID are translated to paths for the current language without looking at the ID for the full url. This is our current code:

    @foreach (var language in GetLoop("Languages"))
    {
            var qs = HttpUtility.ParseQueryString(System.Web.HttpContext.Current.Request.QueryString.ToString());
            qs.Set("ID", language.GetString("PageID"));

            var url = "https://" + language.GetString("PrimaryDomain") + "/Default.aspx?" + qs.ToString();

            <link rel="alternate" hreflang='language.GetString("Culture")' href="@url" />
    }

Does any have a way to get the right search engine friendly url for e.g. ecommerce paths?

Best regards, Anders


Replies

 
Nicolai Pedersen
Reply

Only by setting the right language context. We have solutions that has an english website that serves both danish, english and german products - so it is not that simple.

You have to speficically set the language context to do it right - DW does not know exactly what you do.

sorry about the inconveniene.

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

Thats not good... :-( How can I fix this?

It seems like I would need to have public access to HandleModuleUrl in Handler.vb to get the right url from the system?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Hi Anders

I think it would be GetUrlFromQueryString(queryStringParameter, parameterValue, alternateKey)

I can see that you can set the LanguageID in Context.Current.Items on the "alternateUrlKey" key. Set it to the right Ecommerce languageID and the handler should react on it.

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

It seems like this requires a bit too much knowledge about the url handling in Dynamicweb and I will appreciate if this can be wrapped in a helper function by the api?

Anyway do you see any pitfalls in my current implementation?

 

@foreach (var language in GetLoop("Languages"))
        {
            if (!string.IsNullOrEmpty(language.GetString("PrimaryDomain")) || true)
            {
                var qs = HttpUtility.ParseQueryString(System.Web.HttpContext.Current.Request.QueryString.ToString());
                qs.Set("ID", language.GetString("PageID"));

      
                var page = Dynamicweb.Content.Page.GetPageById(language.GetInteger("FirstActivePageID"));

      string url = "https://" + language.GetString("PrimaryDomain") + Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(language.GetInteger("PageID"));

            foreach (string key in qs)
            {
                if (key.Equals("ID", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                var value = qs[key];
                var urlFromHandler = Dynamicweb.Frontend.UrlProviders.Handler.GetUrl(key, value, page.Area.EcomLanguageID);

                if (Dynamicweb.Frontend.SearchEngineFriendlyURLs.UseExtensionLessUrls)
                {
                    url += urlFromHandler.Replace(".aspx", "");
                }
                else
                {
                    url = url.Replace(".aspx", urlFromHandler);
                }
            }
                      <meta name="ae-test" content="@url" />

      }
    }

 

Best regards, Anders

 

 
Nicolai Pedersen
Reply

It could work - would test performance of it though.

 
Anders Ebdrup
Anders Ebdrup
Reply

Hi Nicolai,

 

Thanks for the review. In later versions can a new tag be added to the language-loop with the hreflang or maybe make a function in the api, so this logic is transparent for the implementer?

 

Best regards, Anders

 
Nicolai Pedersen
Reply

Of course - will look into this once dealing with a new provider for ecommerce for DW9.

Thanks, Nicolai

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply

Bump!
We have the same issue, and are looking to solve this using standard DW API, or settings.
Has there been any development related to this case?

 
Nicolai Pedersen
Reply

There have been no development on this...

BR Nicolai

 
Martin Grønbekk Moen
Martin Grønbekk Moen
Reply
This post has been marked as an answer

Okay, we solved it for now by using this code (DW 9.5.4 w/Rapido 2.1).

2018-11-05_1319.png
Votes for this answer: 1

 

You must be logged in to post in the forum