starting to send across a guest checkout structure
This commit is contained in:
		@ -176,7 +176,8 @@ function fulcrm_shoppingcart_get_session_cart( $create = true ) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $api_data = fulcrm_apiv2_GET( 'shoppingcart/' . $_SESSION[ 'fulcrm_shoppingcart_id' ] . '/',
 | 
					        $api_data = fulcrm_apiv2_GET( 'shoppingcart/' . $_SESSION[ 'fulcrm_shoppingcart_id' ] . '/',
 | 
				
			||||||
                                      $query = array( 'expand' => implode( ',', array( 'shoppingitems',
 | 
					                                      $query = array( 'expand' => implode( ',', array( 'd',
 | 
				
			||||||
 | 
					                                                                                       'shoppingitems',
 | 
				
			||||||
                                                                                       'shoppingitems.d',
 | 
					                                                                                       'shoppingitems.d',
 | 
				
			||||||
                                                                                       'shoppingitems.content_object',
 | 
					                                                                                       'shoppingitems.content_object',
 | 
				
			||||||
                                                                                       'shoppingitems.product' ) ) ) );
 | 
					                                                                                       'shoppingitems.product' ) ) ) );
 | 
				
			||||||
@ -236,7 +237,7 @@ function fulcrm_shoppingcart_remove_url( $shoppingitem_id ) {
 | 
				
			|||||||
    return url( 'fulcrm/cart/remove/' . $shoppingitem_id . '/' . $hmac );
 | 
					    return url( 'fulcrm/cart/remove/' . $shoppingitem_id . '/' . $hmac );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function fulcrm_shoppingcart_person_add_form_submit( $form, &$form_state ) {
 | 
					function _fulcrm_shoppingcart_person_add_form_submit_to_data( $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' ] );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $person_data = array( 'd' => $person_d );
 | 
					    $person_data = array( 'd' => $person_d );
 | 
				
			||||||
@ -248,7 +249,10 @@ function fulcrm_shoppingcart_person_add_form_submit( $form, &$form_state ) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $person_data[ 'uuid' ] = fulcrm_uuid_uuid4();
 | 
					    $person_data[ 'uuid' ] = fulcrm_uuid_uuid4();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fulcrm_shoppingcart_person_add_form_submit( $form, &$form_state ) {
 | 
				
			||||||
 | 
					    $person_data = _fulcrm_shoppingcart_person_add_form_submit_to_data( $form, $form_state );
 | 
				
			||||||
    $person_data = module_invoke_all( 'fulcrm_shoppingcart_alter_person_add', $person_data );
 | 
					    $person_data = module_invoke_all( 'fulcrm_shoppingcart_alter_person_add', $person_data );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $api_data = fulcrm_apiv2_POST( 'person/', $person_data, $query = array( 'expand' => 'd' ) );
 | 
					    $api_data = fulcrm_apiv2_POST( 'person/', $person_data, $query = array( 'expand' => 'd' ) );
 | 
				
			||||||
@ -258,23 +262,33 @@ function fulcrm_shoppingcart_person_add_form_submit( $form, &$form_state ) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function fulcrm_shoppingcart_person_add_guest_form_submit( $form, &$form_state ) {
 | 
					function fulcrm_shoppingcart_person_add_guest_form_submit( $form, &$form_state ) {
 | 
				
			||||||
    $person_d = fulcrm_collection_form_values_to_d( 'person', $form_state[ 'values' ] );
 | 
					    $person_data = _fulcrm_shoppingcart_person_add_form_submit_to_data( $form, $form_state );
 | 
				
			||||||
 | 
					    $person_data = module_invoke_all( 'fulcrm_shoppingcart_alter_person_add', $person_data );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $person_data = array( 'd' => $person_d );
 | 
					    $cart = fulcrm_shoppingcart_get_session_cart();
 | 
				
			||||||
    if ( array_key_exists( 'name', $person_d ) ) {
 | 
					    if ( $cart[ 'url' ] ) {
 | 
				
			||||||
        if ( is_array( $person_d[ 'name' ] ) )
 | 
					        $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_data[ 'uuid' ] ] = $person_data;
 | 
				
			||||||
            $person_data[ 'name' ] = $person_d[ 'name' ][ 0 ];
 | 
					        if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
 | 
				
			||||||
        elseif ( is_string( $person_d[ 'name' ] ) )
 | 
					             !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ) {
 | 
				
			||||||
            $person_data[ 'name' ] = $person_d[ 'name' ];
 | 
					            $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_data[ 'uuid' ];
 | 
				
			||||||
    }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $person_data[ 'uuid' ] = fulcrm_uuid_uuid4();
 | 
					        $api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ], array( 'd' => $cart[ 'd' ] ),
 | 
				
			||||||
 | 
					                                        $query = array( 'expand' => implode( ',', array( 'd',
 | 
				
			||||||
 | 
					                                                                                         'shoppingitems',
 | 
				
			||||||
 | 
					                                                                                         'shoppingitems.d',
 | 
				
			||||||
 | 
					                                                                                         'shoppingitems.content_object',
 | 
				
			||||||
 | 
					                                                                                         'shoppingitems.product' ) ) ) );
 | 
				
			||||||
 | 
					        if ( $api_data[ 'success' ] ) {
 | 
				
			||||||
 | 
					            module_invoke_all( 'fulcrm_shoppingcart_person_add', $api_data[ 'data' ], array_key_exists( 'destination', $_GET ) ? $_GET[ 'destination' ] : variable_get( 'fulcrm_shoppingcart_proceed_url', url('<front>') ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $person_data = module_invoke_all( 'fulcrm_shoppingcart_alter_person_add_guest', $person_data );
 | 
					            $form_state[ 'fulcrm_collection' ][ 'person' ] = $person_data;
 | 
				
			||||||
 | 
					            $form_state[ 'fulcrm_collection' ][ 'shoppingcart' ] = $api_data[ 'cart' ];
 | 
				
			||||||
    $api_data = fulcrm_apiv2_POST( 'person/', $person_data, $query = array( 'expand' => 'd' ) );
 | 
					        } else {
 | 
				
			||||||
    if ( $api_data[ 'success' ] ) {
 | 
					            drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
 | 
				
			||||||
        module_invoke_all( 'fulcrm_shoppingcart_person_add', $api_data[ 'data' ], array_key_exists( 'destination', $_GET ) ? $_GET[ 'destination' ] : variable_get( 'fulcrm_shoppingcart_proceed_url', url('<front>') ) );
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -307,16 +321,62 @@ function fulcrm_shoppingcart_person_add( $collection_id, $hmac ) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( &$form_state, $person_uuid, $person_name ) {
 | 
				
			||||||
 | 
					    $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' ] );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $eventslotbookings = array();
 | 
				
			||||||
 | 
					    if ( array_key_exists( 'eventbookingtypeslots', $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ] ) ) {
 | 
				
			||||||
 | 
					        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 ( array_key_exists( $eventpart_id, $eventslotbookings ) )
 | 
				
			||||||
 | 
					                drupal_set_message( 'XXX cannot yet cope with multiple choice event slot bookings; defaulting to first.', 'warning' );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $eventslotbookings[ $eventpart_id ] = $eventslot_id;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        drupal_set_message( 'XXX no eventbookingtypeslots to choose from?', 'warning' );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( $person_uuid ) {
 | 
				
			||||||
 | 
					        $item = array( 'shoppingcart' => $cart[ 'url' ],
 | 
				
			||||||
 | 
					                       'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
 | 
				
			||||||
 | 
					                       'quantity' => 1.0,
 | 
				
			||||||
 | 
					                       'd' => array( 'fulcrm' => array( 'eventbooking' => array( 'eventbooking' => array(),
 | 
				
			||||||
 | 
					                                                                                 'eventslotbookings' => $eventslotbookings,
 | 
				
			||||||
 | 
					                                                                                 'person' => $person_uuid,
 | 
				
			||||||
 | 
					                                                                                 ),
 | 
				
			||||||
 | 
					                                                        ),
 | 
				
			||||||
 | 
					                                     'name' => $shoppingitem_name,
 | 
				
			||||||
 | 
					                                     ),
 | 
				
			||||||
 | 
					                       );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item, $query = array( 'expand' => 'd' ) );
 | 
				
			||||||
 | 
					        fulcrm_shoppingcart_invalidate_cache();
 | 
				
			||||||
 | 
					        if ( $api_data[ 'success' ] ) {
 | 
				
			||||||
 | 
					            $hook_results = module_invoke_all( 'fulcrm_shoppingcart_post_add_to_cart', $cart, $person_data[ 'data' ], $api_data[ 'data' ] );
 | 
				
			||||||
 | 
					            foreach ( $hook_results as $hook_result )
 | 
				
			||||||
 | 
					                return $hook_result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            drupal_set_message( t('Added "%item" to shopping cart.', array( '%item' => $item[ 'd' ][ 'name' ] ) ), 'status' );
 | 
				
			||||||
 | 
					            $form_state[ 'redirect' ] = 'fulcrm/cart';
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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_id = $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'id' ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $person_id = NULL;
 | 
					 | 
				
			||||||
    $person_uuid = NULL;
 | 
					    $person_uuid = NULL;
 | 
				
			||||||
    if ( array_key_exists( 'id', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
					 | 
				
			||||||
        $person_id = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'id' ];
 | 
					 | 
				
			||||||
    if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
					    if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
				
			||||||
        $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
 | 
					        $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -327,73 +387,44 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if ( is_array( $cart ) ) {
 | 
					    if ( is_array( $cart ) ) {
 | 
				
			||||||
        if ( $person_uuid ) {
 | 
					        if ( $person_uuid ) {
 | 
				
			||||||
            $api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ],
 | 
					            if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
 | 
				
			||||||
                                            array( 'd' => array( 'fulcrm' => array( 'transaction' => array( 'person' => $person_uuid,
 | 
					                 !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
 | 
				
			||||||
                                                                                                            ),
 | 
					                 !array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) {
 | 
				
			||||||
                                                                                    'person' => array( $person_uuid => array() ),
 | 
					                $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array();
 | 
				
			||||||
                                                                                    ),
 | 
					                $patch = TRUE;
 | 
				
			||||||
                                                                 ),
 | 
					 | 
				
			||||||
                                                   ),
 | 
					 | 
				
			||||||
                                            $query = array( 'expand' => 'd' ) );
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        foreach ( $form_state[ 'values' ][ 'ticket_for_persons' ] as $ticket_for_person ) {
 | 
					 | 
				
			||||||
            $person_name = 'unnamed person';
 | 
					 | 
				
			||||||
            if ( $ticket_for_person === 'myself' ) {
 | 
					 | 
				
			||||||
                $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
 | 
					 | 
				
			||||||
                $person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'name' ];
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                $person_uuid = fulcrm_crypto_get_object_id_form_value( 'person.uuid', $ticket_for_person );
 | 
					 | 
				
			||||||
                if ( $person_uuid )
 | 
					 | 
				
			||||||
                    $person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'persons' ][ $person_uuid ][ 'name' ];
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
 | 
				
			||||||
            $shoppingitem_name = ( $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'event' ][ 'name' ] . "\r\n" .
 | 
					                 !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ) {
 | 
				
			||||||
                                   $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'name' ] . ', ' . $person_name . "\r\n" .
 | 
					                $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_uuid;
 | 
				
			||||||
                                   $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] );
 | 
					                $patch = TRUE;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            $eventslotbookings = array();
 | 
					 | 
				
			||||||
            if ( array_key_exists( 'eventbookingtypeslots', $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ] ) ) {
 | 
					 | 
				
			||||||
                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 ( array_key_exists( $eventpart_id, $eventslotbookings ) )
 | 
					 | 
				
			||||||
                        drupal_set_message( 'XXX cannot yet cope with multiple choice event slot bookings; defaulting to first.', 'warning' );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    $eventslotbookings[ $eventpart_id ] = $eventslot_id;
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                drupal_set_message( 'XXX no eventbookingtypeslots to choose from?', 'warning' );
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					            if ( $patch ) {
 | 
				
			||||||
            if ( $person_uuid ) {
 | 
					                $api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ], array( 'd' => $cart[ 'd' ] ),
 | 
				
			||||||
                $item = array( 'shoppingcart' => $cart[ 'url' ],
 | 
					                                                $query = array( 'expand' => 'd' ) );
 | 
				
			||||||
                               'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
 | 
					 | 
				
			||||||
                               'quantity' => 1.0,
 | 
					 | 
				
			||||||
                               'd' => array( 'fulcrm' => array( 'eventbooking' => array( 'eventbooking' => array(),
 | 
					 | 
				
			||||||
                                                                                         'eventslotbookings' => $eventslotbookings,
 | 
					 | 
				
			||||||
                                                                                         'person' => $person_uuid,
 | 
					 | 
				
			||||||
                                                                                         ),
 | 
					 | 
				
			||||||
                                                                ),
 | 
					 | 
				
			||||||
                                             'name' => $shoppingitem_name,
 | 
					 | 
				
			||||||
                                             ),
 | 
					 | 
				
			||||||
                               );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                $api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item, $query = array( 'expand' => 'd' ) );
 | 
					 | 
				
			||||||
                fulcrm_shoppingcart_invalidate_cache();
 | 
					                fulcrm_shoppingcart_invalidate_cache();
 | 
				
			||||||
                if ( $api_data[ 'success' ] ) {
 | 
					 | 
				
			||||||
                    $hook_results = module_invoke_all( 'fulcrm_shoppingcart_post_add_to_cart', $cart, $person_data[ 'data' ], $api_data[ 'data' ] );
 | 
					 | 
				
			||||||
                    foreach ( $hook_results as $hook_result )
 | 
					 | 
				
			||||||
                        return $hook_result;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    drupal_set_message( t('Added "%item" to shopping cart.', array( '%item' => $item[ 'd' ][ 'name' ] ) ), 'status' );
 | 
					 | 
				
			||||||
                    $form_state[ 'redirect' ] = 'fulcrm/cart';
 | 
					 | 
				
			||||||
                } else {
 | 
					 | 
				
			||||||
                    drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if ( array_key_exists( 'ticket_for_persons', $form_state[ 'values' ] ) ) {
 | 
				
			||||||
 | 
					            foreach ( $form_state[ 'values' ][ 'ticket_for_persons' ] as $ticket_for_person ) {
 | 
				
			||||||
 | 
					                $person_name = 'unnamed person';
 | 
				
			||||||
 | 
					                if ( $ticket_for_person === 'myself' ) {
 | 
				
			||||||
 | 
					                    $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
 | 
				
			||||||
 | 
					                    $person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'name' ];
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    $person_uuid = fulcrm_crypto_get_object_id_form_value( 'person.uuid', $ticket_for_person );
 | 
				
			||||||
 | 
					                    if ( $person_uuid )
 | 
				
			||||||
 | 
					                        $person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'persons' ][ $person_uuid ][ 'name' ];
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $person_uuid, $person_name );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state,
 | 
				
			||||||
 | 
					                                                                           $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ],
 | 
				
			||||||
 | 
					                                                                           $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'name' ] );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        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' );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -401,15 +432,15 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
 | 
				
			|||||||
    $form_state[ 'fulcrm_shoppingcart' ][ 'shoppingcart' ] = $cart;
 | 
					    $form_state[ 'fulcrm_shoppingcart' ][ 'shoppingcart' ] = $cart;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function fulcrm_shoppingcart_buy_eventbookingtype_guest_add_person_form_submit( $form, &$form_state ) {
 | 
					function fulcrm_shoppingcart_buy_eventbookingtype_person_add_guest_form_submit( $form, &$form_state ) {
 | 
				
			||||||
    die( print_r( $form_state[ 'values' ], 1 ) );
 | 
					    fulcrm_shoppingcart_person_add_guest_form_submit( $form, $form_state );
 | 
				
			||||||
 | 
					    if ( array_key_exists( 'person', $form_state[ 'fulcrm_shoppingcart' ] ) ) {
 | 
				
			||||||
 | 
					        fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, $form_state );        
 | 
				
			||||||
 | 
					        // XXXXXX
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $person, $eventbookingtype, $product ) {
 | 
					function fulcrm_shoppingcart_event_has_capacity( $event_id ) {
 | 
				
			||||||
    $form = array();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    $event_id = $eventbookingtype[ 'event' ][ 'id' ];
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    $capacity = null;
 | 
					    $capacity = null;
 | 
				
			||||||
    $count = null;
 | 
					    $count = null;
 | 
				
			||||||
    $api_data = fulcrm_apiv2_GET( 'event/' . $event_id . '/' );
 | 
					    $api_data = fulcrm_apiv2_GET( 'event/' . $event_id . '/' );
 | 
				
			||||||
@ -424,11 +455,14 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe
 | 
				
			|||||||
        $count = $api_data[ 'data' ][ 'count' ];
 | 
					        $count = $api_data[ 'data' ][ 'count' ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ( !is_null( $capacity ) && !is_null( $count ) ) {
 | 
					    if ( !is_null( $capacity ) && !is_null( $count ) ) {
 | 
				
			||||||
        if ( $count >= $capacity ) {
 | 
					        if ( $count >= $capacity )
 | 
				
			||||||
            drupal_set_message( t('Sorry, this event must be sold out.  There are no more tickets available.'), 'error' );
 | 
					            return FALSE;
 | 
				
			||||||
            return $form;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    return TRUE;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $person, $eventbookingtype, $product ) {
 | 
				
			||||||
 | 
					    $form = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] = $person;
 | 
					    $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] = $person;
 | 
				
			||||||
    $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ] = $eventbookingtype;
 | 
					    $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ] = $eventbookingtype;
 | 
				
			||||||
@ -446,7 +480,7 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    drupal_set_title( check_plain( $eventbookingtype[ 'event' ][ 'name' ] ) . ', ' .
 | 
					    drupal_set_title( check_plain( $eventbookingtype[ 'event' ][ 'name' ] ) . ', ' .
 | 
				
			||||||
                      check_plain( $eventbookingtype[ 'name' ] ) . ', ' .
 | 
					                      check_plain( $eventbookingtype[ 'name' ] ) . ', ' .
 | 
				
			||||||
                      check_plain( $product_data[ 'data' ][ 'name' ] ) );
 | 
					                      check_plain( $product[ 'name' ] ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // $form[ 'person' ] = fulcrm_collection_to_form( 'person', $eventbookingtype[ 'person_ddatacollection' ], $person[ 'd' ] );
 | 
					    // $form[ 'person' ] = fulcrm_collection_to_form( 'person', $eventbookingtype[ 'person_ddatacollection' ], $person[ 'd' ] );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -486,7 +520,7 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe
 | 
				
			|||||||
                $form[ 'new_person' ] = fulcrm_collection_to_form( 'person', $collection_data[ 'data' ], array() );
 | 
					                $form[ 'new_person' ] = fulcrm_collection_to_form( 'person', $collection_data[ 'data' ], array() );
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        $form[ '#submit' ] = 'fulcrm_shoppingcart_buy_eventbookingtype_guest_add_person_form_submit';
 | 
					        $form[ '#submit' ] = 'fulcrm_shoppingcart_buy_eventbookingtype_person_add_guest_form_submit';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $form[ 'actions' ] = array( '#type' => 'actions' );
 | 
					    $form[ 'actions' ] = array( '#type' => 'actions' );
 | 
				
			||||||
@ -498,13 +532,9 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe
 | 
				
			|||||||
    return $form;
 | 
					    return $form;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function fulcrm_shoppingcart_buy_eventbookingtype_guest_form_submit( $form, &$form_state ) {
 | 
					 | 
				
			||||||
    die( print_r( $form_state, 1 ) );
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function fulcrm_shoppingcart_buy_eventbookingtype_guest_form( $form, &$form_state, $person, $eventbookingtype, $product ) {
 | 
					function fulcrm_shoppingcart_buy_eventbookingtype_guest_form( $form, &$form_state, $person, $eventbookingtype, $product ) {
 | 
				
			||||||
    $form = fulcrm_shoppingcart_buy_eventbookingtype_form( $form, $form_state, $person, $eventbookingtype, $product );
 | 
					    $form = fulcrm_shoppingcart_buy_eventbookingtype_form( $form, $form_state, $person, $eventbookingtype, $product );
 | 
				
			||||||
    $form[ 'actions' ][ 'submit' ][ '#submit' ] = array( 'fulcrm_shoppingcart_buy_eventbookingtype_guest_form_submit' );
 | 
					    $form[ 'actions' ][ 'submit' ][ '#submit' ] = array( 'fulcrm_shoppingcart_buy_eventbookingtype_person_add_guest_form_submit' );
 | 
				
			||||||
    return $form;
 | 
					    return $form;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -520,6 +550,12 @@ function fulcrm_shoppingcart_buy_eventbookingtype_login_form( $form, &$form_stat
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function fulcrm_shoppingcart_buy_eventbookingtype( $person, $eventbookingtype, $product ) {
 | 
					function fulcrm_shoppingcart_buy_eventbookingtype( $person, $eventbookingtype, $product ) {
 | 
				
			||||||
 | 
					    $event_id = $eventbookingtype[ 'event' ][ 'id' ];
 | 
				
			||||||
 | 
					    if ( !fulcrm_shoppingcart_event_has_capacity( $event_id ) ) {
 | 
				
			||||||
 | 
					        drupal_set_message( t('Sorry, this event must be sold out.  There are no more tickets available.'), 'error' );
 | 
				
			||||||
 | 
					        return '';
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   $person_id = NULL;
 | 
					   $person_id = NULL;
 | 
				
			||||||
    if ( array_key_exists( 'id', $person ) )
 | 
					    if ( array_key_exists( 'id', $person ) )
 | 
				
			||||||
        $person_id = $person[ 'id' ];
 | 
					        $person_id = $person[ 'id' ];
 | 
				
			||||||
@ -557,11 +593,9 @@ function fulcrm_shoppingcart_buy_eventbookingtype( $person, $eventbookingtype, $
 | 
				
			|||||||
function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_state ) {
 | 
					function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_state ) {
 | 
				
			||||||
    $product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
 | 
					    $product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $person_id = NULL;
 | 
					 | 
				
			||||||
    $person_uuid = NULL;
 | 
					    $person_uuid = NULL;
 | 
				
			||||||
    if ( array_key_exists( 'id', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
					    if ( array_key_exists( 'person', $form_state[ 'fulcrm_shoppingcart' ] ) &&
 | 
				
			||||||
        $person_id = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'id' ];
 | 
					         array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] ) )
 | 
				
			||||||
    if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
					 | 
				
			||||||
        $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
 | 
					        $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ( array_key_exists( 'shoppingcart', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
					    if ( array_key_exists( 'shoppingcart', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
				
			||||||
@ -571,15 +605,23 @@ function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_stat
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if ( is_array( $cart ) ) {
 | 
					    if ( is_array( $cart ) ) {
 | 
				
			||||||
        if ( $person_uuid ) {
 | 
					        if ( $person_uuid ) {
 | 
				
			||||||
            $api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ], 
 | 
					            $patch = FALSE;
 | 
				
			||||||
                                            array( 'd' => array( 'fulcrm' => array( 'transaction' => array( 'person' => $person_uuid,
 | 
					            if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
 | 
				
			||||||
                                                                                                            ),
 | 
					                 !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
 | 
				
			||||||
                                                                                    'person' => array( $person_uuid => array() ),
 | 
					                 !array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) {
 | 
				
			||||||
                                                                                    ),
 | 
					                $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array();
 | 
				
			||||||
                                                                 ),
 | 
					                $patch = TRUE;
 | 
				
			||||||
                                                   ),
 | 
					            }
 | 
				
			||||||
                                            $query = array( 'expand' => 'd' ) );
 | 
					            if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
 | 
				
			||||||
            fulcrm_shoppingcart_invalidate_cache();
 | 
					                 !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ) {
 | 
				
			||||||
 | 
					                $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_uuid;
 | 
				
			||||||
 | 
					                $patch = TRUE;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            if ( $patch ) {
 | 
				
			||||||
 | 
					                $api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ], array( 'd' => $cart[ 'd' ] ),
 | 
				
			||||||
 | 
					                                                $query = array( 'expand' => 'd' ) );
 | 
				
			||||||
 | 
					                fulcrm_shoppingcart_invalidate_cache();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $shoppingitem_name = ( $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] );
 | 
					        $shoppingitem_name = ( $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] );
 | 
				
			||||||
 | 
				
			|||||||
@ -1,3 +1,5 @@
 | 
				
			|||||||
 | 
					<p><a href="<?php $cart = fulcrm_shoppingcart_get_session_cart(); print $cart[ 'url' ]; ?>?expand=d,shoppingitems,shoppingitems.d"><?php print $cart[ 'url' ]; ?></a></p>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<?php print $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_event' ][ '#markup' ]; unset( $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_event' ] ); ?>
 | 
					<?php print $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_event' ][ '#markup' ]; unset( $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_event' ] ); ?>
 | 
				
			||||||
<?php print $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_eventbookingtype' ][ '#markup' ]; unset( $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_eventbookingtype' ] ); ?>
 | 
					<?php print $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_eventbookingtype' ][ '#markup' ]; unset( $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_eventbookingtype' ] ); ?>
 | 
				
			||||||
<?php print $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_product' ][ '#markup' ]; unset( $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_product' ] ); ?>
 | 
					<?php print $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_product' ][ '#markup' ]; unset( $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_product' ] ); ?>
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user