K2BTools Tutorial - Exercise 8.2: Viewing the shopping cart total

In this exercise we will use the Summary node, which allows the developer to define a section to summarize information from the grid of selected items. In this section we will place a total amount that will be the sum to be paid for the selected products.

  1. Right-click on the multiple selection node and select Add / Attributes.
    AddAttributes
    Add Attributes

  2. Add a variable with the following properties:
  3. Name:Total
  4. BasedOn: ProductPrice
  5. Description: Total
  6. Save the web panel to update the web form and variables.
  7. Once the variable has been defined, we need to program the code that will update the total value.
    To do so, we have to increase the total in the Load event of the selected items grid.
    To quickly access the subroutine that we need to implement, we can use the GoToEvent property of the multiple selection node.
    GoToEvent
    Go To Event

  8. Right-click on the multiple selection node and in Go To Event select the "U_LoadSelectedGridRowsVar".
  9. This subroutine is invoked in the Load event of the grid with selected products before loading each one. The product number that will be loaded is indicated by the variable &SelectedGridLoadCount_MultipleSelection. Therefore, if it is the first product we start the total variable; otherwise, we increase the value of the existing variable. To do so, place the following code in the subroutine.

    If &SelectedGridLoadCount_MultipleSelection = 1
    &Total = &Selected_ProductPrice
    Else
    &Total += &Selected_ProductPrice
    EndIf

    Subroutine code
  10. Press F5 to execute the web panel to see the result.