now making bookings with slot choices

master
Marek Isalski 6 years ago
parent eeb23bcfc9
commit 5958c229cb

@ -341,28 +341,13 @@ function _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( &$form_s
foreach ( $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'eventbookingtypeslots' ] as $eventbookingtypeslots ) {
$eventpart_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'eventpart' ] );
$eventslot_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'url' ] );
if ( in_array( $eventpart_id, $made_choice ) ) {
$eventslotbookings[ $eventpart_id ] = $made_choice[ $eventpart_id ];
} else {
$eventslotbookings[ $eventpart_id ] = $eventslot_id;
if ( !array_key_exists( $eventpart_id, $eventslotbookings ) )
$all_choices[ $eventpart_id ] = array();
$all_choices[ $eventpart_id ][] = $eventslot_id;
}
$eventslotbookings[ $eventpart_id ] = $made_choices[ $eventpart_id ];
}
} else {
drupal_set_message( 'XXX no eventbookingtypeslots to choose from?', 'warning' );
}
$additional_choices = array();
foreach ( $all_choices as $k => $v ) {
if ( count( $v ) > 1 )
$additional_choices[ $k ] = $v;
}
if ( $person_uuid && empty( $additional_choices ) ) {
if ( $person_uuid ) {
$item = array( 'shoppingcart' => $cart[ 'url' ],
'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
'quantity' => 1.0,
@ -388,14 +373,15 @@ 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 ) {
// $person_d = fulcrm_collection_form_values_to_d( 'person', $form_state[ 'values' ] );
$product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
$eventbookingtype_id = $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'id' ];
$eventbookingtype = $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ];
$eventbookingtype_id = $eventbookingtype[ 'id' ];
$event = $eventbookingtype[ 'event' ];
$person_uuid = NULL;
if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] ) )
@ -439,8 +425,21 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
}
}
$made_choices = array();
foreach ( $event[ 'eventparts' ] as $eventpart ) {
$key = 'eventpart:' . $eventpart[ 'id' ];
if ( array_key_exists( $key, $form_state[ 'values' ] ) ) {
$choice = fulcrm_crypto_get_object_id_form_value( 'eventslot.id', $form_state[ 'values' ][ $key ] );
if ( $choice )
$made_choices[ $eventpart[ 'id' ] ] = $choice;
}
}
if ( array_key_exists( 'ticket_for_persons', $form_state[ 'values' ] ) ) {
foreach ( $form_state[ 'values' ][ 'ticket_for_persons' ] as $ticket_for_person ) {
$ticket_for_persons = $form_state[ 'values' ][ 'ticket_for_persons' ];
if ( !is_array( $ticket_for_persons ) )
$ticket_for_persons = array( $ticket_for_persons );
foreach ( $ticket_for_persons as $ticket_for_person ) {
$add_person_name = 'unnamed person';
if ( $ticket_for_person === 'myself' ) {
$add_person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
@ -451,13 +450,15 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
$add_person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'persons' ][ $add_person_uuid ][ 'name' ];
}
$ac = _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
$add_person_uuid, $add_person_name, $product_id );
_fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
$add_person_uuid, $add_person_name, $product_id,
$made_choices = $made_choices );
}
} else {
$person = $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ];
$ac = _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
$person_uuid, $person[ 'name' ], $product_id );
_fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
$person_uuid, $person[ 'name' ], $product_id,
$made_choices = $made_choices );
}
if ( !empty( $ac ) ) {
@ -590,7 +591,7 @@ 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' => 'Choose Your Options',
$form[ 'eventslots' ] = array( '#title' => 'Itinerary',
'#type' => 'fieldset',
);
$eventslots = array();
@ -605,13 +606,14 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe
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(),
);
$eventpart_key = 'eventpart:' . $eventpart_id;
if ( !array_key_exists( $eventpart_key, $form[ 'eventslots' ] ) )
$form[ 'eventslots' ][ $eventpart_key ] = 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' ];
$form[ 'eventslots' ][ $eventpart_key ][ '#options' ][ $eventslot_id ] = $eventslot[ 'name' ];
}
$choices = false;
@ -636,8 +638,6 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe
foreach ( $form[ 'ticket_for_persons' ][ '#options' ] as $option_key => $option_value )
$form[ 'ticket_for_persons' ][ '#default_value' ] = $option_key;
}
} else {
unset( $form[ 'eventslots' ] );
}
$form[ 'actions' ] = array( '#type' => 'actions' );

Loading…
Cancel
Save