Example: e-Marketing Spot

The following code comes from the eMarketingSpotDisplay.jsp file located in the /WC_installdir/samples/Snippets/web/Marketing/Campaigns folder.

<%--
*****
* In the default "Consumer Direct" store, this file is included into 
* the OrderItemDisplay.jsp and SidebarDisplay.jsp to display e-Marketing 
* Spots in the Shopping Cart page and in the sidebar of the store pages.
*
* This eMarketingSpot.jsp is built by customizing the eMarketingSpot.jsp 
* sample snippet to fit the layout and flow of the ConsumerDirect store.
*
* This e-Marketing Spot code supports all types of Web activities:
* - Products, items and category suggestions.
* - Content - Awareness advertisements
* - Discount advertisements
* - Coupon advertisements
* - Merchandising Association - cross-sell, up-sell, accessories.
*
* If you intend to display only one type of Web activity in your 
* e-Marketing Spot, sections of the code that will not be used can be 
* removed.
*
* Parameters
* -emsName
* This file can be reused in different pages of the store by including it 
* and giving a unique value for emsName, which should match exactly with an 
* e-Marketing Spot name defined in the WebSphere Commerce Accelerator.
*
* -catalogId
* The catalogId is required to build proper the proper URL.
*
* -maxNumDisp
* This value is used to set the maximum number of assets to display in an 
* e-Marketing Spot. If this parameter is omitted, or is <0, then the default 
* values will be used.
* The default values are
* - 4 - maximumNumberOfCatalogEntries
* - 4 - maximumNumberOfCategories
* - 3 - maximumNumberOfCollateral
* - 4 - maximumNumberOfAssociateCatalogEntries
*
* -maxItemsInRow
* This value is used to set the maximum number of CatalogEntries, Categories, 
* and AssociateCatalogEntries assets to display in a row. If this parameter is 
* omitted, or is <0, then the default value of 4 will be used.
*
* -maxColInRow
* This value sets the maximum number of Collateral assets to display in a row. 
* If this parameter is omitted, or is <0, then the default value of 3 will be 
* used.
*
*
* This is an example of how this file could be included into a page:
* <c:import url="${jspStoreDir}include/eMarketingSpotDisplay.jsp">
* <c:param name="emsName" value="ShoppingCartPage" />
* <c:param name="MaxNumDisp" value="8" />
* <c:param name="catalogId" value="${WCParam.catalogId}" />
* <c:param name="maxItemsInRow" value="4" />
* <c:param name="maxColInRow" value="3" />
* </c:import>
* If the parameters MaxNumDisp, maxItemsInRow, or maxColInRow are not provided, 
* the default values are used.
*****
--%>

<!-- Start- JSP File Name: eMarketingSpotDisplay.jsp -->

<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://commerce.ibm.com/base" prefix="wcbase" %>
<%@ taglib uri="flow.tld" prefix="flow" %>
<%@ include file="JSTLEnvironmentSetup.jspf"%>


<%--
The e-Marketing Spot requires a proper value for the emsName parameter, which 
is the exact name for an e-Marketing Spot as defined in the WebSphere Commerce 
Accelerator.
--%>


<c:if test="${!empty param.emsName}">

<%-- create an e-Marketing Spot --%>
<wcbase:useBean id="eMarketingSpot" 
   classname="com.ibm.commerce.marketing.beans.EMarketingSpot">

<%-- set the name for the e-Marketing Spot --%>
<c:set target="${eMarketingSpot}" property="name" value="${param.emsName}" />

<%--
***
* If the e-Marketing Spot is located in one of the product display pages and 
* the upsell, cross-sell, or accessory is to be based on the product being 
* displayed in the same page as the e-Marketing Spot, then the 
* sourcecatalogEntryId should be set to the productId of the current page. If 
* the upsell, cross-sell, or accessory is to be based on the contents of the 
* shopping cart or customer's purchase history, setting this value is not 
* necessary.
***
--%>
<c:if test="${!empty productId}">
<c:set value="${productId}" target="${eMarketingSpot}" 
   property="sourceCatalogEntryId" />
