Develop > Presentation layer > Customize promotions > Promotions customization: Management Center > Create a custom promotion type in the Management Center
Create the XSLT template to transform the promotion XML
Create a custom XSLT template to transform the authoring promotion XML to the runtime promotion XML. This transformation takes place when a business user activates a promotion based on the custom promotion type.
Before you begin
Review the following topics to ensure that you understand the role of XSLT templates:
- How promotion data is stored and managed
- Create and registering the XSL template (this is a lesson in a tutorial that provides a downloadable example of an XSLT template and then explains its contents)
The Promotions tool provides a set of default XSLT templates. Each default promotion type defined in the Promotions tool is configured to work with certain templates. When you create a custom promotion type, create a new custom XSLT template; however, you can copy the content of an existing XSLT template into an empty file and then customize only certain sections.
Typically, define a new purchase condition structure for a new promotion type.
To develop a new purchase condition XSLT template, use information you gathered in two previous steps as input, that is:
- The purchase condition section of the runtime promotion XML that you modeled
- The data you determined is required from the Management Center user interface for this particular promotion type
Procedure
- Create the XSLT template for the element of the new promotion type that you are customizing. In most cases, this is the <PurchaseCondition> element.
To use one of the default XSLT templates as a starting point, the templates are stored at this path:
WC_EAR/xml/config/com.ibm.commerce.promotion/template
The following table maps each purchase condition XSLT template to its default promotion type:
XSLT templates mapped to default promotion types
Purchase condition XSLT template Default promotion type OrderPercentOffPurchaseConditionTemplate.xsl Percentage off an order OrderAmountOffPurchaseConditionTemplate.xsl Amount off on order OrderFreeGiftPurchaseConditionTemplate.xsl Free gift with an order ProductAllItemPercentOffPurchaseConditionTemplate.xsl Percentage off the subtotal of catalog entries ProductPerItemPercentOffPurchaseConditionTemplate.xsl Percentage off individual catalog entries ProductPurchaseWithPurchasePercentOffPurchaseConditionTemplate.xsl Buy catalog entry X, get percentage off catalog entry Y ProductSameItemPercentOffPurchaseConditionTemplate.xsl Buy catalog entry X, get additional X at a percentage off ProductAllItemAmountOffPurchaseConditionTemplate.xsl Amount off the subtotal of catalog entries ProductPerItemAmountOffPurchaseConditionTemplate.xsl Amount off individual catalog entries ProductWithFreeGiftPurchaseConditionTemplate.xsl Buy catalog entry X, get catalog entry Y free CategoryAllItemPercentOffPurchaseConditionTemplate.xsl Percentage off the subtotal of catalog entries from a category CategoryPerItemPercentOffPurchaseConditionTemplate.xsl Percentage off individual catalog entries from a category CategorySameItemPercentOffPurchaseConditionTemplate.xsl Buy catalog entries from category X, get additional catalog entries from category X at a percentage off CategoryAllItemAmountOffPurchaseConditionTemplate.xsl Amount off the subtotal of catalog entries from a category CategoryPerItemAmountOffPurchaseConditionTemplate.xsl Amount off individual catalog entries from a category CategoryWithFreeGiftPurchaseConditionTemplate.xsl Buy catalog entries from category X, get catalog entry Y free MultipleItemsPercentOffPurchaseConditionTemplate.xsl Buy A and B, get a percentage off both OrderFixedCostShippingPurchaseConditionTemplate.xsl Fixed price for shipping an order OrderFixedAmountOffShippingPurchaseConditionTemplate.xsl Amount off shipping on an order ProductFixedCostShippingPurchaseConditionTemplate.xls Buy catalog entry X, get shipping at a fixed price CategoryFixedCostShippingPurchaseConditionTemplate.xls Buy catalog entries from category X, get shipping at a fixed price
In addition to the purchase condition XSLT templates, there are three additional XSLT templates. These three templates are used for all default promotion types.
XSLT templates mapped to default promotion types
Purchase condition XSLT template Purpose DefaultTargetingConditionTemplate.xsl Transforms the authoring promotion XML to create the targetingCondition section of the runtime promotion XML. DefaultCustomConditionsTemplate.xsl Transforms the authoring promotion XML to create the customCondition section of the runtime promotion XML. DefaultBasePromotionTemplate.xsl Transforms the authoring promotion XML to create the basePromotion section of the runtime promotion XML.
- Save the custom XSLT template file under the following directory:
WC_EAR/xml/config/com.ibm.commerce.promotion-ext/template
Example
For the custom promotion type, Customers who purchase two dining chairs (FULO-01) qualify to purchase a dining table (FULO-02) at the reduced price of $200, you create a custom XSL template for the <PurchaseCondition> element called ProductPurchaseWithPurchaseFixedCostPurchaseConditionTemplate.xsl. It looks like the following sample:
<?xml version="1.0" encoding="UTF-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- handles purchase condition --> <xsl:template name="PurchaseConditionTemplate" match="/"> <PurchaseCondition impl="com.ibm.commerce.marketing.promotion.condition.PurchaseCondition"> <Pattern impl="com.ibm.commerce.marketing.promotion.condition.Pattern"> <Constraint impl="com.ibm.commerce.marketing.promotion.condition.Constraint"> <WeightedRange impl="com.ibm.commerce.marketing.promotion.condition.WeightedRange"> <LowerBound> <xsl:value-of select="PromotionData/Elements/PurchaseCondition/Purchase/Data/Quantity" /> </LowerBound> <UpperBound> <xsl:value-of select="PromotionData/Elements/PurchaseCondition/Purchase/Data/Quantity" /> </UpperBound> <Weight>1</Weight> </WeightedRange> <FilterChain impl="com.ibm.commerce.marketing.promotion.condition.FilterChain"> <Filter impl="com.ibm.commerce.marketing.promotion.condition.MultiSKUFilter"> <xsl:for-each select="PromotionData/Elements/PurchaseCondition/Purchase/IncludeCatalogEntryIdentifier"> <IncludeCatEntryKey> <xsl:call-template name="CatalogEntryKeyTemplate"> <xsl:with-param name="dn" select="Data/DN" /> <xsl:with-param name="sku" select="Data/SKU" /> </xsl:call-template> </IncludeCatEntryKey> </xsl:for-each> <xsl:for-each select="PromotionData/Elements/PurchaseCondition/Purchase/ExcludeCatalogEntryIdentifier"> <ExcludeCatEntryKey> <xsl:call-template name="CatalogEntryKeyTemplate"> <xsl:with-param name="dn" select="Data/DN" /> <xsl:with-param name="sku" select="Data/SKU" /> </xsl:call-template> </ExcludeCatEntryKey> </xsl:for-each> </Filter> </FilterChain> </Constraint> <Constraint impl="com.ibm.commerce.marketing.promotion.condition.Constraint"> <WeightedRange impl="com.ibm.commerce.marketing.promotion.condition.WeightedRange"> <LowerBound> <xsl:value-of select="PromotionData/Elements/PurchaseCondition/Reward/Data/Quantity" /> </LowerBound> <UpperBound> <xsl:value-of select="PromotionData/Elements/PurchaseCondition/Reward/Data/Quantity" /> </UpperBound> <Weight>1</Weight> </WeightedRange> <FilterChain impl="com.ibm.commerce.marketing.promotion.condition.FilterChain"> <Filter impl="com.ibm.commerce.marketing.promotion.condition.MultiSKUFilter"> <xsl:for-each select="PromotionData/Elements/PurchaseCondition/Reward/IncludeCatalogEntryIdentifier"> <IncludeCatEntryKey> <xsl:call-template name="CatalogEntryKeyTemplate"> <xsl:with-param name="dn" select="Data/DN" /> <xsl:with-param name="sku" select="Data/SKU" /> </xsl:call-template> </IncludeCatEntryKey> </xsl:for-each> <xsl:for-each select="PromotionData/Elements/PurchaseCondition/Reward/ExcludeCatalogEntryIdentifier"> <ExcludeCatEntryKey> <xsl:call-template name="CatalogEntryKeyTemplate"> <xsl:with-param name="dn" select="Data/DN" /> <xsl:with-param name="sku" select="Data/SKU" /> </xsl:call-template> </ExcludeCatEntryKey> </xsl:for-each> </Filter> </FilterChain> </Constraint> </Pattern> <Distribution impl="com.ibm.commerce.marketing.promotion.reward.Distribution"> <Type>Volume</Type> <Base>Quantity</Base> <Currency> <xsl:value-of select="PromotionData/Elements/PurchaseCondition/Data/Currency" /> </Currency> <Range impl="com.ibm.commerce.marketing.promotion.reward.DistributionRange"> <LowerBound>1</LowerBound> <UpperBound>-1</UpperBound> <LowerBoundIncluded>true</LowerBoundIncluded> <UpperBoundIncluded>false</UpperBoundIncluded> <RewardChoice> <Reward impl="com.ibm.commerce.marketing.promotion.reward.DefaultReward"> <AdjustmentFunction impl="com.ibm.commerce.marketing.promotion.reward.AdjustmentFunction"> <FilterChain impl="com.ibm.commerce.marketing.promotion.condition.FilterChain"> <Filter impl="com.ibm.commerce.marketing.promotion.condition.MultiSKUFilter"> <xsl:for-each select="PromotionData/Elements/PurchaseCondition/Reward/IncludeCatalogEntryIdentifier"> <IncludeCatEntryKey> <xsl:call-template name="CatalogEntryKeyTemplate"> <xsl:with-param name="dn" select="Data/DN" /> <xsl:with-param name="sku" select="Data/SKU" /> </xsl:call-template> </IncludeCatEntryKey> </xsl:for-each> <xsl:for-each select="PromotionData/Elements/PurchaseCondition/Reward/ExcludeCatalogEntryIdentifier"> <ExcludeCatEntryKey> <xsl:call-template name="CatalogEntryKeyTemplate"> <xsl:with-param name="dn" select="Data/DN" /> <xsl:with-param name="sku" select="Data/SKU" /> </xsl:call-template> </ExcludeCatEntryKey> </xsl:for-each> </Filter> </FilterChain> <Adjustment impl="com.ibm.commerce.marketing.promotion.reward.FixedCostAdjustment"> <FixedCost> <xsl:value-of select="PromotionData/Elements/PurchaseCondition/Data/FixedCost" /> </FixedCost> <AdjustmentType>IndividualAffectedItems</AdjustmentType> <Currency> <xsl:value-of select="PromotionData/Elements/PurchaseCondition/Data/Currency" /> </Currency> </Adjustment> </AdjustmentFunction> </Reward> </RewardChoice> </Range> <PatternFilter impl="com.ibm.commerce.marketing.promotion.condition.DummyPatternFilter"> </PatternFilter> </Distribution> </PurchaseCondition> </xsl:template> <!-- handles CatalogEntryKey --> <xsl:template name="CatalogEntryKeyTemplate"> <xsl:param name="dn" /> <xsl:param name="sku" /> <CatalogEntryKey> <DN> <xsl:value-of select="$dn" /> </DN> <SKU> <xsl:value-of select="$sku" /> </SKU> </CatalogEntryKey> </xsl:template> </xsl:transform>
Previous topic: Register a serialization JSP file for the new object definition
Next topic: Update the promotion type configuration file