From 5f8b5286f37c9e8f58f94f604cc0664883d1d4ff Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Sun, 2 Sep 2018 16:24:25 +0100 Subject: [PATCH] now using new APIv2 field for _remaining_capacity --- fulcrm_shoppingcart.module | 39 +++----------------------------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index e915e2b..de4f7ca 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -500,35 +500,6 @@ 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(); @@ -613,7 +584,9 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe '#options' => array(), ); $eventslot_id = fulcrm_crypto_object_id_form_value( 'eventslot.id', $eventslot[ 'id' ] ); - $form[ 'eventslots' ][ $eventpart_key ][ '#options' ][ $eventslot_id ] = $eventslot[ 'name' ]; + $remaining_capacity = $eventslot[ '_remaining_capacity' ]; + if ( is_null( $remaining_capacity ) || ( $remaining_capacity > 0 ) ) + $form[ 'eventslots' ][ $eventpart_key ][ '#options' ][ $eventslot_id ] = $eventslot[ 'name' ]; } $choices = false; @@ -623,12 +596,6 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe $eventpart[ '#default_value' ] = $option_key; } else { $choices = true; - foreach ( $eventpart[ '#options' ] as $option_key => $option_value ) { - $eventslot_id = fulcrm_crypto_get_object_id_form_value( 'eventslot.id', $option_key ); - if ( $eventslot_id && !fulcrm_shoppingcart_eventslot_has_capacity( $eventslot_id ) ) { - unset( $eventpart[ '#options' ][ $option_key ] ); - } - } } }