Crear la plantilla XSLT para transformar el XML de promoción

Cree una plantilla XSLT personalizada para transformar el XML de promoción de autoría en el XML de promoción de tiempo de ejecución. Esta transformación tiene lugar cuando un usuario de negocio activa una promoción basada en su tipo de promoción personalizado.

Antes de empezar

Revise los temas siguientes para asegurarse de que entiende la función de las plantillas XSLT:

Por qué y cuándo se efectúa esta tarea

La herramienta Promociones proporciona un conjunto de plantillas XSLT predeterminadas. Cada tipo de promoción predeterminado definido en la herramienta Promociones está configurado para funcionar con determinadas plantillas. Cuando crea un tipo de promoción personalizado, debe crear una plantilla XSLT personalizada nueva; no obstante, puede copiar el contenido de una plantilla XSLT existente en un archivo vacío y luego personalizar sólo determinadas secciones.
Normalmente, debe definir una nueva estructura de condición de compra para un nuevo tipo de promoción. Para desarrollar una nueva plantilla XSLT de condición de compra, debe utilizar información que ha recopilado en dos pasos anteriores como entrada, es decir:
  • La sección de condición de compra del XML de promoción de tiempo de ejecución que ha modelado
  • Los datos que ha determinado que son necesarios de la interfaz de usuario del Centro de gestión para este tipo de promoción concreto

Procedimiento

  1. Cree la plantilla XSLT para el elemento del nuevo tipo de promoción que está personalizando. En la mayoría de los casos, este es el elemento <PurchaseCondition>.

    Si desea utilizar una de las plantillas XSLT predeterminadas como punto de partida, las plantillas se almacenan en esta vía de acceso:

    workspace_dir/WC/xml/config/com.ibm.commerce.promotion/template

    La tabla siguiente correlaciona cada plantilla XSLT de condición de compra con su tipo de promoción predeterminado:

    Plantillas XSLT correlacionadas con tipos de promoción predeterminados
    Plantilla XSLT de condición de compra Tipo de promoción predeterminado
    CategoryAllItemAmountOffPurchaseConditionTemplate.xsl Importe de descuento en el subtotal de las entradas de catálogo de una categoría
    CategoryAllItemFixedCostPurchaseConditionTemplate.xls Precio fijo en el subtotal de entradas de catálogo de una categoría
    CategoryAllItemPercentOffPurchaseConditionTemplate.xsl Porcentaje de descuento en el subtotal de las entradas de catálogo de una categoría
    CategoryFixedCostShippingPurchaseConditionTemplate.xls Compre las entradas de catálogo de la categoría X y llévese un precio fijo de envío
    CategoryPerItemAmountOffPurchaseConditionTemplate.xsl Importe de descuento en entradas de catálogo individuales de una categoría
    CategoryPerItemFixedCostPurchaseConditionTemplate.xls Precio fijo en entradas de catálogo individuales de una categoría
    CategoryPerItemPercentOffPurchaseConditionTemplate.xsl Porcentaje de descuento en entradas de catálogo individuales de una categoría
    CategoryPurchaseWithPurchasePercentOffPurchaseConditionTemplate.xls Compre entradas de catálogo X y obtenga un porcentaje de descuento en la entrada de catálogo Y
    CategorySameItemPercentOffPurchaseConditionTemplate.xsl Compre entradas de catálogo de la categoría X y obtenga un porcentaje de descuento en entradas de catálogo adicionales de la categoría X
    CategoryWithFreeGiftPurchaseConditionTemplate.xsl Compre entradas de catálogo de categoría X y llévese la entrada de catálogo Y gratis
    MultipleItemsGetYFixedAmountOffPurchaseConditionTemplate.xls Compre A (y B y C), obtenga un importe de descuento Y
    MultipleItemsGetYPercentOffPurchaseConditionTemplate.xls Compre A (y B y C) y obtenga un porcentaje de descuento en Y
    MultipleItemsPercentOffPurchaseConditionTemplate.xsl Compre A y B y obtenga un porcentaje de descuento en ambos
    OrderAmountOffPurchaseConditionTemplate.xsl Importe de descuento en el pedido
    OrderFixedAmountOffShippingPurchaseConditionTemplate.xsl Importe de descuento en el envío de un pedido
    OrderFixedCostShippingPurchaseConditionTemplate.xsl Precio fijo para el envío de un pedido
    OrderFreeGiftPurchaseConditionTemplate.xsl Regalo gratis con un pedido
    OrderPercentOffPurchaseConditionTemplate.xsl Porcentaje de descuento en el pedido
    ProductAllItemAmountOffPurchaseConditionTemplate.xsl Importe de descuento en el subtotal de las entradas de catálogo
    ProductAllItemFixedCostPurchaseConditionTemplate.xls Precio fijo en el subtotal de las entradas de catálogo
    ProductAllItemPercentOffPurchaseConditionTemplate.xsl Porcentaje de descuento en el subtotal de las entradas de catálogo
    ProductFixedCostShippingPurchaseConditionTemplate.xls Compre la entrada de catálogo X y llévese un precio fijo de envío
    ProductPerItemAmountOffPurchaseConditionTemplate.xsl Importe de descuento en entradas de catálogo individuales
    ProductPerItemFixedCostPurchaseConditionTemplate.xls Precio fijo en entradas de catálogo individuales
    ProductPerItemPercentOffPurchaseConditionTemplate.xsl Porcentaje de descuento en entradas de catálogo individuales
    ProductPurchaseWithPurchasePercentOffPurchaseConditionTemplate.xsl Compre la entrada de catálogo X y obtenga un porcentaje de descuento en la entrada de catálogo Y
    ProductSameItemPercentOffPurchaseConditionTemplate.xsl Compre una entrada de catálogo X y llévese otra entrada de catálogo X con un porcentaje de descuento
    ProductWithFreeGiftPurchaseConditionTemplate.xsl Compre la entrada de catálogo X y llévese la entrada de catálogo Y gratis

    Además de las plantillas XSLT de condición de compra, hay tres plantillas XSLT adicionales. Estas tres plantillas se utilizan para todos los tipos de promoción predeterminados.

    Plantillas XSLT correlacionadas con tipos de promoción predeterminados
    Plantilla XSLT de condición de compra Finalidad
    DefaultTargetingConditionTemplate.xsl Transforma el XML de promoción de autoría para crear la sección targetingCondition del XML de promoción de tiempo de ejecución.
    DefaultCustomConditionsTemplate.xsl Transforma el XML de promoción de autoría para crear la sección customCondition del XML de promoción de tiempo de ejecución.
    DefaultBasePromotionTemplate.xsl Transforma el XML de promoción de autoría para crear la sección basePromotion del XML de promoción de tiempo de ejecución.
  2. Guarde su archivo de plantilla XSLT personalizado bajo el siguiente directorio:

    workspace_dir/WC/xml/config/com.ibm.commerce.promotion-ext/template

