-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: feat/slr-support
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [phpcs] reported by reviewdog 🐶 |
||
$confirmed = true; | ||
|
||
foreach ( $this->get_entries() as $post_id => $token ) { | ||
|
@@ -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; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [phpcs] reported by reviewdog 🐶 |
||
use TEC\Tickets\Commerce\Shortcodes\Checkout_Shortcode; | ||
use TEC\Tickets\Seating\Admin\Ajax; | ||
use TEC\Tickets\Seating\Ajax_Methods; | ||
|
@@ -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 | ||
|
@@ -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' ] ); | ||
|
@@ -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' ] ); | ||
|
@@ -346,7 +356,7 @@ public function register_seat_tab( $tabbed_view, $post ) { | |
if ( ! $post ) { | ||
return; | ||
} | ||
|
||
if ( ! tec_tickets_seating_enabled( $post->ID ) ) { | ||
return; | ||
} | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [phpcs] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [phpcs] reported by reviewdog 🐶 |
||
$incomplete_flags = array_intersect( $new_status->get_flags(), [ 'incomplete', 'count_incomplete' ] ); | ||
$delete_session = count( $incomplete_flags ) === 0; | ||
$this->session->confirm_all_reservations( $delete_session ); | ||
} | ||
|
||
/** | ||
|
@@ -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(); | ||
} | ||
} |
There was a problem hiding this comment.
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