From f58c48dc23692b6817a84dbc52bb72fe542c5a07 Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Sun, 2 Sep 2018 13:36:30 +0100 Subject: [PATCH] add fulcrm_shoppingcart_eventslot_has_capacity --- fulcrm_shoppingcart.module | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index bd70e17..f252f72 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -499,6 +499,35 @@ function fulcrm_shoppingcart_event_has_capacity( $event_id ) { return TRUE; } +function fulcrm_shoppingcart_eventslot_has_capacity( $eventslot_id ) { + $capacity = null; + $count = null; + $api_data = fulcrm_apiv2_GET( 'eventslot/' . $event_id . '/', + $query = array( 'expand' => 'eventpart,eventpart.event' ) ); + if ( $api_data[ 'success' ] ) { + $capacities = array( $api_data[ 'data' ][ 'eventpart' ][ 'event' ][ 'capacity' ], + $api_data[ 'data' ][ 'eventpart' ][ 'capacity' ], + $api_data[ 'data' ][ 'capacity' ] ); + foreach ( $capacities as $cap ) { + if ( !is_null( $cap ) ) + $capacity = $cap; + } + } + + $api_data = fulcrm_apiv2_GET( 'eventslotbooking/', $query = array( 'eventslot' => $eventslot_id, + 'eventbooking__confirmed__isnull' => 'False', + 'eventbooking__cancelled__isnull' => 'True', + ) ); + if ( $api_data[ 'success' ] ) + $count = $api_data[ 'data' ][ 'count' ]; + + if ( !is_null( $capacity ) && !is_null( $count ) ) { + if ( $count >= $capacity ) + return FALSE; + } + return TRUE; +} + function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $person, $eventbookingtype, $product ) { $form = array();