now making bookings with slot choices
This commit is contained in:
		@ -341,28 +341,13 @@ function _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( &$form_s
 | 
				
			|||||||
        foreach ( $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'eventbookingtypeslots' ] as $eventbookingtypeslots ) {
 | 
					        foreach ( $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'eventbookingtypeslots' ] as $eventbookingtypeslots ) {
 | 
				
			||||||
            $eventpart_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'eventpart' ] );
 | 
					            $eventpart_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'eventpart' ] );
 | 
				
			||||||
            $eventslot_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'url' ] );
 | 
					            $eventslot_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'url' ] );
 | 
				
			||||||
 | 
					            $eventslotbookings[ $eventpart_id ] = $made_choices[ $eventpart_id ];
 | 
				
			||||||
            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;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        drupal_set_message( 'XXX no eventbookingtypeslots to choose from?', 'warning' );
 | 
					        drupal_set_message( 'XXX no eventbookingtypeslots to choose from?', 'warning' );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $additional_choices = array();
 | 
					    if ( $person_uuid ) {
 | 
				
			||||||
    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' ],
 | 
					        $item = array( 'shoppingcart' => $cart[ 'url' ],
 | 
				
			||||||
                       'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
 | 
					                       'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
 | 
				
			||||||
                       'quantity' => 1.0,
 | 
					                       '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' );
 | 
					            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 ) {
 | 
					function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_state ) {
 | 
				
			||||||
    // $person_d = fulcrm_collection_form_values_to_d( 'person', $form_state[ 'values' ] );
 | 
					    // $person_d = fulcrm_collection_form_values_to_d( 'person', $form_state[ 'values' ] );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
 | 
					    $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;
 | 
					    $person_uuid = NULL;
 | 
				
			||||||
    if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] ) )
 | 
					    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' ] ) ) {
 | 
					        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';
 | 
					                $add_person_name = 'unnamed person';
 | 
				
			||||||
                if ( $ticket_for_person === 'myself' ) {
 | 
					                if ( $ticket_for_person === 'myself' ) {
 | 
				
			||||||
                    $add_person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
 | 
					                    $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' ];
 | 
					                        $add_person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'persons' ][ $add_person_uuid ][ 'name' ];
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $ac = _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
 | 
					                _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
 | 
				
			||||||
                                                                                     $add_person_uuid, $add_person_name, $product_id );
 | 
					                                                                               $add_person_uuid, $add_person_name, $product_id,
 | 
				
			||||||
 | 
					                                                                               $made_choices = $made_choices );
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            $person = $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ];
 | 
					            $person = $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ];
 | 
				
			||||||
            $ac = _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
 | 
					            _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
 | 
				
			||||||
                                                                                 $person_uuid, $person[ 'name' ], $product_id );
 | 
					                                                                           $person_uuid, $person[ 'name' ], $product_id,
 | 
				
			||||||
 | 
					                                                                           $made_choices = $made_choices );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ( !empty( $ac ) ) {
 | 
					        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[ '#submit' ] = 'fulcrm_shoppingcart_buy_eventbookingtype_person_add_guest_form_submit';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $form[ 'eventslots' ] = array( '#title' => 'Choose Your Options',
 | 
					    $form[ 'eventslots' ] = array( '#title' => 'Itinerary',
 | 
				
			||||||
                                   '#type' => 'fieldset',
 | 
					                                   '#type' => 'fieldset',
 | 
				
			||||||
                                   ); 
 | 
					                                   ); 
 | 
				
			||||||
    $eventslots = array();
 | 
					    $eventslots = array();
 | 
				
			||||||
@ -605,13 +606,14 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe
 | 
				
			|||||||
    foreach ( $eventbookingtype[ 'eventbookingtypeslots' ] as $ebts ) {
 | 
					    foreach ( $eventbookingtype[ 'eventbookingtypeslots' ] as $ebts ) {
 | 
				
			||||||
        $eventslot = $ebts[ 'eventslot' ];
 | 
					        $eventslot = $ebts[ 'eventslot' ];
 | 
				
			||||||
        $eventpart_id = fulcrm_apiv2_url_to_pk( $eventslot[ 'eventpart' ] );
 | 
					        $eventpart_id = fulcrm_apiv2_url_to_pk( $eventslot[ 'eventpart' ] );
 | 
				
			||||||
        if ( !array_key_exists( $eventpart_id, $form[ 'eventslots' ] ) )
 | 
					        $eventpart_key = 'eventpart:' . $eventpart_id;
 | 
				
			||||||
            $form[ 'eventslots' ][ $eventpart_id ] = array( '#type' => 'radios',
 | 
					        if ( !array_key_exists( $eventpart_key, $form[ 'eventslots' ] ) )
 | 
				
			||||||
 | 
					            $form[ 'eventslots' ][ $eventpart_key ] = array( '#type' => 'radios',
 | 
				
			||||||
                                                             '#title' => $eventparts[ $eventpart_id ][ 'name' ],
 | 
					                                                             '#title' => $eventparts[ $eventpart_id ][ 'name' ],
 | 
				
			||||||
                                                             '#options' => array(),
 | 
					                                                             '#options' => array(),
 | 
				
			||||||
                                                             );
 | 
					                                                             );
 | 
				
			||||||
        $eventslot_id = fulcrm_crypto_object_id_form_value( 'eventslot.id', $eventslot[ 'id' ] );
 | 
					        $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;
 | 
					    $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 )
 | 
					            foreach ( $form[ 'ticket_for_persons' ][ '#options' ] as $option_key => $option_value )
 | 
				
			||||||
                $form[ 'ticket_for_persons' ][ '#default_value' ] = $option_key;
 | 
					                $form[ 'ticket_for_persons' ][ '#default_value' ] = $option_key;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    } else {
 | 
					 | 
				
			||||||
        unset( $form[ 'eventslots' ] );
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $form[ 'actions' ] = array( '#type' => 'actions' );
 | 
					    $form[ 'actions' ] = array( '#type' => 'actions' );
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user