Skip to main content

Obtaining a TicketOrder Object

Add the code shown below to the body of the AddShow method.

The first thing our method does is obtain a TicketOrder object. If this is a new order, we need to create a new TicketOrder object. On the other hand, if we are in the middle of processing an order for this user, the object already exists within the database (with its Complete property set to 0).

If we have already created a TicketOrder object, its object ID is stored in the %session object (an instance of the %CSP.SessionOpens in a new tab class). (We will see how it gets there in a minute.) Like the %request object that we used earlier, the %session object is provided by Caché and it stores name / value pairs. But, unlike the %request object, which is different for each request, the %session object stores data across requests, for as long as a user's session lasts. (We'll look at sessions in detail a little later.)

—Utils.AddShow—
Utils.AddShow
ClassMethod AddShow(ShowID As %String)
{
    // Get an order object
    If $data(%session.Data("Order")) {
        Set ord = ##class(Cinema.TicketOrder).%OpenId(%session.Data("Order"))
    }
    Else {
        Set ord=##class(Cinema.TicketOrder).%New()
        // ...
    }

    // ...

    // Save incomplete order and remember its Id in %session.
    Do ord.%Save()
    Set %session.Data("Order") = ord.%Id()
}
FeedbackOpens in a new tab