-
Notifications
You must be signed in to change notification settings - Fork 41
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
[SL-253] Update seating availability calculation depending on seat reservation. #3461
Open
rafsuntaskin
wants to merge
83
commits into
master
Choose a base branch
from
feat/sl-253-calc-seating-availablity
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,181
−337
Open
Changes from all commits
Commits
Show all changes
83 commits
Select commit
Hold shift + click to select a range
ceeac15
added new filter method
rafsuntaskin 50ee94c
replace usages
rafsuntaskin 7a2089e
fix return cast
rafsuntaskin f62e70a
apply filter for seating attendees
rafsuntaskin 5080366
filter by reservation meta
rafsuntaskin dc364b3
call stock method once
rafsuntaskin a985564
skip non reservation attendee from attendee counts
rafsuntaskin c379837
sync total sales with new attendee count
rafsuntaskin afaeaa2
skip non reservation attendees from count
rafsuntaskin df2bf5e
added stock filter
rafsuntaskin db44468
WIP: stock meta read filter
rafsuntaskin b4bad76
Merge branch 'release/T24.hydra' into feat/sl-253-calc-seating-availa…
rafsuntaskin 66a7302
WIP: revert stock filter
rafsuntaskin 9367a20
Fixed casting bug with inarray check
rafsuntaskin ccab1e5
Filter stock with seating inventory
rafsuntaskin 50342a7
cache stock filter
rafsuntaskin 7f24748
Merge branch 'release/T24.hydra' into feat/sl-253-calc-seating-availa…
rafsuntaskin b7996e3
update doc block
rafsuntaskin 02f88e2
updated filter doc block
rafsuntaskin e5f80f8
tests updated attendee meta
rafsuntaskin 09ef598
tests updated more meta
rafsuntaskin 752f873
updated more tests
rafsuntaskin 4881358
tests - avoid direct stock meta check
rafsuntaskin 65bb792
tests - fix attendees fetch
rafsuntaskin c3833ab
tests - add deletion mock
rafsuntaskin 96f2308
fixed stock count filter
rafsuntaskin 50fb64f
tests- updated attendee meta
rafsuntaskin 1e5da35
tests - fix attendee meta update
rafsuntaskin 961f4bc
Fix - remove reservation meta on layout update
rafsuntaskin a710373
Tests - adjusted AjaxTest with new updates
rafsuntaskin 13a3bfa
Tests - adjusted EditorTest
rafsuntaskin e646eb7
Tests - adjusted TimerTest
rafsuntaskin 1d2e2c8
Tests - phpcbf
rafsuntaskin c4def17
tests - update SeatTypes tests where orders are placed
rafsuntaskin 4b6a6fc
tests - update SeatTypes tests where orders are placed 2
rafsuntaskin dc9c9e0
tests - update SeatTypes tests where orders are placed 3
rafsuntaskin 6dc28f2
tests - updated orders controller
rafsuntaskin a2a7ef8
Merge branch 'release/T24.hydra' into feat/sl-253-calc-seating-availa…
rafsuntaskin 03aea9c
fix phpcbf
rafsuntaskin 90197f6
Merge branch 'release/T24.hydra' into feat/sl-253-calc-seating-availa…
rafsuntaskin 5d978c4
Version bump for release/T24.imp
codingmusician f0fd943
fixed total sales update
rafsuntaskin 41f2fe2
Merge branch 'release/T24.hydra' into feat/sl-253-calc-seating-availa…
rafsuntaskin ab8636c
phpcbf
rafsuntaskin 86f3dae
tests - new scenario added to cover removal of reservations
rafsuntaskin ad2a57f
changelog added
rafsuntaskin d4228a6
simplified logic
rafsuntaskin a380442
Merge branch 'release/T24.hydra' into feat/sl-253-calc-seating-availa…
rafsuntaskin b5d4640
update snapshot
codingmusician 135e4ee
update snapshot
codingmusician 2270287
fix snapshot
codingmusician 7b95169
fix snapshot
codingmusician 2fbf3a9
remove min
codingmusician e0bddfa
fix logic
codingmusician aaf8ad2
update tests
codingmusician 6a337b3
Merge pull request #3458 from the-events-calendar/task/version-bump-r…
codingmusician 2fdd1af
Merge branch 'master' into release/T24.imp
Camwyn cb7f745
Merge branch 'master' into feat/sl-253-calc-seating-availablity
rafsuntaskin 099ee52
Update src/Tribe/Tickets.php
rafsuntaskin 5fdeef6
Merge remote-tracking branch 'origin/release/T25.imp' into fix/ET-227…
codingmusician 1c12e97
changelog
codingmusician 8eeff0c
spacing fix
codingmusician 79bc8da
update doc
codingmusician 3973892
typo
codingmusician bb8e1b3
update wp version in tests
codingmusician 03da5d8
update snapshot
codingmusician fc12e3f
Merge pull request #3462 from the-events-calendar/fix/ET-2273-et-remo…
codingmusician c7b371e
Added an empty array as a default value for foreign key check.
sdokus d6b3ca7
Prevent aggressive hook update
dpanta94 68022a2
Merge branch 'release/T25.imp' into fix/revert-aggresive-hook-update
dpanta94 72153ac
Fix ft_smoketest suite
dpanta94 149a1d0
Fix wpunit suite
dpanta94 14ad43b
added changelog
dpanta94 09aae6f
Merge pull request #3465 from the-events-calendar/fix/revert-aggresiv…
lucatume 4a9cfd9
Merge branch 'release/T25.imp' into fix/ET-2275-maybe-disable-foreign…
sdokus 23f67f7
Added safeguards to avoid warnings
sdokus 3f75498
Revised phrasing of if conditional
sdokus 6749b2f
Merge pull request #3464 from the-events-calendar/fix/ET-2275-maybe-d…
sdokus 53d9a8d
Merge branch 'release/T25.imp' into feat/sl-253-calc-seating-availablity
rafsuntaskin 01d0dbb
moved filter to main method
rafsuntaskin 8d03ebd
revert new metho usages
rafsuntaskin 72f1a4a
apply new filter for ticketscommerce
rafsuntaskin dfa5bb7
removed old overrride method
rafsuntaskin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: feat | ||
|
||
Seated tickets stock now calculated from attendee reservation count. [SL-253] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: fix | ||
|
||
Screen options will no longer be disabled when Event Tickets is active. [ET-2273] |
4 changes: 4 additions & 0 deletions
4
changelog/fix-ET-2275-maybe-disable-foreign-keys-default-array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: fix | ||
|
||
Added a default empty array to `maybe_disable_foreign_key_checks`. [ET-2275] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: fix | ||
|
||
Reverts aggressive hook update, causing fatals on installtion with themes overwritting the template `Single Ticket Item`. [ET-2276] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
use Tribe__Tickets__Tickets as Tickets; | ||
use Tribe__Tickets__Tickets_Handler as Tickets_Handler; | ||
use WP_Post; | ||
use Tribe__Cache_Listener as Triggers; | ||
|
||
/** | ||
* Class Controller. | ||
|
@@ -104,6 +105,7 @@ protected function do_register(): void { | |
add_filter( 'update_post_metadata', [ $this, 'handle_ticket_meta_update' ], 10, 4 ); | ||
add_action( 'before_delete_post', [ $this, 'restock_ticket_on_attendee_deletion' ], 10, 2 ); | ||
add_action( 'wp_trash_post', [ $this, 'restock_ticket_on_attendee_trash' ] ); | ||
add_filter( 'tec_tickets_ticket_stock', [ $this, 'filter_ticket_stock_value' ], 10, 2 ); | ||
} | ||
|
||
/** | ||
|
@@ -124,6 +126,42 @@ public function unregister(): void { | |
remove_filter( 'update_post_metadata', [ $this, 'handle_ticket_meta_update' ], 10 ); | ||
remove_action( 'before_delete_post', [ $this, 'restock_ticket_on_attendee_deletion' ] ); | ||
remove_action( 'wp_trash_post', [ $this, 'restock_ticket_on_attendee_trash' ] ); | ||
remove_filter( 'tec_tickets_ticket_stock', [ $this, 'filter_ticket_stock_value' ] ); | ||
} | ||
|
||
/** | ||
* Filters the stock value for a ticket to match the seated ticket inventory. | ||
* | ||
* @since TBD | ||
* | ||
* @param int $stock The stock value. | ||
* @param Ticket_Object $ticket The ticket object. | ||
* | ||
* @return int The filtered stock value. | ||
*/ | ||
public function filter_ticket_stock_value( $stock, $ticket ) { | ||
$seat_type = get_post_meta( $ticket->ID, Meta::META_KEY_SEAT_TYPE, true ); | ||
if ( ! $seat_type ) { | ||
return $stock; | ||
} | ||
|
||
$cache_key = sprintf( 'seating_filter_ticket_stock_value_%d_%s', $stock, $ticket->ID ); | ||
|
||
$cache = tribe_cache(); | ||
|
||
// This cached value will be invalidated by the save of any Ticket, Attendee or Order. | ||
$cached = $cache->get( $cache_key, Triggers::TRIGGER_SAVE_POST, null, DAY_IN_SECONDS ); | ||
|
||
if ( is_int( $cached ) ) { | ||
return $cached; | ||
} | ||
|
||
$attendees = $ticket->get_provider()->get_attendees_by_id( $ticket->get_event()->ID ); | ||
$stock = $this->get_seated_ticket_inventory( $stock, $ticket, $attendees ); | ||
|
||
$cache->set( $cache_key, $stock, Triggers::TRIGGER_SAVE_POST, DAY_IN_SECONDS ); | ||
|
||
return $stock; | ||
} | ||
|
||
/** | ||
|
@@ -172,21 +210,25 @@ public function set_event_stock_counts( $types, $post_id ): array { | |
if ( empty( $seat_type ) ) { | ||
continue; | ||
} | ||
|
||
$capacity = $ticket->capacity(); | ||
$stock = $ticket->stock(); | ||
$sold_qty = $ticket->qty_sold(); | ||
|
||
|
||
if ( $stock ) { | ||
$sold_qty = min( $capacity - $stock, $sold_qty ); | ||
} | ||
|
||
if ( ! isset( $capacity_by_type[ $seat_type ] ) ) { | ||
$capacity_by_type[ $seat_type ] = $capacity; | ||
} | ||
|
||
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. Remove these tabs. |
||
if ( ! isset( $total_sold_by_type[ $seat_type ] ) ) { | ||
$total_sold_by_type[ $seat_type ] = $sold_qty; | ||
} else { | ||
$total_sold_by_type[ $seat_type ] += $sold_qty; | ||
} | ||
|
||
++$types['tickets']['count']; | ||
} | ||
|
||
|
@@ -227,7 +269,7 @@ public function get_seated_ticket_inventory( int $inventory, Ticket_Object $tick | |
$return_false = static fn() => false; | ||
add_filter( 'tribe_tickets_ticket_object_is_ticket_cache_enabled', $return_false ); | ||
|
||
$ticket_ids = [ $ticket->ID ]; | ||
$ticket_ids = [ (int) $ticket->ID ]; | ||
|
||
// Pull the inventory from the other tickets with the same seat type. | ||
foreach ( | ||
|
@@ -245,7 +287,9 @@ public function get_seated_ticket_inventory( int $inventory, Ticket_Object $tick | |
$total_sold = count( | ||
array_filter( | ||
$event_attendees, | ||
static fn( array $attendee ): bool => in_array( (int) $attendee['product_id'], $ticket_ids, true ) | ||
static fn( array $attendee ): bool => | ||
in_array( (int) $attendee['product_id'], $ticket_ids, true ) | ||
&& ! empty( get_post_meta( $attendee['ID'], Meta::META_KEY_RESERVATION_ID, true ) ) | ||
) | ||
); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove these tabs.