Skip to main content

The ChangeQuantity Method 2

Next we determine whether we are changing the quantity of adult tickets or child tickets by examining the TicketType argument. We can then adjust the total charge stored in the TicketOrder object and store the new quantity into the AdultTickets or ChildTickets property of the TicketItem object.

ClassMethod ChangeQuantity(
        ItemNum As %Integer, 
        TicketType As %Integer, 
        NewQuantity As %Integer)
    If $data(%session.Data("Order")) {
        // Open the current order object
        Set ord = ##class(Cinema.TicketOrder).%OpenId(%session.Data("Order"))

        // Update quantity
        Set itm=ord.Items.GetAt(ItemNum)

        // Determine if we are changing
        // adult or child tickets
        If ( TicketType = 1) {
            // Adjust the total price
            Set ord.Total = ord.Total +
                ((NewQuantity - itm.AdultTickets) * itm.Show.Theater.AdultPrice)
            // Update the number of tickets
            Set itm.AdultTickets = NewQuantity
        Else {
            Set ord.Total = ord.Total +
                ((NewQuantity - itm.ChildTickets) * itm.Show.Theater.ChildPrice)
            Set itm.ChildTickets = NewQuantity
        // ...
FeedbackOpens in a new tab