From 63a51abd24fb5ab713d2e1598a9197aeb9c4384a Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Sun, 2 Sep 2018 15:09:28 +0100 Subject: [PATCH] now checking capacity and showing options --- fulcrm_shoppingcart.module | 43 +++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index f252f72..1b9c201 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -590,6 +590,44 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe $form[ '#submit' ] = 'fulcrm_shoppingcart_buy_eventbookingtype_person_add_guest_form_submit'; } + $form[ 'eventslots' ] = array( '#title' => 'Options', + '#type' => 'fieldset', + ); + $eventslots = array(); + $eventpart = array(); + foreach ( $eventbookingtype[ 'event' ][ 'eventparts' ] as $eventpart ) { + $eventparts[ $eventpart[ 'id' ] ] = $eventpart; + foreach ( $eventpart[ 'eventslots' ] as $eventslot ) { + $eventslots[ $eventslot[ 'id' ] ] = $eventslot; + } + } + + foreach ( $eventbookingtype[ 'eventbookingtypeslots' ] as $ebts ) { + $eventslot = $ebts[ 'eventslot' ]; + $eventpart_id = fulcrm_apiv2_url_to_pk( $eventslot[ 'eventpart' ] ); + if ( !array_key_exists( $eventpart_id, $form[ 'eventslots' ] ) ) + $form[ 'eventslots' ][ $eventpart_id ] = array( '#type' => 'radios', + '#title' => $eventparts[ $eventpart_id ][ 'name' ], + '#options' => array(), + ); + $eventslot_id = fulcrm_crypto_object_id_form_value( 'eventslot.id', $eventslot[ 'id' ] ); + $form[ 'eventslots' ][ $eventpart_id ][ '#options' ][ $eventslot_id ] = $eventslot[ 'name' ]; + } + + foreach ( $form[ 'eventslots' ] as $eventpart_id => $eventpart ) { + if ( count( $eventpart[ '#options' ] ) == 1 ) { + foreach ( $eventpart[ '#options' ] as $option_key => $option_value ) + $eventpart[ '#default_value' ] = $option_key; + } else { + 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 ] ); + } + } + } + } + $form[ 'actions' ] = array( '#type' => 'actions' ); $form[ 'actions' ][ 'submit' ] = array( '#type' => 'submit', '#value' => t('Add to Cart'), @@ -793,7 +831,10 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) { 'person_ddatacollection', 'eventbooking_ddatacollection', 'eventbookingtypeslots', - 'eventbookingtypeslots.eventslot' ) ) ) ); + 'eventbookingtypeslots.eventslot', + 'event', + 'event.eventparts', + 'event.eventparts.eventslots' ) ) ) ); if ( !$eventbookingtype_data[ 'success' ] ) { return 'error while fetching information about your booking!'; }