Search code examples
sap-commerce-cloudstorefront

Hybris redirect from a cmssite to another cmssite


I have b2c and b2b site. When a b2b customer logs out it should be redirected to b2c site homepage.

I tried below. It works for other sites like "www.google.com" but redirecting to another cmssite doesn't work.

httpResponse.sendRedirect(encodedRedirectUrl);

Also I tried setting target cmssite to currentSite before redirect but no luck

I believe the session site and other parameters are not cleared from current site or populated for target site. Guide me the right way to do it.


Solution

  • There are two things you need to know about CMS sites and the session:

    1. When you access a hybris storefront for the first time, hybris determines the CMS site for this specific request. The request is matched against the URL pattern in your CMS sites. The first CMS site that has a pattern that matches is put into the session. Also the corresponding catalogs are set and so on.
    2. When a CMS site is set in session the process from 1. is not undertaken anymore. Every request that arrives will be associated with the CMS site from the session.

    What you need to do is:

    Either:

    Clear the CMS site from the session BEFORE doing the redirect, so the CMS site filter is forced to determine the CMS site once again.

    OR:

    Replace the b2b site with the b2c CMS site in the session when logging off. Then do the redirect.


    Check these classes:

    my.storefront.filters.cms.CMSSiteFilter

    especially the method: processNormalRequest

    de.hybris.platform.acceleratorcms.context.impl.DefaultContextInformationLoader#initializeSiteFromRequest