SOLVED

Creating a Total Amount in Velocity Scripting

Go to solution
Highlighted
Anonymous
Not applicable

Creating a Total Amount in Velocity Scripting

I am trying to create a velocity scripting table that is able to add the total amount of what a person purchased. I am able to pull all the Custom Object data in, but have not successfully added multiple variables. I did find the $math.add( object1, object2 ) function but have been unable to render correctly the $transaction.price if the user has multiple transactions. Has anyone had success adding multiple variables in Velocity Scripting? Current code pasted below.

#set ( $totalprice = 0 )

<table border="1">

  <tr>

  <th>Product Description</th><th>Last Four CC</th><th>Shipping Address</th><th>Shipping Date</th><th>Amount</th>

  </tr>

    #foreach($transaction in $transactions_cList)

  <tr>

  <td>$transaction.description</td>

  <td>$transaction.lastfour</td>

  <td>$transaction.shippingstreetaddress</td>

  <td>$transaction.requiredshipdate</td>

  <td>$transaction.price</td>

  </tr>               

  #end

  <tr>

  <td colspan=5>Total: </td>

  </tr>

</table>

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Level 10 - Community Moderator

Re: Creating a Total Amount in Velocity Scripting

I don't know where you were trying to do the math. Have you done:

#set( $totalPrice = 0)

#foreach( $transaction in $transaction_cList )

     #set ( $totalPrice = $math.add( $totalPrice, $transaction.price ) )

#end

View solution in original post

2 REPLIES 2
Highlighted
Level 10 - Community Moderator

Re: Creating a Total Amount in Velocity Scripting

I don't know where you were trying to do the math. Have you done:

#set( $totalPrice = 0)

#foreach( $transaction in $transaction_cList )

     #set ( $totalPrice = $math.add( $totalPrice, $transaction.price ) )

#end

View solution in original post

Highlighted
Anonymous
Not applicable

Re: Creating a Total Amount in Velocity Scripting

Excellent Sanford.

That is exactly what I was missing!