The next code sample is also a modified version of the crossSiteLinkGenerator.jsp page. It uses SiteIdForCatalogItem in conjunction with SiteLinkDroplet to generate a URL that follows this pattern:
production-URL/product-template/product-ID
For example:
/crs/storeus/browse/productDetailsSingleSku.jsp?productId=xprod200The product template that gets used depends on the product you are creating a link for, hence, the dynamic nature of this example. In the URL above, /crs/storeus is the production-URL, /browse/productDetailsSingleSku.jsp is the product-template and ?productId=xprod200 is the product-ID. Here is the code sample:
<dsp:getvalueof var="product" param="product"/>
<dsp:droplet name="/atg/commerce/multisite/SiteIdForCatalogItem"
item="${product}" var="siteIdForCatalogItem">
<dsp:oparam name="output">
<%-- Pass the site ID and the product's template path to SiteLinkDroplet to
get a site-specific URL to the product template. --%>
<dsp:getvalueof var="urlToUpdate" param="product.template.url"/>
<dsp:droplet name="/atg/dynamo/droplet/multisite/SiteLinkDroplet"
siteId="${siteIdForCatalogItem.siteId}"
path="${urlToUpdate}" var="siteLink">
<dsp:oparam name="output">
<%-- Render the generated URL to the product template, appended with
the product ID. --%>
<dsp:a href="${siteLink.url}">
<dsp:param name="productId" param="product.repositoryId"/>
<dsp:valueof param="product.displayName"/>
</dsp:a>
</dsp:oparam>
</dsp:droplet>
</dsp:oparam>
</dsp:droplet>This code sample resolves the various portions of the URL as follows:
The
SiteIdForCatalogItemdroplet determines the best site ID to use for the product.The
SiteLinkDropletuses thesiteIdreturned bySiteIdForCatalogItemto determine which site it is building a URL for, and then it retrieves theproduction-URLportion of the URL from theproductionURLproperty for that site. In our example, the value ofproductionURLis/crs/storeus. Note that, in this example,productionURLdoes not contain domain information, so the URL thatSiteLinkDropletproduces also does not include this information. Consequently, the browser uses the current page’s protocol, domain, and port for the link.The
product-templateportion comes from the product’sproduct.template.urlproperty, which is stored in theurlToUpdatevariable and passed toSiteLinkDropletin itspathattribute.SiteLinkDropletgenerates a URL comprised of the production URL and product template and stores it in thesiteLinkvariable (this variable holds the EL accessible output parameters and parameter values forSiteLinkDroplet). The JSP then appends the?productId=productIDportion to the URL using this statement:<dsp:param name="productId" param="product.repositoryId"/>
Additional Notes:
In some instances, you want your application to render product links to other sites (for example, cross sells). In other instances, changing the site context is inappropriate so, while you may be displaying products from other sites, you should not render them as links to other sites (for example, order confirmation).
For more details on the
SiteLinkDroplet,SiteIdForItem, andSiteIdForCatalogItemservlet beans, see the Page Developer's Guide.crossSiteLinkGenerator.jspis a Commerce Reference Store gadget that simplifies adding cross-site functionality to many locations and includes logic for adding cross-site links in a variety of circumstances.The display name in the Oracle Commerce Business Control Center for the site configuration’s
productionURLproperty is Site Base URL.

