Reputation: 2677
I did read the WebService and Fallback Language topic. But still I have some questions. We want the same as in that topic. We have a couple of webservices (Get categories, get products, etc) where we need to have a fallback language.
What is our case: We have a product with filled names for French and English American, our fallback language is English American. When we call the webservice for getProduct with lang=fr we are getting the French name, so that is OK. When we remove the French name in the HMC we are expecting to get the English American name of the product when we call the getProduct with lang=fr. But we don’t get any name in the response. Why is the fallback mechanism not working?
Now I just read that topic WebService and Fallback Language and as I understand you need to create a MyProductResource class to override the GET method and add :
@GET
public Response getMyProduct()
{
i18nService.setLocalizationFallbackEnabled(true);
return createGetResponse().build();
}
But I need to do the same for the Categories (and may be for even more calls), so for that I need also create a resource class? Why is this so hard and not working 'out-of-the-box'?
Is there a way to change this with a global setting or something like that?
Upvotes: 1
Views: 1824
Reputation: 2677
Solution I used:
Added the following part in the filter-config-v1-spring.xml to the defaultCommerceWebServicesFilterChainListV1
<!-- Custom filter to enable Fallback mechanism -->
<ref bean="languageFallbackFilter"/>
Also after the list add the bean definition
<bean id="languageFallbackFilter" class="b2b.hybris.commercewebservices.filter.LanguageFallbackFilter">
<property name="i18nService" ref="i18nService" />
</bean>
And ofcourse create the class LanguageFallbackFilter
package b2b.hybris.commercewebservices.filter;
import de.hybris.platform.servicelayer.i18n.I18NService;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.web.filter.OncePerRequestFilter;
/**
* This LanguageFallbackFilter will enable the Localization Fallback mechanism
*
*/
public class LanguageFallbackFilter extends OncePerRequestFilter
{
private static final Logger LOG = Logger.getLogger(LanguageFallbackFilter.class);
private I18NService i18nService;
@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
final FilterChain filterChain) throws ServletException, IOException
{
i18nService.setLocalizationFallbackEnabled(true);
filterChain.doFilter(request, response);
}
@Required
public void setI18nService(final I18NService i18nService)
{
this.i18nService = i18nService;
}
}
Upvotes: 3
Reputation: 21
Are you querying the search engine to fetch the results? If yes, there is a configuration at the Facet Search Configuration level - Enabled language fallback mechanism. If no, then you can define a custom filter so that all your web services go through the filter first and then invoke i18nService.setLocalizationFallbackEnabled(true) within your filter.
Upvotes: 2