From 16974ef4c0cb0ae145fbdc88e91cf061049fb384 Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Sun, 20 May 2018 18:52:59 +0100 Subject: [PATCH] guest checkout via this route is looking good --- fulcrm_shoppingcart.module | 103 +++++++++++------- ..._shoppingcart_buy_eventbookingtype.tpl.php | 25 +++++ 2 files changed, 86 insertions(+), 42 deletions(-) create mode 100644 fulcrm_shoppingcart_buy_eventbookingtype.tpl.php diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index 6831b42..78b1ee8 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -144,6 +144,9 @@ function fulcrm_shoppingcart_theme( $existing, $type, $theme, $path ) { 'fulcrm_shoppingcart_transaction_mailshot' => array( 'variables' => array( 'mailshot' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_transaction_mailshot', ), + 'fulcrm_shoppingcart_buy_eventbookingtype' => array( 'variables' => array( 'user_login_form' => null, 'fulcrm_shoppingcart_buy_eventbookingtype_form' => null ), // data returned from fulcrm API + 'template' => 'fulcrm_shoppingcart_buy_eventbookingtype', + ), ); } @@ -287,10 +290,10 @@ function fulcrm_shoppingcart_person_add_form( $form, &$form_state, $collection, ); $form[ 'actions' ] = array( '#type' => 'actions' ); - $form[ 'actions' ][ 'save' ] = array( '#type' => 'submit', - '#value' => t('Add Person'), - '#submit' => array( 'fulcrm_shoppingcart_person_add_form_submit' ), - ); + $form[ 'actions' ][ 'submit' ] = array( '#type' => 'submit', + '#value' => t('Add Person'), + '#submit' => array( 'fulcrm_shoppingcart_person_add_form_submit' ), + ); return $form; } @@ -404,46 +407,23 @@ function fulcrm_shoppingcart_buy_eventbookingtype_login_form_submit( $form, &$fo } function fulcrm_shoppingcart_buy_eventbookingtype_login_or_add_person_form_submit( $form, &$form_state ) { - if ( $login ) { - user_login_submit( $form, $form_state ); - $form_state[ 'redirect' ] = fulcrm_shoppingcart_buy_url( $form_state[ 'fulcrm_shoppingcart' ][ 'redirect_buy_product_id' ] ); - } elseif ( $add ) { + if ( array_key_exists( 'submit', $form_state[ 'values' ] ) ) { + $action = $form_state[ 'values' ][ 'submit' ]; + + if ( $action === 'Log in' ) { + user_login_submit( $form, $form_state ); + $form_state[ 'redirect' ] = fulcrm_shoppingcart_buy_url( $form_state[ 'fulcrm_shoppingcart' ][ 'redirect_buy_product_id' ] ); + } elseif ( $action === 'XXX' ) { + } else { + die( print_r( $form_state[ 'values' ], 1 ) ); + } } } function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $person, $eventbookingtype, $product ) { $form = array(); - $person_id = NULL; - if ( array_key_exists( 'id', $person ) ) - $person_id = $person[ 'id' ]; - - if ( is_null( $person_id ) ) { - switch ( variable_get( 'fulcrm_shoppingcart_experience', 'force' ) ) { - case 'guest': - case 'user': - if ( user_is_anonymous() ) { - $form = user_login( $form, $form_state ); - $form_state[ 'fulcrm_shoppingcart' ][ 'redirect_buy_product_id' ] = $product[ 'id' ]; - $form[ '#submit' ][] = 'fulcrm_shoppingcart_buy_eventbookingtype_login_or_add_person_form_submit'; - } - break; - case 'force': - if ( user_is_anonymous() ) { - drupal_set_message( t('You need to be logged in to continue shopping.'), 'error' ); // XXX change to be on form - $form = user_login( $form, $form_state ); - $form_state[ 'fulcrm_shoppingcart' ][ 'redirect_buy_product_id' ] = $product[ 'id' ]; - $form[ '#submit' ][] = 'fulcrm_shoppingcart_buy_eventbookingtype_login_form_submit'; - return $form; - } else { - drupal_set_message( t('Sorry! There was a problem looking up your record, and this means we cannot complete this order.'), 'error' ); - return $form; - } - break; - } - } - $event_id = $eventbookingtype[ 'event' ][ 'id' ]; $capacity = null; @@ -511,14 +491,53 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe ); $form[ 'actions' ] = array( '#type' => 'actions' ); - $form[ 'actions' ][ 'save' ] = array( '#type' => 'submit', - '#value' => t('Add to Cart'), - '#submit' => array( 'fulcrm_shoppingcart_buy_eventbookingtype_form_submit' ), - ); + $form[ 'actions' ][ 'submit' ] = array( '#type' => 'submit', + '#value' => t('Add to Cart'), + '#submit' => array( 'fulcrm_shoppingcart_buy_eventbookingtype_form_submit' ), + ); return $form; } +function fulcrm_shoppingcart_buy_eventbookingtype( $person, $eventbookingtype, $product ) { + $person_id = NULL; + if ( array_key_exists( 'id', $person ) ) + $person_id = $person[ 'id' ]; + + if ( is_null( $person_id ) ) { + switch ( variable_get( 'fulcrm_shoppingcart_experience', 'force' ) ) { + case 'guest': + case 'user': + if ( user_is_anonymous() ) { + $user_login_form = drupal_get_form( 'user_login' ); + + $fulcrm_shoppingcart_buy_eventbookingtype_form = drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person, $eventbookingtype, $product ); + + return theme( 'fulcrm_shoppingcart_buy_eventbookingtype', array( 'fulcrm_shoppingcart_buy_eventbookingtype_form' => $fulcrm_shoppingcart_buy_eventbookingtype_form, 'user_login_form' => $user_login_form ) ); + } else { + return 'ZZZ'; // drupal_render( something ); + } + break; + case 'force': + if ( user_is_anonymous() ) { + drupal_set_message( t('You need to be logged in to continue shopping.'), 'error' ); // XXX change to be on form + $form = user_login( $form, $form_state ); + $form_state[ 'fulcrm_shoppingcart' ][ 'redirect_buy_product_id' ] = $product[ 'id' ]; + $form[ '#submit' ][] = 'fulcrm_shoppingcart_buy_eventbookingtype_login_form_submit'; + return 'XXX'; // drupal_render( $form ); + } else { + drupal_set_message( t('Sorry! There was a problem looking up your record, and this means we cannot complete this order.'), 'error' ); + return 'YYY'; // drupal_render( $form ); + } + break; + } + } + + + + return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person_data[ 'data' ], $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] ); +} + function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_state ) { $product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ]; @@ -659,7 +678,7 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) { return 'error while fetching information about your booking!'; } - return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person_data[ 'data' ], $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] ); + return fulcrm_shoppingcart_buy_eventbookingtype( $person_data[ 'data' ], $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] ); break; case null: return drupal_get_form( 'fulcrm_shoppingcart_buy_generic_product_form', $person_data[ 'data' ], $product_data[ 'data' ] ); diff --git a/fulcrm_shoppingcart_buy_eventbookingtype.tpl.php b/fulcrm_shoppingcart_buy_eventbookingtype.tpl.php new file mode 100644 index 0000000..19d00fd --- /dev/null +++ b/fulcrm_shoppingcart_buy_eventbookingtype.tpl.php @@ -0,0 +1,25 @@ + + + + +
+
+
+

Sign in to go faster!

+
+ + + +
+
+
+
+
+
+

Or continue your order by providing some details…

+
+ +
+
+
+