|
The Products of SuperStore |
|
|
We want to list the products existing in the products table of the database in a page called "Products". We will provide a filtering mechanism in the page to list only the products that belong to the selected category. Additionally we will let the users to select one or more products from the list and add to the current order. This time we will use the library elements under the "Tutorial" Branch of the system library to speed up a little bit. Steps:
The "ListProducts" is a ProcessForm element that contains a header section and a repeating ProcessBlock element which is repeated for each product returned from the database query.
You've noticed that the all the products that exist in the database are listed on the page. Listing the products of the selected category Now we want to let the users to select one of the available product categories to filter the product list and display only the products under the selected category.
Note that the WHERE clause that filters the products of the given category is included in the query only if the request parameter "cat" is available.
Adding the selected products to the current order The "ListProducts" element is derived from a "ProcessForm" element. If our aim was just the displaying the products then we wouldn't need a ProcessForm. Since we want to let the users to add the selected products to the current order we need a ProcessForm and other process related elements. The "ProductsBlock" element in the ProcessForm contains hidden input fields ID, NAME and PRICE. The values of these fields are provided by the "products" data source. Note that hidden input fields are required to post data to the server along with the request.
Insert new if it does not exist, Increase the QUANTITY if it does. The purpose of this process is to add the selected products into the shopping cart. It should be kept in mind that it is executed for each process record that are selected by the user. It first checks to see if the product being processed is already exists in the cart table. That is realized with the selecT COUNT(*) AS v:CNT FROM cart WHERE PRODUCT_ID = @vof(ID); statement. The variable "v:CNT" will contain 0 if the product does not exists in the cart and 1 if it does. By evaluating the value of this variable either "UPDATE" or "INSERT" statement is executed. For Oracle The syntax of the INSERT statement is different for Oracle and it should be as follows:
Note that currently we insert 0 to the USER_ID column by now until we implement the security in the web application. In the "Completing the Web Application" topic we will modify this query to assign the user id of the current user to the USER_ID column.
When the user selects one or more products on the list and clicks on this command button, the selected products will be added to the shopping cart. The products in the cart will be displayed in the "CurrentOrder" page which we will develop next. You can test this page as it is (before developing the "CurrentOrder" page) and you can check the content of the "cart" table of the SuperStore database using a database browser.
|