</c:if>

<%-- Set the ID of the catalog that the customer is currently viewing. --%>
<c:set value="${param.catalogId}" target="${eMarketingSpot}" 
   property="currentCatalogId" />

<%--
***
* Set the maximum number of return objects for each return type of the 
* e-Marketing Spot. If a parameter was passed in from the calling JSP, use 
* that value. If not, set the default to 4 catalog entries, 4 categories, 1 
* content, and 4 associate catalog entries. Note that  if the 
* parameter is passed from the calling JSP, that value will apply for all four 
* types of assets - CatalogEntries, Categories, Collateral, and 
* AssociateCatalog Entries. If you want to specify different maximum numbers 
* for each type, change the code to accept four separate values as parameters, 
* or change the default values here.
***
--%>
<c:choose>
<c:when test="${param.maxNumDisp>0}">
<c:set value="${param.maxNumDisp}" target="${eMarketingSpot}" 
   property="maximumNumberOfCatalogEntries" />
<c:set value="${param.maxNumDisp}" target="${eMarketingSpot}" 
   property="maximumNumberOfCategories" />
<c:set value="${param.maxNumDisp}" target="${eMarketingSpot}" 
   property="maximumNumberOfCollateral" />
<c:set value="${param.maxNumDisp}" target="${eMarketingSpot}" 
   property="maximumNumberOfAssociateCatalogEntries" />
</c:when>
<c:otherwise>
<c:set value="4" target="${eMarketingSpot}" 
   property="maximumNumberOfCatalogEntries" />
<c:set value="4" target="${eMarketingSpot}" 
   property="maximumNumberOfCategories" />
<c:set value="3" target="${eMarketingSpot}" 
   property="maximumNumberOfCollateral" />
<c:set value="4" target="${eMarketingSpot}" 
   property="maximumNumberOfAssociateCatalogEntries" />
</c:otherwise>
</c:choose>

</wcbase:useBean>
<%--
***
* Set the maximum number of return objects to be displayed in one row of the
* e-Marketing Spot. If the number of objects is exceeded, the remainder will wrap 
* to the next line. If a parameter was passed in from the calling JSP, use that 
* value. If not, set the default to 4. Note that  if the parameter is passed from 
* the calling JSP, that value will apply for the three types of assets - 
* CatalogEntries, Categories, and AssociateCatalog Entries. If you want to specify 
* different maximum numbers per row for each type, change the code to accept four 
* separate values as parameters, or set maxInRow to a different value in each 
* block of the page's code.
***
--%>
<c:choose>
<c:when test="${param.maxItemsInRow>0}">
<c:set var="maxInRow" value="${param.maxItemsInRow}" />
</c:when>
<c:otherwise>
<c:set var="maxInRow" value="4" />
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${param.maxColInRow>0}">
<c:set var="maxColInRow" value="${param.maxColInRow}" />
</c:when>
<c:otherwise>
<c:set var="maxColInRow" value="3" />
</c:otherwise>
</c:choose>

<%--
The following two lines determine the widths of each display column:
- 'clmwidth' is the width of columns for displaying products, items, bundles, 
  kits, and categories.
- 'colwidth' is the width of columns for displaying Image and Flash types of 
  content.
--%>
<c:set var="clmwidth" value="${100%maxInRow}"/>
<c:set var="colwidth" value="${100%maxColInRow}"/>

<%--
If this e-Marketing Spot has a Web activity scheduled for it, and has objects 
to display, display the heading for the e-Marketing Spot. This text will not 
display if there is only content in this e-Marketing Spot.
--%>
<c:if test="${eMarketingSpot.containAssociateCatalogEntries || 
   eMarketingSpot.containCatalogEntries ||eMarketingSpot.containCategories}">
