Store Cart Details in Database

To keep a record of all the items included in a particular order, add the eCart server behavior Store Cart Details in Database to a page. This server behavior inserts a new record for each item in the shopping cart.

The server behavior may be triggered by the press of any form button on the page — in general or a specific button — or other actions including the loading of the page or any form posting to the current page; you can even execute the server behavior if a particular session variable or other dynamic value is defined.

After the record has been inserted, the user may be re-directed to another page.

Databases typically use two tables to handle orders, a general Orders table and an OrderDetails table. The two tables are linked by key field, usually OrderID; each record in the OrderDetails table includes a column called something like DetailsOrderID that corresponds to the OrderID column in the Orders table.

This makes it possible to retrieve a summary of all the orders placed by a particular customer by querying just the Orders table or to get a listing of all the products on a particular order by querying the OrderDetails page.

You can also employ a database view (also called a query of a query) that combines information from the two tables.

The Store Cart Details in Database server behavior adds records to the OrdersDetails table. Frequently this server behavior is used together with the Store Cart Summary in Database server behavior to save all the cart information at the same time.

To apply the Store Cart Details in Database server behavior:

  1. From the Server Behaviors panel, choose Add (+) and select eCart > Database Manipulation > Store Cart Details in Database server behavior.
  2. Select the action you want to initiate the server behavior from the Trigger list. The options are:
    • Any Form Post: Any form posted to the current page that the server behavior is applied to will trigger the record insertion.
    • Before Page Load: The record insert is triggered when the current page that the server behavior is applied to is loaded.
    • On Form Submit: Any form submitted on the same page that the server behavior is applied to will trigger the record insertion.
    • eCart [cart name] is not empty: The server behavior is triggered if the specified shopping cart applied to the page contains no items.
    • eCart [cart name] is empty: The server behavior is triggered if the specified shopping cart applied to the page contains no items.
    • Button [button name] pressed: The server behavior is triggered if the specified button on the page is clicked.
    • Recordset [recordset name] is not empty: The server behavior is triggered if the specified recordset applied to the page contains no items.
    • Recordset [recordset name] is empty: The server behavior is triggered if the specified recordset applied to the page shopping cart contains no items.
    • Dynamic Data: Server-side code can be specified in the dynamic data interface (accessed through the lightning bolt) to create a trigger specific to your needs if one in the list does not meet your requirements.
  3. Select the desired connection from the Connection list.

    If necessary, you can create a new connection by clicking the Define button.
  4. Choose a table to insert the shopping cart information into from the Table list.

    The table chosen should have, at a minimum, columns for a details order ID (the unique key field), an order ID, an item ID, and quantity. Other useful columns include ones for a product name, price and selected options.
  5. Select the key field for the table from the Order ID list.
  6. Bind values to the table columns listed in the columns area. Either static or dynamic values can be used.

    To bind a static value, enter it in the Value field for a selected column.

    To bind a dynamic value, choose the lightning bolt to open the Dynamic Data dialog box and select an item from a shopping cart entry; click OK to close the Dynamic Data dialog.

    Choose a data type from the Type list to confirm your selection.

    Dynamic values can also be entered by hand in the Value field.

    In the example figure, the following values are assigned:
    • DetailsID - Left blank and not updated. DetailsID is an autonumber field.
    • DetailOrderID - Expand the Session entry in the Dynamic Data dialog and select OrderNumber. The OrderNumber session variable is defined in the Save Cart Summary in Database server behavior.
    • DetailProductID - The ID column from the shopping cart dynamic data entry is selected.
    • DetailProductName - The Name column from the shopping cart dynamic data entry is selected.
    • DetailQuantity - The Quantity column from the shopping cart dynamic data entry is selected.
    • DetailPrice - The Price column from the shopping cart dynamic data entry is selected.
    • DetailOption1, DetailOption2 - No options are specified for this example, so these entries are left blank. For an entry to be left blank, the associated column in the database table must be able to accept zero length (null) values.
  7. If you want another page to be displayed after the record insertion is complete, enter the path to that file in the Redirect field or click the folder icon and choose your file from the Select File dialog box.
  8. Click OK when you're done.
You can modify the server behavior by double-clicking its entry in the Server Behaviors panel.