guest checkout via this route is looking good

master
Marek Isalski 7 years ago
parent 039dc5e31c
commit 16974ef4c0

@ -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' ] );

@ -0,0 +1,25 @@
<?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_product' ][ '#markup' ]; unset( $fulcrm_shoppingcart_buy_eventbookingtype_form[ 'title_product' ] ); ?>
<div class="row">
<div class="col col-xs-12 col-md-4">
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title">Sign in to go faster!</h3></div>
<div class="panel-body">
<?php $user_login_form[ 'actions' ][ 'submit' ][ '#value' ] = 'Sign In'; ?>
<?php $user_login_form[ 'actions' ][ 'submit' ][ '#attributes' ][ 'class' ] = array( 'btn', 'btn-primary' ); ?>
<?php print drupal_render( $user_login_form ); ?>
</div>
</div>
</div>
<div class="col hide-xs col-md-1"></div>
<div class="col col-xs-12 col-md-7">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Or continue your order by providing some details&hellip;</h3></div>
<div class="panel-body">
<?php print drupal_render( $fulcrm_shoppingcart_buy_eventbookingtype_form ); ?>
</div>
</div>
</div>
</div>
Loading…
Cancel
Save