Ejemplo

Para su tipo de promoción personalizado, Los clientes que compren dos sillas de comedor (FULO-01) cumplen los requisitos para comprar una mesa de comedor (FULO-02) al precio rebajado de 200 euros, cree una plantilla XSL personalizada para el elemento <PurchaseCondition> llamada ProductPurchaseWithPurchaseFixedCostPurchaseConditionTemplate.xsl. Es parecida al ejemplo siguiente:
<?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>
Para hacer que una promoción se aplique al elemento menos caro, sustituya las restricciones existentes en el archivo CategorySameItemPercentOffPurchaseConditionTemplate.xsl por las siguientes restricciones:
Importante: Primero debe habilitar ApplyPromotionOnLowestPricedOrderItemsFirst para que funcionen las restricciones.
<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/Data/BaseQuantity" />
		</LowerBound>
		<UpperBound>
			<xsl:value-of select="PromotionData/Elements/PurchaseCondition/Data/BaseQuantity" />
		</UpperBound>
		<Weight>1</Weight>
	</WeightedRange>
	<FilterChain impl="com.ibm.commerce.marketing.promotion.condition.FilterChain">
		<Filter impl="com.ibm.commerce.marketing.promotion.condition.CategoryFilter">
			<xsl:for-each select="PromotionData/Elements/PurchaseCondition/IncludeCategoryIdentifier">
				<IncludeCategory>
					<xsl:call-template name="CategoryKeyTemplate">
						<xsl:with-param name="dn" select="Data/DN" />
						<xsl:with-param name="name" select="Data/Name" />
					</xsl:call-template>
				</IncludeCategory>
			</xsl:for-each>
			<xsl:for-each select="PromotionData/Elements/PurchaseCondition/ExcludeCategoryIdentifier">
				<ExcludeCategory>
					<xsl:call-template name="CategoryKeyTemplate">
						<xsl:with-param name="dn" select="Data/DN" />
						<xsl:with-param name="name" select="Data/Name" />
					</xsl:call-template>
				</ExcludeCategory>
			</xsl:for-each>
		</Filter>
		<xsl:choose>
			<xsl:when test="PromotionData/Elements/PurchaseCondition/ExcludeCatalogEntryIdentifier">
			<!-- Only populate when there are exclude items -->
				<Filter impl="com.ibm.commerce.marketing.promotion.condition.MultiSKUFilter">
					<xsl:for-each select="PromotionData/Elements/PurchaseCondition/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>
			</xsl:when>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="PromotionData/Elements/PurchaseCondition/CatalogEntryAttributeRule">
			<!-- Only populate when there are attributes -->
				<Filter	impl="com.ibm.commerce.marketing.promotion.condition.CatalogEntryAttributeFilter">
					<AssociatedLanguage><xsl:value-of select="PromotionData/Elements/PurchaseCondition/Data/Language" />
                                   </AssociatedLanguage>
					<CaseSensitive>false</CaseSensitive>
					<SupportAttributeWithNoAssociatedLanguage>true</SupportAttributeWithNoAssociatedLanguage>
					<xsl:for-each select="PromotionData/Elements/PurchaseCondition/CatalogEntryAttributeRule">
						<xsl:call-template name="CatalogEntryAttributeRuleTemplate">
							<xsl:with-param name="attributeRule" select="." />
						</xsl:call-template>	
					</xsl:for-each>					
				</Filter>
			</xsl:when>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="PromotionData/Elements/PurchaseCondition/IncludePaymentTypeIdentifier">
				<xsl:choose>
					<xsl:when test="PromotionData/Elements/PurchaseCondition/IncludePaymentTypeIdentifier/Data/PaymentType != 'Any'">
						<Filter impl="com.ibm.commerce.marketing.promotion.condition.PaymentTypeFilter">
							<IncludePaymentType>
								<PaymentMethodName><xsl:value-of 
