Orders::setup_template_vars()
Sets up the template variables used to render the Orders Report Page.
Return
(array)
Source
File: src/Tickets/Commerce/Reports/Orders.php
public function setup_template_vars() {
$post_id = tribe_get_request_var( 'post_id' );
$post_id = tribe_get_request_var( 'event_id', $post_id );
$post = get_post( $post_id );
$post_type_object = get_post_type_object( $post->post_type );
$post_singular_label = $post_type_object->labels->singular_name;
$tickets = \Tribe__Tickets__Tickets::get_event_tickets( $post_id );
$ticket_ids = tribe_get_request_var( 'product_ids', false );
if ( false !== $ticket_ids ) {
$ticket_ids = array_map( 'absint', explode( ',', $ticket_ids ) );
$ticket_ids = array_filter(
$ticket_ids,
static function ( $ticket_id ) {
return get_post_type( $ticket_id ) === Commerce\Ticket::POSTTYPE;
}
);
$tickets = array_map( [ tribe( Commerce\Ticket::class ), 'get_ticket' ], $ticket_ids );
}
$tickets = array_filter(
$tickets,
static function ( $ticket ) {
return Module::class === $ticket->provider_class;
}
);
$event_data = [];
$tickets_data = [];
$thousands_sep = tribe( \Tribe__Tickets__Commerce__Currency::class )->get_currency_locale( 'thousands_sep' );
foreach ( $tickets as $ticket ) {
$quantities = tribe( Commerce\Ticket::class )->get_status_quantity( $ticket->ID );
$total_by_status = [];
foreach ( $quantities as $status_slug => $status_count ) {
if ( ! isset( $event_data['qty_by_status'][ $status_slug ] ) ) {
$event_data['qty_by_status'][ $status_slug ] = 0;
}
if ( ! isset( $event_data['total_by_status'][ $status_slug ] ) ) {
$event_data['total_by_status'][ $status_slug ] = [];
}
$event_data['total_by_status'][ $status_slug ][] = $total_by_status[ $status_slug ] = str_replace( $thousands_sep, '', Price::sub_total( $ticket->price, $status_count ) );
$event_data['qty_by_status'][ $status_slug ] += (int) $status_count;
}
$tickets_data[ $ticket->ID ] = [
'total_by_status' => $total_by_status,
'qty_by_status' => $quantities,
];
}
$event_data['total_by_status'] = array_map(
static function ( $sub_totals ) use ( $thousands_sep ) {
return str_replace( $thousands_sep, '', Price::total( $sub_totals ) );
},
$event_data['total_by_status']
);
$this->template_vars = [
'title' => $this->get_title(),
'orders_table' => tribe( Commerce\Admin_Tables\Orders::class ),
'post' => $post,
'post_id' => $post_id,
'post_type_object' => $post_type_object,
'post_singular_label' => $post_singular_label,
'tickets' => $tickets,
'tickets_data' => $tickets_data,
'event_data' => $event_data,
'tooltip' => tribe( 'tooltip.view' ),
'thousands_sep' => $thousands_sep,
];
return $this->template_vars;
}
Changelog
| Version | Description |
|---|---|
| 5.6.8 | Removed title from template vars, title will be rendered by the Tabbed_View |
| 5.2.0 | Introduced. |