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

[SL-240] - Feat - Create Woo Tickets with Seating. WIP #3481

Open
wants to merge 17 commits into
base: bucket/woo-seating-integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 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
5 changes: 0 additions & 5 deletions src/Tickets/Seating/Frontend/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,6 @@ public function confirm_all_reservations( bool $delete_token_session = true ): b
* @return array|null The reservations for the ticket and post.
*/
public function get_post_ticket_reservations( int $post_id = null, int $ticket_id = null ): ?array {
// Bail while in admin side always. There are no reservations in the admin.
if ( is_admin() ) {
return null;
}

Comment on lines -361 to -365
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method that is just checking if the reservation data exists. No need to keep it behind admin check.

if ( ! ( $ticket_id && $post_id && tec_tickets_seating_enabled( $post_id ) ) ) {
return null;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Tickets/Seating/Orders/Attendee.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace TEC\Tickets\Seating\Orders;

use TEC\Tickets\Commerce\Module;
use Tribe__Main as Common;
use Tribe__Tickets__Attendee_Repository as Attendee_Repository;
use Tribe__Utils__Array as Arr;
Expand All @@ -20,6 +19,7 @@
use WP_Query;
use WP_Post;
use Tribe__Tickets__Ticket_Object as Ticket_Object;
use Tribe__Tickets__RSVP as RSVP_Provider;

/**
* Class Attendee
Expand Down Expand Up @@ -69,11 +69,11 @@ public function render_seat_column( $value, $item, $column ) {
return $value;
}

if ( ! isset( $item['ID'] ) ) {
if ( ! isset( $item['attendee_id'] ) ) {
return '-';
}

$seat_label = get_post_meta( $item['ID'], Meta::META_KEY_ATTENDEE_SEAT_LABEL, true );
$seat_label = get_post_meta( $item['attendee_id'], Meta::META_KEY_ATTENDEE_SEAT_LABEL, true );

if ( ! empty( $seat_label ) ) {
return $seat_label;
Expand Down Expand Up @@ -302,11 +302,11 @@ public function inject_seat_info_in_my_tickets( string $html, Template $template
public function format_many( array $attendees ): array {
$unknown_attendee_name = __( 'Unknown', 'event-tickets' );

// Filter out attendees that are not from the Commerce module.
// Filter out attendees that are from the RSVP provider.
$attendees = array_filter(
$attendees,
static function ( array $attendee ): bool {
return Module::class === $attendee['provider'];
return RSVP_Provider::class !== $attendee['provider'];
}
);

Expand Down
4 changes: 3 additions & 1 deletion src/Tickets/Seating/app/blockEditor/filters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { addFilter, addAction } from '@wordpress/hooks';
import CapacityForm from './capacity-form';
import { storeName } from './store';
import { currentProviderSupportsSeating } from './store/compatibility';
import { select } from '@wordpress/data';
import Seats from './dashboard-actions/seats';
import { filterCapacityTableMappedProps } from './capacity-table';
Expand Down Expand Up @@ -34,7 +35,8 @@ function filterRenderCapacityForm(renderDefaultForm, { clientId, ticketProvider
return renderDefaultForm;
}

if ( ticketProvider !== "TEC\\Tickets\\Commerce\\Module" && ticketProvider !== 'tc' ) {
// When the provider does not support seating, we render the default form.
if ( ! currentProviderSupportsSeating() ) {
return renderDefaultForm;
}

Expand Down
14 changes: 13 additions & 1 deletion src/Tickets/Seating/app/blockEditor/store/compatibility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { applyFilters } from '@wordpress/hooks';
import { getTicketProviderFromCommonStore } from './common-store-bridge';

/**
Expand All @@ -14,5 +15,16 @@ import { getTicketProviderFromCommonStore } from './common-store-bridge';
export function currentProviderSupportsSeating() {
const provider = getTicketProviderFromCommonStore();

return 'TEC\\Tickets\\Commerce\\Module' === provider;
/**
* Filter the allowed ticket providers for seating.
*
* @since TBD
*
* @param {string[]} allowedProviders The allowed ticket providers for seating.
*/
let allowedProviders = applyFilters( 'tec.tickets.seating.allowedProviders', [
'TEC\\Tickets\\Commerce\\Module',
] );

return allowedProviders.includes( provider );
}
2 changes: 1 addition & 1 deletion src/Tickets/Seating/app/frontend/session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ export function watchCheckoutControls() {
*
* @since 5.16.0
*
* @type {string} The `querySeelctorAll` selectors used to find the checkout controls on the page.
* @type {string} The `querySelectorAll` selectors used to find the checkout controls on the page.
*/
const filteredCheckoutControls = applyFilters(
'tec.tickets.seating.frontend.session.checkoutControls',
Expand Down
9 changes: 8 additions & 1 deletion src/Tribe/Commerce/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ public function hook() {
* @since 4.11.0
*/
public function process_cart() {
if ( empty( $_POST['tribe_tickets_ar'] ) || is_admin() ) {
$has_tickets = tec_get_request_var( 'tribe_tickets_ar' );

if ( empty( $has_tickets ) ) {
return;
}

if ( ! wp_doing_ajax() && is_admin() ) {
return;
}


$data = $_POST;

Expand Down
23 changes: 22 additions & 1 deletion tests/slr_jest/blockEditor/store/compatibility.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { currentProviderSupportsSeating } from '@tec/tickets/seating/blockEditor/store/compatibility';
import commonStoreBridge from '@tec/tickets/seating/blockEditor/store/common-store-bridge';
import { addFilter } from "@wordpress/hooks";
jest.mock('@tec/tickets/seating/blockEditor/store/common-store-bridge', () => ({
getTicketProviderFromCommonStore: jest.fn(),
}));
Expand Down Expand Up @@ -31,12 +32,32 @@ describe('compatibility.js', () => {
expect(currentProviderSupportsSeating()).toBe(true);
});

test('returns true if current provider is not Tickets Commerce', () => {
test('returns false if current provider is not Tickets Commerce', () => {
commonStoreBridge.getTicketProviderFromCommonStore.mockReturnValue(
'Some__Other__Provider'
);

expect(currentProviderSupportsSeating()).toBe(false);
});

test( 'returns true if current provider is in allowed provider list', () => {
commonStoreBridge.getTicketProviderFromCommonStore.mockReturnValue(
'Some__Other__Provider'
);

addFilter( 'tec.tickets.seating.allowedProviders', 'test', () => {
return [ 'Some__Other__Provider' ];
} );

expect( currentProviderSupportsSeating() ).toBe( true );
} );

test('returns false if current provider is undefined', () => {
commonStoreBridge.getTicketProviderFromCommonStore.mockReturnValue(
undefined
);

expect(currentProviderSupportsSeating()).toBe(false);
});
});
});
Loading