< Previous | Next >Customize the WebSphere Commerce pricing engine
We can create a price rule element to override the supplied price rule elements.
Task info
Price rules each have their own conditions. There are multiple price rule elements used to compose a price rule. The multiplying calculations are not done in the price rule element commands, otherwise the same value points can be multiplied more than one time. To avoid value points multiplied more than one time, the commands that output the offer price must be overridden, or used as a parameter. This tutorial teaches you how to customize the WebSphere Commerce pricing engine and create a price rule element class to use for our own business purposes.To customize the WebSphere Commerce price engine:
Procedure
- Find the price rule element to override:
- Open WebSphere Commerce API, and go to the package com.ibm.commerce.price.rule.commands.element. In this package, these classes are listed:
- CalculatePriceElementCmdImpl
- CatalogConditionElementCmdImpl
- ComparisonConditionElementCmdImpl
- CoordinatorElementCmdImpl
- CustomerConditionElementCmdImpl
- NestedPriceRuleElementCmdImpl
- PriceEquationCalculationCmdImpl
- PriceListConditionElementCmdImpl
- PriceListElementCmdImpl
- PriceRuleElementCmdImpl
- RoundingElementCmdImpl
- DateConditionElementCmdImpl
- Override the classes:
- ComparisonConditionElementCmdImpl
- PriceEquationCalculationCmdImpl
- PriceListElementCmdImpl
Replace the class names:
- MyComparisonConditionElementCmdImpl
- MyPriceEquationCalculationCmdImpl
- MyPriceListElementCmdImpl
- Open the WebSphere Commerce Developer.
- Open the Java™ EE perspective.
- Expand the project WebSphereCommerceServerExtensionsLogic located under src. Create a package named com.mycompany.commerce.price.rule.commands.element.
- Import the source code.
- Use the right mouse button, click the com.mycompany.commerce.price.rule.commands.element package.
- Click Import>GeneralFile System. Click Next.
- Go to the temporary location where CustomizeGetEntitledPrice.zip is and go to WebSphereCommerceServerExtensionsLogic\src\com\mycompany\commerce\price\rule\commands\element.
- Click all files and click Finish. Click Yes to All to overwrite any existing files.
- Organize the imports for the WebSphereCommerceServerExtensionsLogic project.
- Open the Java perspective in WebSphere Commerce Developer.
- Expand the WebSphereCommerceServerExtensionsLogc project, right click src.
- Click Source>Organize Imports.
- Insert the new CMDREG records to override the supplied implementations.
- Under the WebSphereCommerceServerExtensionLogic project, create a file named PriceCmdReg.xml.
- Copy the following content into PriceCmdReg.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE import SYSTEM "..\WC\xml\schema\dtd\wcs.dtd"> <import> <!--Add service commands for value points --> <cmdreg storeent_id="0" interfacename="com.ibm.commerce.price.facade.server.commands.FetchEntit ledPriceCmd+/EntitledPrice[(CatalogEntryIdentifier[UniqueID=] and ContractIdentifier[UniqueID=] and UnitPrice[Price[@currency=] and (Quantity= and Quantity[@uom=])] and VP=)]" classname="com.mycompany.commerce.price.facade.server.commands.ExtFetch EntitledPriceByContractAndCatentryIdCmdImpl"/> <cmdreg storeent_id="0" interfacename="com.ibm.commerce.price.facade.server.commands.FetchEntit ledPriceCmd+/EntitledPrice[(CatalogEntryIdentifier[ExternalIdentifier[P artNumber=]] and ContractIdentifier[UniqueID=] and UnitPrice[Price[Price@currency=] and (Quantity= Quantity[@uom=])] and VP=)]" classname="com.mycompany.commerce.price.facade.server.commands.ExtFetch EntitledPriceByContractAndPartNumberCmdImpl"/> <cmdreg storeent_id="0" interfacename="com.ibm.commerce.price.facade.server.commands.FetchEntit ledPriceCmd+/EntitledPrice[(CatalogEntryIdentifier[UniqueID=] and UnitPrice[Price[@currency=] and (Quantity= and Quantity[@uom=])] and VP=)]" classname="com.mycompany.commerce.price.facade.server.commands.ExtFetch EntitledPriceByCatentryIdCmdImpl"/> <cmdreg storeent_id="0" interfacename="com.ibm.commerce.price.facade.server.commands.FetchEntit ledPriceCmd+/EntitledPrice[(CatalogEntryIdentifier[ExternalIdentifier[P artNumber=]] and UnitPrice[Price[@currency=] and (Quantity= and Quantity[@uom=])] and VP=)]" classname="com.mycompany.commerce.price.facade.server.commands.ExtFetch EntitledPriceByPartNumberCmdImpl"/> <!-- Override the OOB price rule element commands --> <cmdreg storeent_id="0" interfacename="com.ibm.commerce.price.rule.commands.element.ComparisonC onditionElementCmd" classname="com.mycompany.commerce.price.rule.commands.element.MyCompari sonConditionelementCmdImpl"/> <cmdreg storeent_id="0" interfacename="com.ibm.commerce.price.rule.commands.element.PriceEquati onCalculationcmd" classname="com.mycompany.commerce.price.rule.commands.element.MyPriceEq uationCalculationCmdImpl"/> <cmdreg storeent_id="0" interfacename="com.ibm.commerce.price.rule.commands.element.PriceListEl ementCmd" classname="com.mycompany.commerce.price.rule.commands.element.MyPriceLi stElementCmdImpl"/> </import>
- Stop the WebSphere Commerce test server.
- In a command prompt, go to the WCDE_installdir\bin.
- To load the data into the database, run the appropriate command:
DB2:
massload-infile ..\workspace\WebSphereCommerceServerExtensionsLogic\PriceCmdReg.xml -dbname developement_db -dbuser db_user -dbpwd db_password -schema db_schema -method sqlimport
Oracle:
massload ..\workspace\WebSphereCommerceServerExtensionsLogic\PriceCmdReg.xml development_db db_user db_passwordNote: Massload is a utility provided by WebSphere Commerce to load an XML input file into a target database. For more information, see the WebSphere Commerce Information Center, and search for Massload utility (Development environment).
- Validate the customization by JUnit.
- Click File>Import.
- Click General>Existing Projects into Workspace. Click Next.
- Browse to the temporary location where CustomizeGetEntitledPrice.zip is, and click GetEntitledPriceExtension-UnitTests. Check
Copy project into workspace, and click Finish.- Set up a TCP/IP Monitor in the WebSphere Commerce Developer. This TCP/IP Monitor is used to see the request and response messages travel between WebSphere Commerce and the external member management system.
- Click Window>Preferences.
- From Preferences, click Run/Debug>TCP/IP Monitor.
- Click Add.
- Type the following information:
- Local monitoring port: 81.
- Host name: localhost
- Port: 80
- Type: TCP/IP
- Click OK.
- Click the created TCP/IP Monitor.
- Click Start.
- Click OK.
- Start the WebSphere Commerce test server.
- Make sure the WebSphere Commerce is already published to the WebSphere Commerce Test Server. If it is not:
- In the Server pane, click the right mouse button, and click the WebSphere Commerce Test Server. Click Add and Remove Projects.
- Click the WebSphere Commerce Project.
- Click Add.
- Click Finish.
If the WebSphere Commerce project is already added, click the right mouse button, and click the WebSphere Commerce Test Server and click Publish.
- Modify GetEntitledPriceExtension-UnitTests/src/com/mycompany/commerce/price/facade/client/GetEntitledPriceTest.java, to ensure that the values of the parameters are correct.
- Use the right mouse button, click GetEntitledPriceTest.java. Click Run As>JUnit Test.
- Check the request and response messages in the TCP/IP Monitor. Ensure that the results are correct.