select="PromotionData/Elements/PurchaseCondition/IncludePaymentTypeIdentifier/Data/PaymentType" />
                                                        </PaymentMethodName>
							</IncludePaymentType>
						</Filter>
					</xsl:when>
				</xsl:choose>						
			</xsl:when>
		</xsl:choose>						
		<Filter impl="com.ibm.commerce.marketing.promotion.condition.ItemSortingFilter">
			<SortingMethod>PriceHighToLow</SortingMethod>
			<SplitMethod>SplitEndToStart</SplitMethod>    	
		</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/Data/RewardQuantity" />
		</LowerBound>
		<UpperBound>
			<xsl:value-of select="PromotionData/Elements/PurchaseCondition/Data/RewardQuantity" />
		</UpperBound>
		<Weight>1</Weight>
	</WeightedRange>
	<FilterChain impl="com.ibm.commerce.marketing.promotion.condition.FilterChain">
		<Filter impl="com.ibm.commerce.marketing.promotion.condition.CategoryFilter">
			<xsl:for-each select="PromotionData/Elements/PurchaseCondition/IncludeCategoryIdentifier">
				<IncludeCategory>
					<xsl:call-template name="CategoryKeyTemplate">
						<xsl:with-param name="dn" select="Data/DN" />
						<xsl:with-param name="name" select="Data/Name" />
					</xsl:call-template>
				</IncludeCategory>
			</xsl:for-each>
			<xsl:for-each select="PromotionData/Elements/PurchaseCondition/ExcludeCategoryIdentifier">
				<ExcludeCategory>
					<xsl:call-template name="CategoryKeyTemplate">
						<xsl:with-param name="dn" select="Data/DN" />
						<xsl:with-param name="name" select="Data/Name" />
					</xsl:call-template>
				</ExcludeCategory>
			</xsl:for-each>
		</Filter>
		<xsl:choose>
			<xsl:when test="PromotionData/Elements/PurchaseCondition/ExcludeCatalogEntryIdentifier">
			<!-- Only populate when there are exclude items -->
				<Filter impl="com.ibm.commerce.marketing.promotion.condition.MultiSKUFilter">
					<xsl:for-each select="PromotionData/Elements/PurchaseCondition/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>
			</xsl:when>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="PromotionData/Elements/PurchaseCondition/CatalogEntryAttributeRule">
			<!-- Only populate when there are attributes -->
				<Filter
					impl="com.ibm.commerce.marketing.promotion.condition.CatalogEntryAttributeFilter">
					<AssociatedLanguage><xsl:value-of select="PromotionData/Elements/PurchaseCondition/Data/Language" />
                                   </AssociatedLanguage>
					<CaseSensitive>false</CaseSensitive>
					<SupportAttributeWithNoAssociatedLanguage>true</SupportAttributeWithNoAssociatedLanguage>
					<xsl:for-each select="PromotionData/Elements/PurchaseCondition/CatalogEntryAttributeRule">
						<xsl:call-template name="CatalogEntryAttributeRuleTemplate">
							<xsl:with-param name="attributeRule" select="." />
						</xsl:call-template>	
					</xsl:for-each>					
				</Filter>
			</xsl:when>
		</xsl:choose>
		<xsl:choose>
			<xsl:when test="PromotionData/Elements/PurchaseCondition/IncludePaymentTypeIdentifier">
				<xsl:choose>
					<xsl:when test="PromotionData/Elements/PurchaseCondition/IncludePaymentTypeIdentifier/Data/PaymentType != 'Any'">
						<Filter impl="com.ibm.commerce.marketing.promotion.condition.PaymentTypeFilter">
							<IncludePaymentType>
								<PaymentMethodName><xsl:value-of
select="PromotionData/Elements/PurchaseCondition/IncludePaymentTypeIdentifier/Data/PaymentType" />
								</PaymentMethodName>
							</IncludePaymentType>
						</Filter>
					</xsl:when>
				</xsl:choose>						
			</xsl:when>
		</xsl:choose>	
		<Filter impl="com.ibm.commerce.marketing.promotion.condition.ItemSortingFilter">
			<SortingMethod>PriceLowToHigh</SortingMethod>        	
		</Filter>								
	</FilterChain>
</Constraint>