<table id="WC_eMarketingSpotDisplay_Table_1">
<tr>
<td align="left" valign="middle" colspan="<c:out value="${maxInRow}"/>" 
   id="WC_eMarketingSpotDisplay_TableCell_1">
<font class="textCustomColor"><fmt:message key="SUGGESTION" 
   bundle="${storeText}" /></font></td>
</tr>
</table>

<c:set var="itemsInRow" value="0"/>

<table id="WC_eMarketingSpotDisplay_Table_2">
<%--
*****
* Start: AssociateCatalogEntries
* The following block is used to display the up-sell, cross-sell, or accessory
* catalog entries associated with this e-Marketing Spot.
*****
--%>
<c:if test="${eMarketingSpot.containAssociateCatalogEntries}">
<c:forEach items="${eMarketingSpot.associateCatalogEntries}" var="catEntry" 
   varStatus="status">
<c:if test="${itemsInRow % maxInRow==0 }">
<tr>
</c:if>
<c:set var="itemsInRow" value="${itemsInRow+1}"/>
<c:set value="${catEntry.campaignInitiative.entityExperimental}" 
   var="marketing_experimentalCampaign" />
<c:url value="ProductDisplay" var="TargetURL">
<c:param name="catalogId" value="${param.catalogId}" />
<c:param name="productId" value="${catEntry.catalogEntryID}" />
<c:param name="storeId" value="${WCParam.storeId}" />
<c:param name="langId" value="${langId}" />
</c:url>
<c:url value="ClickInfo" var="ClickInfoURL">
<c:choose>
<c:when test="${marketing_experimentalCampaign}">
<c:param name="evtype" value="ExpCpgnClick" />
<c:param name="experimentId" value="${catEntry.campaignInitiative.experimentId}" />
<c:param name="testElementId" value="${catEntry.campaignInitiative.viewedElementId}" />
</c:when>
<c:otherwise>
<c:param name="evtype" value="CpgnClick" />
<c:param name="mpe_id" value="${eMarketingSpot.id}" />
<c:param name="intv_id" value="${catEntry.initiativeId}" />
</c:otherwise>
</c:choose>
<c:param name="URL" value="${TargetURL}" />
</c:url>
<td width="<c:out value="${clmwidth}"/>" align="center" valign="top" 
   id="WC_eMarketingSpotDisplay_TableCell_2_<c:out value="${status.count}" />">
<c:set var="useClickInfoURL" value="true"/>
<%@ include file="../Snippets/ReusableObjects/CatalogEntryThumbnailDisplay.jspf" %>
</td>
<%--
Draw another row if the number of items or products displayed on this row is
greater than the number specified by MaxInRow.
--%>
<c:if test="${itemsInRow % maxInRow==0 }">
</tr>
</c:if>

</c:forEach>
</c:if>
<%--
***
* End: AssociateCatalogEntries
***
--%>


<%--
*****
* Start: CatalogEntries
* The following block is used to display the catalog entries associated 
* with this e-Marketing Spot through a suggestive sell Web activity.
**
--%>
<c:if test="${eMarketingSpot.containCatalogEntries}">
<c:forEach items="${eMarketingSpot.catalogEntries}" var="catEntry" 
   varStatus="status">
<c:if test="${itemsInRow % maxInRow==0}" >
<tr>
</c:if>
<c:set var="itemsInRow" value="${itemsInRow+1}"/>
<c:set value="${catEntry.campaignInitiative.entityExperimental}" 
   var="marketing_experimentalCampaign" />
<c:url value="ProductDisplay" var="TargetURL">
<c:param name="catalogId" value="${param.catalogId}" />
<c:param name="productId" value="${catEntry.catalogEntryID}" />
<c:param name="storeId" value="${WCParam.storeId}" />
<c:param name="langId" value="${langId}" />
</c:url>
<c:url value="ClickInfo" var="ClickInfoURL">
<c:choose>
<c:when test="${marketing_experimentalCampaign}">
<c:param name="evtype" value="ExpCpgnClick" />
<c:param name="experimentId" 
   value="${catEntry.campaignInitiative.experimentId}" />
