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=xprod200
The 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
SiteIdForCatalogItem
droplet determines the best site ID to use for the product.The
SiteLinkDroplet
uses thesiteId
returned bySiteIdForCatalogItem
to determine which site it is building a URL for, and then it retrieves theproduction-URL
portion of the URL from theproductionURL
property for that site. In our example, the value ofproductionURL
is/crs/storeus
. Note that, in this example,productionURL
does not contain domain information, so the URL thatSiteLinkDroplet
produces also does not include this information. Consequently, the browser will use the current page’s protocol, domain, and port for the link.The
product-template
portion comes from the product’sproduct.template.url
property, which is stored in theurlToUpdate
variable and passed toSiteLinkDroplet
in itspath
attribute.SiteLinkDroplet
generates a URL comprised of the production URL and product template and stores it in thesiteLink
variable (this variable holds the EL accessible output parameters and parameter values forSiteLinkDroplet
). The JSP then appends the?productId=
productID
portion to the URL using this statement:<dsp:param name="productId" param="product.repositoryId"/>
Additional Notes:
In some instances, you will 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
, andSiteIdForCatalogItem
servlet beans, see the ATG Page Developer's Guide.crossSiteLinkGenerator.jsp
is 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 Business Control Center for the site configuration’s
productionURL
property is Site Base URL.