Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLR - do not clear session for incomplete orders #3335

Draft
wants to merge 1 commit into
base: feat/slr-support
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Tickets/Seating/Frontend/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,11 @@ public function get_session_token_object_id(): ?array {
*
* @since TBD
*
* @param bool $delete_token_session Whether to delete the token session after confirming the reservations.
*
* @return bool Whether the reservations were confirmed or not.
*/
public function confirm_all_reservations(): bool {
public function confirm_all_reservations(bool $delete_token_session = true): bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[phpcs] reported by reviewdog 🐶
Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen
Expected 1 spaces after opening parenthesis; 0 found

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[phpcs] reported by reviewdog 🐶
Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose
Expected 1 spaces before closing parenthesis; 0 found

$confirmed = true;

foreach ( $this->get_entries() as $post_id => $token ) {
Expand All @@ -334,8 +336,11 @@ public function confirm_all_reservations(): bool {
continue;
}

$confirmed &= $this->reservations->confirm( $post_id, $reservation_uuids )
&& $this->sessions->delete_token_session( $token );
$confirmed = $this->reservations->confirm( $post_id, $reservation_uuids );

if ( $confirmed && $delete_token_session ) {
$confirmed &= $this->sessions->delete_token_session( $token );
}
}

return $confirmed;
Expand Down
39 changes: 34 additions & 5 deletions src/Tickets/Seating/Orders/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use TEC\Common\StellarWP\Assets\Asset;
use TEC\Common\StellarWP\DB\DB;
use TEC\Tickets\Admin\Attendees\Page as Attendee_Page;
use TEC\Tickets\Commerce\Order;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[phpcs] reported by reviewdog 🐶
SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse
Type TEC\Tickets\Commerce\Order is not used in this file.

use TEC\Tickets\Commerce\Shortcodes\Checkout_Shortcode;
use TEC\Tickets\Seating\Admin\Ajax;
use TEC\Tickets\Seating\Ajax_Methods;
Expand All @@ -31,6 +32,7 @@
use Tribe__Tickets__Tickets as Tickets;
use WP_Post;
use WP_Query;
use TEC\Tickets\Commerce\Status\Status_Interface;

/**
* Class Controller
Expand Down Expand Up @@ -166,7 +168,11 @@ protected function do_register(): void {
// Attendee delete handler.
add_filter( 'tec_tickets_commerce_attendee_to_delete', [ $this, 'handle_attendee_delete' ] );

add_action( 'tec_tickets_commerce_flag_action_generated_attendees', [ $this, 'confirm_all_reservations' ] );
add_action( 'tec_tickets_commerce_flag_action_generated_attendees', [ $this, 'confirm_all_reservations' ], 10, 4 );
add_action(
'tec_tickets_commerce_order_status_flag_complete',
[ $this, 'confirm_all_reservations_on_completion' ]
);
add_action( 'wp_ajax_' . Ajax::ACTION_FETCH_ATTENDEES, [ $this, 'fetch_attendees_by_post' ] );
add_action( 'wp_ajax_' . Ajax::ACTION_RESERVATION_CREATED, [ $this, 'update_reservation' ] );
add_action( 'wp_ajax_' . Ajax::ACTION_RESERVATION_UPDATED, [ $this, 'update_reservation' ] );
Expand Down Expand Up @@ -247,6 +253,10 @@ public function unregister(): void {
remove_filter( 'post_row_actions', [ $this, 'add_seats_row_action' ] );

remove_action( 'tec_tickets_commerce_flag_action_generated_attendees', [ $this, 'confirm_all_reservations' ] );
remove_action(
'tec_tickets_commerce_order_status_flag_complete',
[ $this, 'confirm_all_reservations_on_completion' ]
);
remove_action( 'wp_ajax_' . Ajax::ACTION_FETCH_ATTENDEES, [ $this, 'fetch_attendees_by_post' ] );
remove_action( 'wp_ajax_' . Ajax::ACTION_RESERVATION_CREATED, [ $this, 'update_reservation' ] );
remove_action( 'wp_ajax_' . Ajax::ACTION_RESERVATION_UPDATED, [ $this, 'update_reservation' ] );
Expand Down Expand Up @@ -346,7 +356,7 @@ public function register_seat_tab( $tabbed_view, $post ) {
if ( ! $post ) {
return;
}

if ( ! tec_tickets_seating_enabled( $post->ID ) ) {
return;
}
Expand Down Expand Up @@ -455,14 +465,22 @@ public function remove_move_row_action( $default_row_actions, $item ) {
}

/**
* Confirms all the reservations contained in the Session cookie.
* Confirms all the reservations contained in the Session cookie on generation of an Attendee.
* If the order status is complete, it will also delete the token session.
*
* @since TBD
*
* @param array<Attendee> $attendees The generated attendees, unused.
* @param \Tribe__Tickets__Tickets $ticket The ticket the attendee is generated for, unused.
* @param \WP_Post $order The order the attendee is generated for, unused.
* @param Status_Interface $new_status New post status.
*
* @return void
*/
public function confirm_all_reservations(): void {
$this->session->confirm_all_reservations();
public function confirm_all_reservations($attendees, $ticket, $order, $new_status): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[phpcs] reported by reviewdog 🐶
Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen
Expected 1 spaces after opening parenthesis; 0 found

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[phpcs] reported by reviewdog 🐶
Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingBeforeClose
Expected 1 spaces before closing parenthesis; 0 found

$incomplete_flags = array_intersect( $new_status->get_flags(), [ 'incomplete', 'count_incomplete' ] );
$delete_session = count( $incomplete_flags ) === 0;
$this->session->confirm_all_reservations( $delete_session );
}

/**
Expand Down Expand Up @@ -786,4 +804,15 @@ public function update_reservation(): void {
public function add_seats_row_action( array $actions, $post ): array {
return $this->seats_report->add_seats_row_action( $actions, $post );
}

/**
* On completion of a TC Order, confirm all the reservations and clear the session.
*
* @since TBD
*
* @return void
*/
public function confirm_all_reservations_on_completion(): void {
$this->session->confirm_all_reservations();
}
}
Loading