<c:param name="testElementId" 
   value="${catEntry.campaignInitiative.viewedElementId}" />
</c:when>
<c:otherwise>
<c:param name="evtype" value="CpgnClick" />
<c:param name="mpe_id" value="${eMarketingSpot.id}" />
<c:param name="intv_id" value="${catEntry.initiativeId}" />
</c:otherwise>
</c:choose>
<c:param name="URL" value="${TargetURL}" />
</c:url>
<td width="<c:out value="${clmwidth}"/>" align="center" valign="top" 
   id="WC_eMarketingSpotDisplay_TableCell_3_<c:out value="${status.count}" />">
<c:set var="useClickInfoURL" value="true"/>
<%@ include file="../Snippets/ReusableObjects/CatalogEntryThumbnailDisplay.jspf" %>
</td>
<%--
Draw another row if the number of items or products displayed on this 
row is greater than the number specified by MaxInRow.
--%>
<c:if test="${itemsInRow % maxInRow==0 }">

</tr>
</c:if>


</c:forEach>

</c:if>
<%--
***
* End: CatalogEntries
***
--%>




<%--
***
* Start: Categories
* The following block is used to display categories associated with this 
* e-Marketing Spot through Category Recommendation Web activities.
**
--%>
<c:if test="${eMarketingSpot.containCategories}">

<c:forEach items="${eMarketingSpot.categories}" var="CategoryObj" 
   varStatus="status">

<c:if test="${(itemsInRow) % maxInRow==0 }">
<tr>
</c:if>
<c:set var="itemsInRow" value="${itemsInRow+1}"/>
<c:set value="${CategoryObj.campaignInitiative.entityExperimental}" 
   var="marketing_experimentalCampaign" />

<c:url value="CategoryDisplay" var="TargetURL">
<c:param name="categoryId" value="${CategoryObj.categoryId}" />
<c:param name="catalogId" value="${CategoryObj.catalogId}" />
<c:param name="storeId" value="${WCParam.storeId}" />
<c:param name="langId" value="${langId}" />
</c:url>
<c:url value="ClickInfo" var="ClickInfoURL">
<c:choose>
<c:when test="${marketing_experimentalCampaign}">
<c:param name="evtype" value="ExpCpgnClick" />
<c:param name="experimentId" 
   value="${CategoryObj.campaignInitiative.experimentId}" />
<c:param name="testElementId" 
   value="${CategoryObj.campaignInitiative.viewedElementId}" />
</c:when>
<c:otherwise>
<c:param name="evtype" value="CpgnClick" />
<c:param name="mpe_id" value="${eMarketingSpot.id}" />
<c:param name="intv_id" value="${CategoryObj.initiativeId}" />
</c:otherwise>
</c:choose>
<c:param name="URL" value="${TargetURL}" />
</c:url>

<td width="<c:out value="${clmwidth}"/>" align="center" valign="top" 
   id="WC_eMarketingSpotDisplay_TableCell_4_<c:out value="${status.count}" />">
<%--
***
* Start: Category Thumbnail Display
* If there is a thumbnail image for this category, display it.
***
--%>
<c:if test="${!empty CategoryObj.description.thumbNail}">
<div align="center">
<a href="<c:out value="${ClickInfoURL}"/>" 
   name="WC_eMarketingSpotDisplay_ImageLink_4_<c:out value="${status.count}" />" 
   id="WC_eMarketingSpotDisplay_ImageLink_4_<c:out value="${status.count}" />">
