From 00f7fb14655cf0b1191bda11ea3a79d2630be3e1 Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Sat, 19 May 2018 23:36:45 +0100 Subject: [PATCH] implement forced-login for the case of experience 'force' --- fulcrm_shoppingcart.module | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index 1b13cc9..f7b7424 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -342,8 +342,39 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta $form_state[ 'fulcrm_shoppingcart' ][ 'shoppingcart' ] = $cart; } +function fulcrm_shoppingcart_buy_eventbookingtype_login_form_submit( $form, &$form_state ) { + user_login_submit( $form, $form_state ); + $form_state[ 'redirect' ] = fulcrm_shoppingcart_buy_url( $form_state[ 'fulcrm_shoppingcart_redirect_buy_product_id' ] ); +} + 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': + break; + case 'user': + break; + case 'force': + if ( user_is_anonymous() ) { + drupal_set_message( t('You need to be logged in to continue shopping.'), 'error' ); + $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;