Tutorials > Management Center > Create a new promotion type
Create new resource bundles for custom text strings
In this lesson, you create a new properties file and resource bundle to define the custom text strings to display on the Management Center user interface for the customized widgets. In the Management Center, all text labels and images displayed in the user interface must be defined as properties and registered in a resource bundles file.
A properties file is a resource bundle that contains translatable text that displays in the user interface. Resource bundles contain locale-specific objects. By using resource bundle files, the text can be translated into different languages. In the previous lesson, you planned the user interface support the new promotion, and you determined that include four new text strings:
Text string Description Resource key "Minimum Purchase on base catalog entries ($)" The label for the total price threshold for the purchase condition promotion_Minimum_purchase_TotalPrice "Quantity for free" The label for the gift quantity for the reward promotion_Free_gift_qty "Spend $ on catalog entry X, get catalog entry Y free" The name of the new promotion type that appears in the Promotion Type Selector window promotion_type_ProductLevelFreeGift "Purchase condition: Order contains a specified amount spent on a catalog entry. Reward: One or more free gifts.
Example:
- Spend $100 or more on Villagois table glasses, and receive a decanter and a cork screw free!"
The description of the new promotion type that appears in the Promotion Type Selector window promotion_type_description_ProductLevelFreeGift You can reuse all other text strings from existing promotion types.
Procedure
- Open WebSphere Commerce Developer.
- Create a new package for the properties file:
- In the Enterprise Explorer view, navigate to LOBTools > JavaResources: src.
- Right-click the src folder, and then click New > Package.
- In the New Java Package window, create a new properties package named com.mycompany.commerce.promotion.client.lobtools.properties.
- Click Finish.
- In the new properties package, create a new file:
- Right-click the com.mycompany.commerce.promotion.client.lobtools.properties properties package.
- Click New > Other.
- In the Select a wizard window, expand the General folder and click File.
- Click Next.
- Name the new file PromotionLOB_en_US.properties.
- Click Finish to save the file. The file opens in the default XML editor.
- To define the new properties, copy and paste the following code into the PromotionLOB_en_US.properties file:
#=========================================================================== # Customized Promotion Properties #=========================================================================== #Used in extProductLevelFreeGiftTemplate to define the new Promotion type name in the drop down list promotion_type_ProductLevelFreeGift=Spend $ on catalog entry X, get catalog entry Y free #Used in PromotionTypeTemplatePicker.lzx to define the promotion type description in the Promotion Type Selector window promotion_type_description_ProductLevelFreeGift=<b>Purchase condition:</b>Order contains a specified amount spent on a catalog entry.<br/><br/><b>Reward:</b> One or more free gifts.<br/><br/><b>Example:</b><ul><li>Spend $100 or more on Villagois table glasses, and receive a decanter and a cork screw free!</li></ul> #Used in extProductLevelFreeGiftProperties and extProductLevelFreeGiftPurchaseConditionObjectDefinition to define the property label of the total price threshold promotion_Minimum_purchase_TotalPrice=Minimum Purchase on base catalog entries ($) #Used in extProGiftRewardGrid and extProductLevelFreeGiftPurchaseConditionObjectDefinition to define the property label of the gift quantity promotion_Free_gift_qty=Quantity for free
- Save and close the file.
- Create a new directory structure for the custom code:
- In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx.
- Right-click the lzx folder and click New > Folder.
- In the Folder name field, type mycompany. All of the customized OpenLaszlo code should be put under this folder.
- Click Finish.
- Complete one of the following steps:
- Create the remainder of the directory structure you need for this tutorial, which is mycompany/promotion/objectDefinitions/elements. Your directory structure should now look like this:
- Create the promotion directory. Your directory structure should now look like this:
- The new text strings added in the properties file cannot be used by OpenLaszlo classes or Management Center definitions directly. Register the properties with the new resource bundles:
- In the Enterprise Explorer view, navigate to LOBTools > WebContent > WEB-INF > src > lzx > mycompany > promotion.
- Right-click the promotion directory; then click New > Other.
- In the "Select a wizard" window, expand the General folder and click File.
- Click Next.
- Name the new file PromotionResourceBundle.lzx.
- Click Finish to save the file. The file opens in the default XML editor.
- To define the new resource bundle class and create an instance of it, copy and paste the following code into the file PromotionResourceBundle.lzx:
<library> <!--- Resource bundle for the customized Promotion component and all the resource keys used are defined here. A global instance of this class is instantiated with the id <code>extPromotionResources</code>. --> <class name="extPromotionResourceBundle" extends="wcfResourceBundle" baseName="com.mycompany.commerce.promotion.client.lobtools.properties.PromotionLOB"> <wcfResourceBundleKey name="promotion_type_ProductLevelFreeGift" /> <wcfResourceBundleKey name="promotion_type_description_ProductLevelFreeGift" /> <wcfResourceBundleKey name="promotion_Minimum_purchase_TotalPrice" /> <wcfResourceBundleKey name="promotion_Free_gift_qty" /> </class> <extPromotionResourceBundle /> </library>To refer to the resource bundle from other OpenLaszlo classes, use the ID in the resource bundle class. In this example, the ID is extPromotionResources. Therefore, to use the resource "promotion_type_ProductLevelFreeGift" in the OpenLaszlo source, the reference would look like this:
${extPromotionResources.promotion_type_ProductLevelFreeGift.string}
To refer to the resource bundle from the Management Center definitions, use the ID in the resource bundle class. In this example, the ID is extPromotionResources. Therefore, to use the resource "promotion_type_ProductLevelFreeGift" in a Management Center definition, the reference would look like this:
${extPromotionResources.promotion_type_ProductLevelFreeGift}
- Save and close the file.
- Register the new resource bundle class in the promotion extensions library:
- Open the file at this path:
LOBTools/WebContent/WEB-INF/src/lzx/commerce/promotion/PromotionExtensionsLibrary.lzx This library is used to register all custom files related to the promotions component. Include the file in the library to make it available to all other OpenLaszlo classes.
- Add the following include statement within the <library> element:
<include href="../../mycompany/promotion/PromotionResourceBundle.lzx"/>
- Save the file, but leave it open so that the do not have to reopen it later in this tutorial to register additional custom files.
- Right-click the LOBTools project; then click Build OpenLaszlo Project on the context menu.
- Restart the WebSphere Commerce test server. The properties that you defined are available.
In this lesson, you completed the new properties file and resource bundles definition. In the next lesson, we will define a new OpenLaszlo object definition class to represent the new purchase condition promotion element.