Tutorials > Management Center > Add new search conditions in the advanced search of the Catalogs tool
Extend the Advanced Search dialog to include extended properties as search
The Advanced Search dialog in the Catalogs tool is implemented by the catAllCatalogEntriesAdvancedSearchContent class in WCDE_INSTALL\workspace\LOBTools\WebContent\WEB-INF\src\lzx\commerce\catalog\restricted\searchDefinitions\CatalogAdvancedSearchContent.lzx. catAllCatalogEntriesAdvancedSearchContent is a subclass of wcfAdvancedSearchContent.
The existing search condition input fields use user interface widgets, such as wcfInputText, wcfBaseRadioGroup, wcfBaseRadioButton, wcfGridCheckbox, and other OpenLaszlo user interface widgets.
Procedure
- Define the new properties used in the extended Advanced Search dialog.
Verify which properties have already been added to the CatalogLOB_en_US.properties file and add any properties definitions that are missing from this file.
- Navigate to LOBTools > Java Resources: src > com.mycompany.catalog.client.lobtools.properties.
- Double-click CatalogLOB_en_US.properties to open it in the default editor.
- Verify that the following properties definitions are in the CatalogLOB_en_US.properties file:
productWarranty_DefaultOption=choose one...If any of these properties definitions are not defined, add them to the file.
- Save and close the file.
- Navigate to LOBTools > WebContent > WEB-INF > src > lzx > mycompany > catalog.
- Double-click extCatalogManagementResourceBundle.lzx to open it in the default editor.
- Verify that the following wcfResourceBundleKey definitions are contained in the extCatalogResourceBundle class:
<wcfResourceBundleKey name="productWarranty_DefaultOption"/>If any of these wcfResourceBundleKey definitions are not defined, add them to the file.
- Save and close the file. If the LOBTools project is not compiled automatically, right-click the LOBTools project and select Build OpenLaszlo Project.
- To make the properties that you defined available, restart the WebSphere Commerce Test Server.
- Create a new advanced search content class.
In this step, you create a new Advanced Search dialog that extends the default Advanced Search dialog. You add the custom user interface widgets to this dialog. The user selects the warranty term and warranty type from a list of options.
- Ensure you have downloaded the completed tutorial code package and import the file MyCompanyCatalogAdvancedSearchContent.lzx from the WCToolkitEE60/workspace/LOBTools/WebContent/WEB-INF/src/lzx/mycompany/catalog/searchDefinitions directory.
- Add the following code to the MyCompanyCatalogAdvancedSearchContent.lzx file:
<library> <wcfRegisterSearchDefinition searchType="FindAllCatalogEntries" searchDefinitionClass="catFindAllCatalogEntriesSearchDefinition"/> <!--- This search is used to find {@link catBaseProductPrimaryObjectDefinition}, {@link catBaseBundlePrimaryObjectDefinition}, {@link catBaseKitPrimaryObjectDefinition}, {@link catBaseCatalogGroupSKUPrimaryObjectDefinition} and {@link catBaseProductSKUPrimaryObjectDefinition}. The search retrieves objects that match the search term. The search term text is compared with the values of the following properties: <ul> <li>partnumber <li>name </ul> --> <class name="catFindAllCatalogEntriesSearchDefinition" extends="wcfSearchDefinition" searchType="FindAllCatalogEntries" displayName="${catalogResources.findCatalogEntriesSearchDefinition_DisplayName.string}" listClass="catCatalogEntrySearchGrid" listTitle="${catalogResources.catalogGroupChildListTitle.string}" utilitiesListClass="catCatalogEntryUtilitiesSearchGrid" advancedSearchContentClass="extAllCatalogEntriesAdvancedSearchContent" icon="catalogEntriesIcon" tooltip="${catalogResources.searchAllCatalogEntriesTooltip.string}"> <wcfSearchService name="findAllCatalogEntries" url="/cmc/FindCatalogEntries-All"> <wcfServiceParam name="storeId"/> <wcfServiceParam name="masterCatalogId"/> </wcfSearchService> </class> </library>In this code sample, the extAllCatalogEntriesAdvancedSearchContent class uses properties resource bundles to show the warranty type and warranty term option names. For example, extCatalogResources.productWarranty_DefaultOption.string, extCatalogResources.productWarranty_DisplayNameForTerm1, extCatalogResources.productWarranty_DisplayNameForType1.string, and so on. Some of these were already defined in Tutorial: Adding new fields in the Catalogs tool.
Since the advanced search content class is not an IBM class, it is prefixed with ext to indicate that it is an extension.
- Save and close the file.
- Register the new advanced search class.
After the new OpenLaszlo library file MyCompanyCatalogAdvancedSearchContent.lzx is created, register it in CatalogExtensionsLibrary so that the classes in this library can be used by other classes.
- Navigate to LOBTools > WebContent > WEB-INF > src > lzx > commerce > catalog.
- Double-click CatalogExtensionsLibrary.lzx to open it in the default editor.
- In the library section, add a new line to include the new advanced search class:
<include href="../../mycompany/catalog/searchDefinitions/MyCompanyCatalogAdvancedSearchContent.lzx"/>
- Click Save.
- Bind the new advanced search class with the catalog entry search definition.
After you create the new advanced search content, bind it with the catalog entry search definition so that it can be launched by the Catalog search widget.
- Determine the name of the specific search definition that you want to modify so that you can search for it in other files:
Option Description Navigate to the \LOBTools\WebContent\WEB-INF\src\lzx\commerce\catalog directory
- Open the CatalogManagementToolDefinition.lzx file:
- In the Search definitions section, locate the catFindAllCatalogEntriesSearchDefinition catalog entry search definition:
<!-- Search definitions --> <catFindKitsSearchDefinition/> <catFindBundlesSearchDefinition/> <catFindSKUsSearchDefinition/> <catFindProductsSearchDefinition/> <catFindAllCategoriesSearchDefinition/> <catFindAllCatalogEntriesSearchDefinition isDefault="true" displayName="${catalogResources.findAllCatalogEntriesSearchDefinition_DisplayName.string}"/> <catFindAllCatalogEntriesExceptSKUsSearchDefinition/>This is the name of the search definition that to modify.
- Search the *.lzx files for the FindAllCatalogEntries definition name. This definition is declared in the \LOBTools\WebContent\WEB-INF\src\lzx\commerce\catalog\searchDefinitions\FindAllCatalogEntriesSearchDefinition.lzx file.
Navigate to the \LOBTools\WebContent\config\commerce\catalog directory
- Open the CatalogManagementToolDefinition.def file:
- In the Search definitions section, locate the catFindAllCatalogEntriesSearchDefinition catalog entry search definition, where the baseDefinitionName is FindAllCatalogEntries:
<!-- Catalog Search Definitions --> <SearchDefinition baseDefinitionName="FindAllCatalogEntries" displayName="${catalogResources.findAllCatalogEntriesSearchDefinition_DisplayName}" isDefault="true"/><SearchDefinition baseDefinitionName="FindAllCatalogEntriesExceptSKUs"/> <SearchDefinition baseDefinitionName="FindCategories"/> <SearchDefinition baseDefinitionName="FindProducts"/> <SearchDefinition baseDefinitionName="FindSKUs"/> <SearchDefinition baseDefinitionName="FindBundles"/> <SearchDefinition baseDefinitionName="FindKits"/>This is the name of the search definition that to modify.
- Search the *.def files for the FindAllCatalogEntries definition name. This definition is declared in the \LOBTools\WebContent\config\commerce\catalog\searchDefinitions\FindAllCatalogEntriesSearchDefinition.def file.
- Double-click one of the following files to open it in the default editor:
- FindAllCatalogEntriesSearchDefinition.lzx
- FindAllCatalogEntriesSearchDefinition.def
Option Description FindAllCatalogEntriesSearchDefinition.lzx In this class file:
- Locate the advancedSearchContentClass attribute in the class definition and change the attribute value to the newly defined advanced search definition:
advancedSearchContentClass="extAllCatalogEntriesAdvancedSearchContent"
The following code snippet shows the modified FindAllCatalogEntriesSearchDefinition.lzx file:
<library> <class name="catFindAllCatalogEntriesSearchDefinition" extends="wcfSearchDefinition" searchType="FindAllCatalogEntries" displayName="${catalogResources.findAllCatalogEntriesSearchDefinition_DisplayName.string}" isDefault="true" listClass="catCatalogEntrySearchGrid" listTitle="${catalogResources.catalogGroupChildListTitle.string}" advancedSearchContentClass="extAllCatalogEntriesAdvancedSearchContent"> <wcfSearchService name="findAllCatalogEntries" url="/cmc/FindCatalogEntries-All"> <wcfServiceParam name="storeId"/> <wcfServiceParam name="masterCatalogId"/> </wcfSearchService> </class> </library>
- Click Save.
FindAllCatalogEntriesSearchDefinition.def In this definition file:
- Locate the advancedSearchContentClass attribute in the class definition and change the attribute value to the newly defined advanced search content class:
advancedSearchContentClass="extAllCatalogEntriesAdvancedSearchContent"
The following code snippet shows the modified FindAllCatalogEntriesSearchDefinition.def file:
<Definitions> <SearchDefinition advancedSearchContentClass="extAllCatalogEntriesAdvancedSearchContent" definitionName="FindAllCatalogEntries" displayName= "${catalogResources.findCatalogEntriesSearchDefinition_DisplayName}" icon="catalogEntriesIcon" listDefinitionName="catCatalogEntrySearchGrid" listTitle="${catalogResources.catalogGroupChildListTitle}" searchType="FindAllCatalogEntries" tooltip="${catalogResources.searchAllCatalogEntriesTooltip}" utilitiesListDefinitionName="catCatalogEntryUtilitiesSearchGrid"> <SearchService name="findAllCatalogEntries" url="/cmc/FindCatalogEntries-All"> <ServiceParam name="storeId"/> <ServiceParam name="masterCatalogId"/> </SearchService> </SearchDefinition> </Definitions>
- Click Save.