|
|
|
@ -243,8 +243,18 @@ function fulcrm_shoppingcart_remove_url( $shoppingitem_id ) {
|
|
|
|
|
|
|
|
|
|
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[ 'uuid' ] = fulcrm_uuid_uuid4();
|
|
|
|
|
return $person_d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fulcrm_shoppingcart_person_add_form_submit( $form, &$form_state ) {
|
|
|
|
|
$person_d = _fulcrm_shoppingcart_person_add_form_submit_to_data( $form, $form_state );
|
|
|
|
|
$person_d = module_invoke_all( 'fulcrm_shoppingcart_alter_person_add', $person_d );
|
|
|
|
|
|
|
|
|
|
$uuid = $person_d[ 'uuid' ];
|
|
|
|
|
unset( $person_d[ 'uuid' ] );
|
|
|
|
|
$person_data = array( 'd' => $person_d, 'uuid' => $uuid, 'name' => 'unnamed person' );
|
|
|
|
|
|
|
|
|
|
$person_data = array( 'd' => $person_d );
|
|
|
|
|
if ( array_key_exists( 'name', $person_d ) ) {
|
|
|
|
|
if ( is_array( $person_d[ 'name' ] ) )
|
|
|
|
|
$person_data[ 'name' ] = $person_d[ 'name' ][ 0 ];
|
|
|
|
@ -252,15 +262,6 @@ function _fulcrm_shoppingcart_person_add_form_submit_to_data( $form, &$form_stat
|
|
|
|
|
$person_data[ 'name' ] = $person_d[ 'name' ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$person_data[ 'uuid' ] = fulcrm_uuid_uuid4();
|
|
|
|
|
|
|
|
|
|
return $person_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
|
|
$api_data = fulcrm_apiv2_POST( 'person/', $person_data, $query = array( 'expand' => 'd' ) );
|
|
|
|
|
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>') ) );
|
|
|
|
@ -268,16 +269,16 @@ function fulcrm_shoppingcart_person_add_form_submit( $form, &$form_state ) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fulcrm_shoppingcart_person_add_guest_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_d = _fulcrm_shoppingcart_person_add_form_submit_to_data( $form, $form_state );
|
|
|
|
|
$person_d = module_invoke_all( 'fulcrm_shoppingcart_alter_person_add', $person_d );
|
|
|
|
|
|
|
|
|
|
$cart = fulcrm_shoppingcart_get_session_cart();
|
|
|
|
|
if ( $cart[ 'url' ] ) {
|
|
|
|
|
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_data[ 'uuid' ] ] = $person_data;
|
|
|
|
|
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_d[ 'uuid' ] ] = $person_d;
|
|
|
|
|
if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
|
|
|
|
|
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ||
|
|
|
|
|
is_null( $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] ) ) {
|
|
|
|
|
$cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_data[ 'uuid' ];
|
|
|
|
|
$cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_d[ 'uuid' ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ], array( 'd' => $cart[ 'd' ] ),
|
|
|
|
@ -289,7 +290,7 @@ function fulcrm_shoppingcart_person_add_guest_form_submit( $form, &$form_state )
|
|
|
|
|
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>') ) );
|
|
|
|
|
|
|
|
|
|
$form_state[ 'fulcrm_shoppingcart' ][ 'person' ] = $person_data;
|
|
|
|
|
$form_state[ 'fulcrm_shoppingcart' ][ 'person' ] = $person_d;
|
|
|
|
|
$form_state[ 'fulcrm_shoppingcart' ][ 'shoppingcart' ] = $api_data[ 'data' ];
|
|
|
|
|
} else {
|
|
|
|
|
drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
|
|
|
|
|