Creating the object template

In this lesson, you create an object template to define the object structure for the promotion. The object template contains all the objects that each promotion type requires. There is one object template for each promotion type defined in the Promotions tool to specify the unique properties of the promotion type.

About this task

Most promotion properties are common for all promotion types. For example, if you compare the user interface for certain properties, such as the redemption limit and the promotion schedule, they typically look the same from one promotion type to the next. On the other hand, the properties of the purchase and reward conditions vary, depending on:
  • Whether the promotion is an order-level, catalog-entry-level or category-level promotion
  • Whether the discount is a fixed price, a percentage off, an amount off, or a free gift

The object template you are adding, extProductLevelFreeGiftTemplate, is a product level promotion, with a free gift reward.

Procedure

  1. Create a new folder for your template:
    1. Complete one of the following steps:
      • WebSphere Commerce Version 7.0.0.0Feature Pack 1In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx > mycompany > promotion > objectDefinitions.
      • Introduced in Feature Pack 3Feature Pack 2In the Enterprise Explorer view, navigate to LOBTools > WebContent > config > mycompany > promotion > objectDefinitions.
    2. Right-click the objectDefinitions folder; then click New > Folder.
    3. In the Folder name field, type promotionTypes.
    4. Click Finish.
      The directory structure should now look like the following screen snapshot:
      promotionTypes folder
  2. Create a new file for the promotion template:
    1. Right-click the promotionTypes folder.
    2. Click New > File.
    3. Name your new file:
      • WebSphere Commerce Version 7.0.0.0Feature Pack 1ProductLevelFreeGiftTemplate.lzx
      • Introduced in Feature Pack 3Feature Pack 2ProductLevelFreeGiftTemplate.def
    4. Click Finish to save the file.
      The file opens in the default XML editor.
  3. Complete one of the following steps:
    OptionDescription
    WebSphere Commerce Version 7.0.0.0Feature Pack 1ProductLevelFreeGiftTemplate.lzx WebSphere Commerce Version 7.0.0.0Feature Pack 1
    1. Copy and paste the following code into this class file:
      <library>
          <!--Object template for extended promotion type ProductLevelFreeGift. -->
          <class name="extProductLevelFreeGiftTemplate" extends="wcfObjectTemplate"
                 templateType="ProductLevelFreeGift"
                 displayName="${extPromotionResources.promotion_type_ProductLevelFreeGift.string}"
                 description="${extPromotionResources.promotion_type_description_ProductLevelFreeGift.string}">
                 <dataset name="template">
                     <object objectType="ProductLevelFreeGiftPurchaseCondition" />  
                 </dataset>
          </class>
      </library>
      Notice the <object> elements defined in the data set; the objectType value will be stored in the SUBTYPE column of the PX_ELEMENT table.
    2. Save and close the file.
    Introduced in Feature Pack 3Feature Pack 2ProductLevelFreeGiftTemplate.def Introduced in Feature Pack 3Feature Pack 2
    1. Copy and paste the following code into this definition file:
      <Definitions>
          <!--Object template for extended promotion type ProductLevelFreeGift. -->
          <ObjectTemplate definitionName="extProductLevelFreeGiftTemplate"
              templateType="ProductLevelFreeGift"
              displayName="${extPromotionResources.promotion_type_ProductLevelFreeGift}"
              description=
                  "${extPromotionResources.promotion_type_description_ProductLevelFreeGift}">
              <Xml name="template">
                  <object objectType="ProductLevelFreeGiftPurchaseCondition" />  
              </Xml>
          </ObjectTemplate>
      </Definitions>
      Notice the <object> elements defined in the template; the objectType value will be stored in the SUBTYPE column of the PX_ELEMENT table.
    2. Save and close the file.
  4. WebSphere Commerce Version 7.0.0.0Feature Pack 1Right-click the ProductLevelFreeGiftTemplate.lzx file; then click Build OpenLaszlo Project on the context menu.
  5. WebSphere Commerce Version 7.0.0.0Feature Pack 1Register the template file in the promotion extensions library:
    1. In the PromotionExtensionsLibrary.lzx file, which should still be open from a previous step, add the following include statement within the <library> element:
      <include href="../../mycompany/promotion/objectDefinitions/promotionTypes/ProductLevelFreeGiftTemplate.lzx"/>
    2. Save the file.
    3. Right-click the PromotionExtensionsLibrary.lzx file; then click Build OpenLaszlo Project on the context menu.
  6. Complete one of the following steps:
    OptionDescription
    WebSphere Commerce Version 7.0.0.0Feature Pack 1Create an instance of your new template in the promotion primary object definition WebSphere Commerce Version 7.0.0.0Feature Pack 1
    1. In the Enterprise Explorer view, navigate to the LOBTools > WebContent > WEB-INF > src > lzx > commerce > promotion > objectDefinitions directory.
    2. Open the PromotionPrimaryObjectDefinition.lzx file.
    3. Locate the section of the file where the other templates are instantiated, as shown in the following XML sample of a few templates:
      <proCategoryLevelPerItemPercentDiscountTemplate/>
      <proCategoryLevelBuyXGetYFreeTemplate/>
      <proCategoryLevelSameItemPercentDiscountTemplate/>
      
    4. Insert the following code at the bottom of the list of templates:
      <!-- Customization: Promotion template of the new promotion type -->
      <extProductLevelFreeGiftTemplate />
      <!-- End -->
      This new promotion type will now display in the Promotion type list in the Promotions tool user interface.
    5. Save and close the file.
    6. Right-click the PromotionPrimaryObjectDefinition.lzx file; then click Build OpenLaszlo Project on the context menu.
    Introduced in Feature Pack 3Feature Pack 2Add your new template to the promotion primary object definition Introduced in Feature Pack 3Feature Pack 2
    1. In the Enterprise Explorer view, navigate to the LOBTools > WebContent > config > commerce > promotion > objectDefinitions directory.
    2. Open the PromotionPrimaryObjectDefinition.def file.
    3. Locate the section of the file where the other templates are declared, as shown in the following XML sample of a few templates:
      <ObjectTemplate baseDefinitionName="proCategoryLevelPerItemPercentDiscountTemplate"/>
      <ObjectTemplate baseDefinitionName="proProductLevelPerItemValueDiscountTemplate"/>
      <ObjectTemplate baseDefinitionName="proCategoryLevelPerItemValueDiscountTemplate"/>
    4. Insert the following code at the bottom of the list of templates:
      <!-- Customization: Promotion template of the new promotion type -->
      <ObjectTemplate baseDefinitionName="extProductLevelFreeGiftTemplate"/>
      <!-- End -->
      This new promotion type will now display in the Promotion type list in the Promotions tool user interface.
    5. Save and close the file.

Results

In this lesson, you created the promotion user interface template. In the next lesson, you begin creating the customized widgets you need to support your promotion in the Management Center user interface.