<img src="<c:out value="${CategoryObj.objectPath}${CategoryObj.description.thumbNail}"/>"
alt="<c:out value="${CategoryObj.description.name}" />" border="0" />
</a>
</div>
</c:if>
<%--
***
* End: CatalogEntry Display Thumbnail
***
--%>
<%-- Display the link to the category being recommended. --%>
<div>
<br/>
<a href='<c:out value="${ClickInfoURL}"/>' 
   name='WC_eMarketingSpotDisplay_Link_4_<c:out value="${status.count}" />' 
   id='WC_eMarketingSpotDisplay_Link_4_<c:out value="${status.count}" />'>
<c:out value=" ${CategoryObj.description.name}" escapeXml="false" /> 
<fmt:message key="CATEGORY" bundle="${storeText}" />
</a>
</div>

<%--
***
* Start: Category discount
***
--%>
<%-- Remove the exiting discounts, otherwise wcbase:useBean or 
jsp:useBean will not instantiate the object.
--%>
<c:remove var="categoryDiscounts"/>
<wcbase:useBean id="categoryDiscounts" 
   classname="com.ibm.commerce.fulfillment.beans.CalculationCodeListDataBean">
<c:set property="catalogGroupId" value="${CategoryObj.categoryId}" 
   target="${categoryDiscounts}" />
<c:set property="includeParentCategory" value="true" target="${categoryDiscounts}"/>

<%-- UsageId for discount is -1 --%>
<c:set property="calculationUsageId" value="-1" target="${categoryDiscounts}" />
</wcbase:useBean>

<c:if test="${!empty categoryDiscounts}">
<c:forEach var="discountEntry" items="${categoryDiscounts.calculationCodeDataBeans}" 
   varStatus="discountCounter">
<br/>
<c:url var="DiscountDetailsDisplayViewURL" value="DiscountDetailsDisplayView">
<c:param name="code" value="${discountEntry.code}" />
<c:param name="langId" value="${langId}" />
<c:param name="storeId" value="${WCParam.storeId}" />
<c:param name="catalogId" value="${WCParam.catalogId}" />
<%-- This category ID will be used to retrieve the category 
   information on DiscountDetailDisplay.jsp --%>
<c:param name="categoryId" value="${CategoryObj.categoryId}"/>

</c:url>
<span class="discount">
<img src="<c:out value="${jspStoreImgDir}" />images/Discount_star.gif" 
  ${discountEntry.descriptionString}" />"/>&nbsp;
<a class="discount" href='<c:out value="${DiscountDetailsDisplayViewURL}" />' 
   id="WC_EMarketingSopt_Link_CategoryDiscount_1_<c:out 
   value="${discountCounter.count}"/>"><c:out 
   value="${discountEntry.descriptionString}" escapeXml="false" /></a>
</span>
<br/>

</c:forEach>
</c:if>

<%--
***
* End of Category Discount
***
--%>
</td>

<c:if test="${(itemsInRow) % maxInRow==0 }">
<%--
Draw another row if the number of items or products displayed on this 
row is greater than the number specified by MaxInRow.
--%>
</tr>
</c:if>



</c:forEach>

</c:if>

<%-- Close out remaining space on the last row. --%>
<c:if test="${(itemsInRow % maxInRow )!=0}">
<td colspan="<c:out value="${maxInRow- (itemsInRow % maxInRow)}" />" 
   id="WC_eMarketingSpotDisplay_TableCell_5"><br/></td>
</tr>
</c:if>



<%--
***
* End: Categories
***
--%>
</table>
</c:if>


<%--
***
* Start: Collateral
* The following block is used to display the content associated with 
* this e-Marketing Spot through Awareness Advertisement Web activities.
***
--%>
<c:if test="${eMarketingSpot.containCollateral}">
<table id="WC_eMarketingSpotDisplay_Table_3">
<c:set var="collateralInRow" value="0"/>


<c:forEach items="${eMarketingSpot.collateral}" var="CollateralObj" 
   varStatus="status">
<%--
Content can be of an Image, a Flash animation, or Text. 
--%>

