starting to send across a guest checkout structure

master
Marek Isalski 7 years ago
parent 563e17ba58
commit f2b3a7046d

@ -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',
$person_data = module_invoke_all( 'fulcrm_shoppingcart_alter_person_add_guest', $person_data ); 'shoppingitems',
'shoppingitems.d',
$api_data = fulcrm_apiv2_POST( 'person/', $person_data, $query = array( 'expand' => 'd' ) ); 'shoppingitems.content_object',
'shoppingitems.product' ) ) ) );
if ( $api_data[ 'success' ] ) { 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>') ) ); 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_collection' ][ 'person' ] = $person_data;
$form_state[ 'fulcrm_collection' ][ 'shoppingcart' ] = $api_data[ 'cart' ];
} else {
drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
}
} else {
drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
} }
} }
@ -307,47 +321,7 @@ function fulcrm_shoppingcart_person_add( $collection_id, $hmac ) {
} }
} }
function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_state ) { function _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( &$form_state, $person_uuid, $person_name ) {
// $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' ];
$person_id = 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' ] ) )
$person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
if ( array_key_exists( 'shoppingcart', $form_state[ 'fulcrm_shoppingcart' ] ) )
$cart = $form_state[ 'fulcrm_shoppingcart' ][ 'shoppingcart' ];
else
$cart = fulcrm_shoppingcart_get_session_cart();
if ( is_array( $cart ) ) {
if ( $person_uuid ) {
$api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ],
array( 'd' => array( 'fulcrm' => array( 'transaction' => array( 'person' => $person_uuid,
),
'person' => array( $person_uuid => array() ),
),
),
),
$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' ];
}
$shoppingitem_name = ( $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'event' ][ 'name' ] . "\r\n" . $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' ][ 'eventbookingtype' ][ 'name' ] . ', ' . $person_name . "\r\n" .
$form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] ); $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] );
@ -393,7 +367,64 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
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' );
} }
} }
}
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' ];
$person_uuid = NULL;
if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ] ) )
$person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
if ( array_key_exists( 'shoppingcart', $form_state[ 'fulcrm_shoppingcart' ] ) )
$cart = $form_state[ 'fulcrm_shoppingcart' ][ 'shoppingcart' ];
else
$cart = fulcrm_shoppingcart_get_session_cart();
if ( is_array( $cart ) ) {
if ( $person_uuid ) {
if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array();
$patch = TRUE;
}
if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
!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();
}
}
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,16 +605,24 @@ 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;
), }
if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
!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' ) ); $query = array( 'expand' => 'd' ) );
fulcrm_shoppingcart_invalidate_cache(); 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' ] ); ?>

Loading…
Cancel
Save