Code to Filter Catalog Data for a Particular Language

The product catalog provides support for storing language-specific properties. You can retrieve these properties by setting the language setting for an instance of a product catalog before you display the catalog information.

The following code example demonstrates one way of retrieving catalog data for a particular language. The ASP-Based Catalog Sitelet and ASP.NET-Based Catalog Sitelet in the SDK provide a more complete example of how to use the product catalog multilingual support.

Ee799871.note(en-US,CS.20).gifNote

  • Searching for Unicode text in a catalog requires a modified syntax. SQL requires that Unicode strings be identified with an "N" prefix. This is a problem in parameter searches as only part of the query is Unicode and Commerce Server cannot automatically supply the prefix. For example, a user requests products that match [ISBN] like "<Kanji string>". The SQL query for this search would contain a string like this "(([ISBN] like ''%Kanji string%''))". This query would not return the wanted results because the Kanji string would not be interpreted as Unicode. Instead, the user needs to specify [ISBN] like N"<Kanji string>" to obtain the wanted results.

The following sample includes an HTML form for selecting a particular language. The Action element for the form posts the form date to the Catman.asp file. The Catman.asp file performs the following operations:

  • Creates an instance of the CatalogManager object
  • Retrieves the catalog named "Adventure Works Catalog"
  • Sets the display language to the language selected in the form
  • Retrieves the products for the "Sleeping Bags" category
  • Displays the descriptions of the products in the "Sleeping Bags" category in the selected language

Form to select the language

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>
<Form ID="setlang" Action = "catman.asp" Method = "Post">
<SELECT id=select1 name=Lang>
<OPTION value=fr-FR>French</OPTION>
<OPTION value=en-US>English</OPTION>
<OPTION value=de-DE>German</OPTION></SELECT>

<Input Type=submit>
</Form> 

</BODY>
</HTML>

Catman.asp

<html>
<body>
<%
dim oCatMan
dim oProdCat
dim oProducts
dim sConnStr
dim sCatname
dim sCatagoryname
dim sLang
 
'Instantiate Catalog Manager and setup string variables
Set oCatMan = Server.CreateObject("Commerce.CatalogManager")
sConnStr = "Provider=SQLOLEDB.1;Integrated Security='SSPI';Initial Catalog=Retail_Commerce;Data Source=Myserver;Network Library=dbmssocn;"
sCatname = "Adventure Works Catalog"
sCategoryname = "SleepingBags"
sLang = Request.Form ("Lang")
 
'Initialize the Catalog Manager, set the display language and get some products
oCatMan.Initialize sConnStr, True
Set oProdCat = oCatMan.GetCatalog(sCatname)
oProdCat.Language = sLang
Set oProducts = oProdCat.GetCategory(sCategoryname).Products
 
'Display the product description 
Do While Not oProducts.EOF
  Response.Write oProducts("Description") & "<BR>"
  oProducts.MoveNext ()
Loop
 
%>
</body>
</html>

Copyright © 2005 Microsoft Corporation.
All rights reserved.