Store Cart Summary in Database

To keep a record of the current order, use the eCart Store Cart Summary in Database server behavior. This server behavior inserts a new record in a database table with basic information about the order.

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 Summary in Database server behavior adds records to the more general Orders table. Frequently this server behavior is used together with the Store Cart Details in Database server behavior to save all the cart information at the same time.

To apply the Store Cart Summary in Database server behavior:

  1. From the Server Behaviors panel, choose Add (+) and select eCart > Database Manipulation > Store Cart Summary 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 an order ID (the unique key field) and order total.

    Other useful columns include ones for an order reference ID, a user ID, the shipping amount and the tax on the order.
  5. Select the key field for the table from the Order ID list.
  6. In the Store As field, enter the name of the session variable you want to store the unique ID in.

    Pick a name that is easy to identify and re-use when referencing a particular order, such as OrderNumber.

    The session variable defined here will automatically appear in the Bindings panel and be available from Dynamic Data dialogs.
  7. 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:
    • OrderID - Left blank and not updated. OrderID is an autonumber field.
    • OrderReferenceID - Choose [Cart ID] from the shopping cart dynamic data entry. The code appropriate to your server model is written to include the SessionID, a unique value.
    • OrderUserID - In this example, the user has logged in and his unique user ID has been assigned to a session variable, UserID. The code for writing this session variable appropriate to the server model has been entered manually into the Value field and the binding updated.
    • OrderShipping - Shipping is retrieved from the eCart object data binding for the shipping value in the cart.
    • OrderTax - Tax is retrieved from the eCart object data binding for the tax value in the cart.
    • OrderTotal - From the shopping cart entry of the Dynamic Data dialog, the [GrandTotal] item is selected and the appropriate code is written.
  8. 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.
  9. Click OK when you're done.
You can modify the server behavior by double-clicking its entry in the Server Behaviors panel.