<c:if test="${collateralInRow % maxColInRow==0 }">
<tr>
</c:if>
<c:set var="collateralInRow" value="${collateralInRow+1}"/>
<c:set value="${CollateralObj.campaignInitiative.entityExperimental}" 
   var="marketing_experimentalCampaign" />

<c:url value="ClickInfo" var="ClickInfoURL">
<c:choose>
<c:when test="${marketing_experimentalCampaign}">
<c:param name="evtype" value="ExpCpgnClick" />
<c:param name="experimentId" 
   value="${CollateralObj.campaignInitiative.experimentId}" />
<c:param name="testElementId" 
   value="${CollateralObj.campaignInitiative.viewedElementId}" />
</c:when>
<c:otherwise>
<c:param name="evtype" value="CpgnClick" />
<c:param name="mpe_id" value="${eMarketingSpot.id}" />
<c:param name="intv_id" value="${CollateralObj.initiativeId}" />
</c:otherwise>
</c:choose>
<c:param name="storeId" value="${WCParam.storeId}" />
<c:param name="langId" value="${langId}" />
<c:param name="URL" value="${CollateralObj.urlLink}" />
<c:param name="catalogId" value="${WCParam.catalogId}" />
</c:url>

<%--
This choose block is used for properly displaying the collateral
depending on the type, that is, Image or Flash. Text content is
handled in the next block of code.
--%>
<c:choose>
<c:when test="${CollateralObj.typeName == 'File'}">

<c:set var="content_AttachBean"
value="${CollateralObj.attachmentDataBean}" />


<c:choose>
<c:when test="${CollateralObj.mimeType == 'image'}">
<c:set var="id" value="${status.count}" />
<c:set var="AttachmentDataBean" value="${content_AttachBean}" />
<c:set var="URL" value="${ClickInfoURL}" />
<%@ include file="../Snippets/ReusableObjects/AttachmentDisplay.jspf"%>
<div align="center"><br />
<a href="<c:out value="${ClickInfoURL}"/>"
name="WC_ContentSpotDisplay_Link_6_<c:out value="${status.count}" />"
id="WC_ContentSpotDisplay_Link_6_<c:out value="${status.count}" />">
<c:out value="${CollateralObj.marketingText}" escapeXml="false" />
</a></div>
</c:when>
<c:otherwise>
<c:set var="id" value="${status.count}" />
<c:set var="AttachmentDataBean" value="${content_AttachBean}" />
<%@ include file="../Snippets/ReusableObjects/AttachmentDisplay.jspf"%>
</c:otherwise>
</c:choose>
</c:when>
</c:choose>




<c:if test="${collateralInRow % maxColInRow==0 }">
<%--
Draw another row if the number of collateral displayed on
this row is greater than the number specified by MaxInRow.
--%>
</tr>
</c:if>
</c:forEach>
<%-- Close out remaining space on the last row. --%>

<c:if test="${(collateralInRow % maxColInRow )!= 0}">
<td colspan="<c:out value="${maxColInRow- (collateralInRow % maxColInRow)}" />" 
    id="WC_eMarketingSpotDisplay_TableCell_8">
<br/>
</td>
</tr>
</c:if>


<%--If the content is of type Text, then only one should be displayed per row. --%>

<c:forEach items="${eMarketingSpot.collateral}" var="CollateralObj" 
   varStatus="status">
<c:if test="${CollateralObj.typeName == 'Text'}">
<tr>
<td width="100%" align="left" valign="top" 
   id="WC_eMarketingSpotDisplay_TableCell_7_<c:out value="${status.count}" />">
<br/>
<font class="text"><c:out value="${CollateralObj.marketingText}" 
   escapeXml="false"/></font>
<br/>
</td>
</tr>
</c:if>
</c:forEach>

<%--
***
* End: Collateral
***
--%>
</table>
</c:if>
</c:if>

<!-- End - JSP File Name: eMarketingSpotDisplay.jsp -->