The store and country pickers allow the customer to switch between the ATG Store US, ATG Store Germany, and ATG Home sites:
The store picker renders links to affiliated sites that share a shopping cart. Commerce Reference Store has two affiliated sites, ATG Store US and ATG Home, that share a shopping cart.
The country picker renders links to regional peers of the same site. Commerce Reference Store has two regional peer sites, ATG Store US and ATG Store Germany.
If, in the current site context, a picker doesn’t have any sites to display, the picker won’t be rendered. For example, ATG Store Germany does not share its shopping cart with any other affiliated sites, so when ATG Store Germany is the current site, the store picker is not rendered.
To add controls that change site context, you must retrieve a list of site IDs for the sites to which you want to provide switching controls. Commerce Reference Store uses the /atg/dynamo/droplet/multisite/SharingSitesDroplet
to retrieve these IDs:
For the store picker, Commerce Reference Store passes
atg.ShoppingCart
as the shareable type ID to theSharingSitesDroplet
, so that the droplet returns all sites that share a shopping cart with the current site. For example, if ATG Store US is the current site,SharingSitesDroplet
returns ATG Home, and vice versa.For the country picker, Commerce Reference Store passes
atg.RelatedRegionalStores
as the shareable type ID, so that theSharingSitesDroplet
returns all sites that are in a Related Regional Stores sharing group with the current site. For example, if ATG Store US is the current site, the droplet returns ATG Store Germany, and vice versa.
After you have retrieved a list of site IDs, you render links to the sites associated with those IDs. The store.war/navigation/gadgets/sites.jsp
gadget, shown below, uses the /atg/dynamo/droplet/multisite/SiteLinkDroplet
to build the links that are included in the Store picker.
<dsp:page> <dsp:importbean bean="/atg/dynamo/droplet/multisite/SharingSitesDroplet"/> <dsp:importbean bean="/atg/dynamo/droplet/ForEach"/> <dsp:importbean bean="/atg/multisite/Site" var="currentSite"/> <%-- SharingSitesDroplet returns all the sharing sites within the given site group. If the siteId is not provided as an input parameter, it will be retrieved from the SiteContext. Similarly, the ShareableTypeId may be provided as an optional input parameter. The droplet is used here to return all the sites which have the atg.ShoppingCart sharable type with the current site, these are stores which share the same cart. --%> <dsp:droplet name="SharingSitesDroplet" shareableTypeId="atg.ShoppingCart" var="sharingSites"> <dsp:oparam name="output"> <%-- Ensure we have more than 1 site --%> <c:if test="${fn:length(sharingSites.sites) > 1}"> <dl id="atg_store_sites"> <dt> <%-- Display the Sites text --%> <fmt:message key= "navigation_internationalStores.internationalStoresTitle"/> <fmt:message key="common.labelSeparator"/> </dt> <%-- ForEach droplet renders the open parameter output for each element in its array input parameter. For each site found render a link to the site. --%> <dsp:droplet name="ForEach" array="${sharingSites.sites}" sortProperties="-name" var="current"> <dsp:oparam name="output"> <dsp:setvalue param="site" value="${current.element}"/> <dsp:getvalueof var="siteName" param="site.name"/> <dsp:getvalueof var="siteId" param="site.id"/> <%-- Display a link to the other sites --%> <dd class="<crs:listClass count="${current.count}" size="${current.size}" selected="${siteId == currentSite.id}" />"> <c:choose> <%-- Display the current site name as text --%> <c:when test="${siteId == currentSite.id}"> <dsp:valueof value="${siteName}" /> </c:when> <%-- Otherwise generate a link to the site --%> <c:otherwise> <dsp:include page="/global/gadgets/crossSiteLinkGenerator.jsp"> <dsp:param name="siteId" value="${siteId}"/> <dsp:param name="customUrl" value="/"/> </dsp:include> <dsp:a href="${siteLinkUrl}" title="${siteName}"> <c:out value="${siteName}"/> </dsp:a> </c:otherwise> </c:choose> </dd> </dsp:oparam> </dsp:droplet> </dl> </c:if> </dsp:oparam> </dsp:droplet> </dsp:page>
The store.war/navigation/gadgets/regions.jsp
gadget uses similar code to render the country picker:
<dsp:page> <dsp:importbean bean="/atg/dynamo/droplet/ComponentExists"/> <dsp:importbean bean="/atg/dynamo/droplet/ForEach" /> <dsp:importbean bean="/atg/dynamo/droplet/multisite/SharingSitesDroplet" /> <dsp:importbean bean="/atg/multisite/Site" var="currentSite"/> <dsp:importbean bean="/atg/store/droplet/DisplayCountryDroplet"/> <%-- ComponentExists droplet conditionally renders one of its output parameters depending on whether or not a specified Nucleus path currently refers to a non-null object. It it used to query whether a particular component has been instantiated, in this case the InternationalStore. If the InternationalStore component has been instantiated then we render the alternate regions. --%> <dsp:droplet name="ComponentExists" path="/atg/modules/InternationalStore"> <dsp:oparam name="true"> <%-- SharingSitesDroplet returns all the sharing sites within the given site group. If the siteId is not provided as an input parameter, it will be retrieved from the SiteContext. Similarly, the ShareableTypeId may be provided as an optional input parameter. The droplet is used here to return all the sites which have the crs.RelatedRegionalStores sharable type with the current site, these are the regional stores. --%> <dsp:droplet name="SharingSitesDroplet" shareableTypeId="crs.RelatedRegionalStores" var="sharingSites"> <dsp:oparam name="output"> <dsp:getvalueof var="sites" param="sites"/> <%-- Ensure we have stores in different regions --%> <c:if test="${fn:length(sharingSites.sites) > 1}"> <dl id="atg_store_regions"> <%-- Display the Country text --%> <dt> <fmt:message key="navigation_internationalStores.RegionsTitle"/> <fmt:message key="common.labelSeparator"/> </dt> <%-- ForEach droplet renders the open parameter output for each element in its array input parameter. For every regional site render a link to it. --%> <dsp:droplet name="ForEach" array="${sharingSites.sites}" var="current"> <dsp:oparam name="output"> <dsp:setvalue param="site" value="${current.element}"/> <dsp:getvalueof var="siteName" param="site.name"/> <dsp:getvalueof var="siteId" param="site.id"/> <dsp:getvalueof var="siteDefaultCountry" param="site.defaultCountry"/> <dsp:getvalueof var="siteDefaultLanguage" param="site.defaultLanguage"/> <%-- DisplayCountryDroplet takes a locale language key and country code and returns the corresponding country display name in the user's locale. --%> <dsp:droplet name="DisplayCountryDroplet" countryCode="${siteDefaultCountry}" language="${siteDefaultLanguage}" var="siteCountry"> <dsp:oparam name="output"> <c:set var="countryName" value="${siteCountry.displayCountryName}"/> </dsp:oparam> </dsp:droplet> <%-- Display a link to the related regional store --%> <dd class="<crs:listClass count="${current.count}" size="${current.size}" selected="${siteId == currentSite.id}" />"> <c:choose> <%-- Display the current region name as text --%> <c:when test="${siteId == currentSite.id}"> <dsp:valueof value="${countryName}" /> </c:when> <%-- Otherwise generate a link to the related store --%> <c:otherwise> <dsp:include page= "/global/gadgets/crossSiteLinkGenerator.jsp"> <dsp:param name="siteId" value="${siteId}"/> <dsp:param name="customUrl" value="/"/> </dsp:include> <dsp:a href="${siteLinkUrl}" title="${countryName}"> <c:out value="${countryName}"/> </dsp:a> </c:otherwise> </c:choose> </dd> </dsp:oparam> </dsp:droplet> </dl> </c:if> </dsp:oparam> </dsp:droplet> </dsp:oparam> </dsp:droplet> </dsp:page>
For details on the SharingSitesDroplet
and SiteLinkDroplet
components, see the ATG Page Developer's Guide.