Tutorials > Management Center > Create a new promotion type
Create 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.
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
- Create a new folder for the template:
- Complete one of the following steps:
- In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx > mycompany > promotion > objectDefinitions.
- In the Enterprise Explorer view, navigate to LOBTools > WebContent > config > mycompany > promotion > objectDefinitions.
- Right-click the objectDefinitions folder; then click New > Folder.
- In the Folder name field, type promotionTypes.
- Click Finish. The directory structure should now look like the following screen snapshot:
- Create a new file for the promotion template:
- Right-click the promotionTypes folder.
- Click New > File.
- Name the new file:
- ProductLevelFreeGiftTemplate.lzx
- ProductLevelFreeGiftTemplate.def
- Click Finish to save the file. The file opens in the default XML editor.
- Complete one of the following steps:
Option Description ProductLevelFreeGiftTemplate.lzx
- 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.
- Save and close the file.
ProductLevelFreeGiftTemplate.def
- 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.
- Save and close the file.
- Right-click the ProductLevelFreeGiftTemplate.lzx file; then click Build OpenLaszlo Project on the context menu.
- Register the template file in the promotion extensions library:
- 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"/>
- Save the file.
- Right-click the PromotionExtensionsLibrary.lzx file; then click Build OpenLaszlo Project on the context menu.
- Complete one of the following steps:
Option Description Create an instance of your new template in the promotion primary object definition
- In the Enterprise Explorer view, navigate to the LOBTools > WebContent > WEB-INF > src > lzx > commerce > promotion > objectDefinitions directory.
- Open the PromotionPrimaryObjectDefinition.lzx file.
- 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/>
- 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.
- Save and close the file.
- Right-click the PromotionPrimaryObjectDefinition.lzx file; then click Build OpenLaszlo Project on the context menu.
Add the new template to the promotion primary object definition
- In the Enterprise Explorer view, navigate to the LOBTools > WebContent > config > commerce > promotion > objectDefinitions directory.
- Open the PromotionPrimaryObjectDefinition.def file.
- 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"/>
- 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.
- Save and close the file.
In this lesson, you created the promotion user interface template. In the next lesson, you begin creating the customized widgets you need to support the promotion in the Management Center user interface.