From abaca6c0a4a0144d7548b0371632bae609ed1f0d Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Sun, 2 Sep 2018 09:39:54 +0100 Subject: [PATCH] beginnings of selecting event slot options --- fulcrm_shoppingcart.module | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index ed3cd24..bd70e17 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -329,7 +329,9 @@ function fulcrm_shoppingcart_person_add( $collection_id, $hmac ) { } } -function _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( &$form_state, $cart, $person_uuid, $person_name, $product_id ) { +function _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( &$form_state, $cart, $person_uuid, $person_name, $product_id, $made_choices = array() ) { + $all_choices = array(); + $shoppingitem_name = ( $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'event' ][ 'name' ] . "\r\n" . $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'name' ] . ', ' . $person_name . "\r\n" . $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] ); @@ -340,16 +342,27 @@ function _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( &$form_s $eventpart_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'eventpart' ] ); $eventslot_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'url' ] ); - if ( array_key_exists( $eventpart_id, $eventslotbookings ) ) - drupal_set_message( 'XXX cannot yet cope with multiple choice event slot bookings; defaulting to first.', 'warning' ); + if ( in_array( $eventpart_id, $made_choice ) ) { + $eventslotbookings[ $eventpart_id ] = $made_choice[ $eventpart_id ]; + } else { + $eventslotbookings[ $eventpart_id ] = $eventslot_id; - $eventslotbookings[ $eventpart_id ] = $eventslot_id; + if ( !array_key_exists( $eventpart_id, $eventslotbookings ) ) + $all_choices[ $eventpart_id ] = array(); + $all_choices[ $eventpart_id ][] = $eventslot_id; + } } } else { drupal_set_message( 'XXX no eventbookingtypeslots to choose from?', 'warning' ); } - if ( $person_uuid ) { + $additional_choices = array(); + foreach ( $all_choices as $k => $v ) { + if ( count( $v ) > 1 ) + $additional_choices[ $k ] = $v; + } + + if ( $person_uuid && empty( $additional_choices ) ) { $item = array( 'shoppingcart' => $cart[ 'url' ], 'product' => fulcrm_apiv2_make_url( 'product', $product_id ), 'quantity' => 1.0, @@ -375,7 +388,7 @@ function _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( &$form_s drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' ); } } - + return $additional_choices; } function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_state ) { @@ -438,13 +451,17 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta $add_person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'persons' ][ $add_person_uuid ][ 'name' ]; } - _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart, - $add_person_uuid, $add_person_name, $product_id ); + $ac = _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart, + $add_person_uuid, $add_person_name, $product_id ); } } else { $person = $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ]; - _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart, - $person_uuid, $person[ 'name' ], $product_id ); + $ac = _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart, + $person_uuid, $person[ 'name' ], $product_id ); + } + + if ( !empty( $ac ) ) { + drupal_set_message( t('Choices to make...'), 'warning' ); } } else {