Next >Tutorial: Modifying a controller command
This tutorial demonstrates how to modify an existing controller command. In this tutorial, you restrict the number of items in a customer's shopping cart to five or fewer unique items. To implement this solution, you override the OrderItemAddCmdImpl class with our own implementation. The implementation includes logic to check for the number of items in the shopping cart. If a customer attempts to add a sixth item to the shopping cart, an exception is thrown. This exception uses a new error message.
Learning objectives
After completed this tutorial, you should be familiar with the following concepts:
- OrderItemAddCmdImpl class
- Controller commands
After completing this tutorial, you should be familiar with the following tasks:
- Creating implementation for a controller command
- Updating the command registry so that the new implementation gets used in your application
- Deploying a modified controller command to a WebSphere Commerce application
Time required
Expect this tutorial to take 30 minutes to complete. The tutorial takes longer if you explore concepts related to this tutorial.
Skill Level
This tutorial is intended for WebSphere Commerce Store developers who are responsible for modifying controller commands. To complete this tutorial, ensure that we are familiar with the following terms and concepts:
- Rational Application Developer.
- The Java programming language.
- The database type used in the WebSphere Commerce development environment.
Lessons in this tutorial
- Creating the error message text
In this lesson, you define the new error message and the associated properties files for the message.- Create MyOrderItemAddCmdImpl
In this lesson, you create the MyOrderItemAddCmdImpl class that implements the interface that is defined within the OrderItemAddCmd class. Your new MyOrderItemAddCmdImpl class must include the code to ensure that a customer shopping cart includes five, or fewer, items.- Modify the command registry to register your new class
In this lesson, you modify the WebSphere Commerce command registry to register your new MyOrderItemAddCmdImpl implementation class and to ensure that your class is used instead of the default OrderItemAddCmdImpl implementation class. When you register your new class, your class is used as the implementation class for all stores.- Test the MyOrderItemAddCmdImpl command
In this lesson, you test your new command in the storefront. To verify that your command customization is complete, ensure that we cannot add more items into your shopping cart than the maximum number of allowed unique items.