adding loads of hooks all over the place
This commit is contained in:
parent
4e4c709c1a
commit
450201b048
@ -7,6 +7,27 @@ function fulcrm_shoppingcart_permission() {
|
||||
);
|
||||
}
|
||||
|
||||
function hook_fulcrm_shoppingcart_alter_person_add( $person ) {
|
||||
}
|
||||
|
||||
function hook_fulcrm_shoppingcart_person_add( $person, $redirect_destination ) {
|
||||
}
|
||||
|
||||
function hook_fulcrm_shoppingcart_pre_add_to_cart( $shoppingcart, $person, $product ) {
|
||||
}
|
||||
|
||||
function hook_fulcrm_shoppingcart_pre_cart_to_transaction( $shoppingcart ) {
|
||||
}
|
||||
|
||||
function hook_fulcrm_shoppingcart_post_cart_to_transaction( $transaction ) {
|
||||
}
|
||||
|
||||
function hook_fulcrm_shoppingcart_transaction_success( $transaction ) {
|
||||
}
|
||||
|
||||
function hook_fulcrm_shoppingcart_transaction_failure( $transaction ) {
|
||||
}
|
||||
|
||||
function fulcrm_shoppingcart_menu() {
|
||||
/*
|
||||
$items[ 'admin/config/services/fulcrm' ] = array( 'page callback' => 'system_admin_menu_block_page',
|
||||
@ -477,33 +498,46 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
|
||||
'related_to_person2persons.related_to.d',
|
||||
'related_to_person2persons.relationship',
|
||||
) ) ) );
|
||||
if ( !$person_data[ 'success' ] ) {
|
||||
return 'error while fetching your details!';
|
||||
}
|
||||
} else {
|
||||
$person_data = array( 'data' => array() );
|
||||
}
|
||||
|
||||
if ( $product_data[ 'success' ] ) {
|
||||
switch ( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ? fulcrm_apiv2_url_to_type( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ) : null ) {
|
||||
case 'eventbookingtype':
|
||||
$eventbookingtype_data = fulcrm_apiv2_GET( $product_data[ 'data' ][ 'content_object' ][ 'url' ],
|
||||
$query = array( 'expand' => implode( ',', array( 'event',
|
||||
'person_ddatacollection',
|
||||
'eventbooking_ddatacollection',
|
||||
'eventbookingtypeslots',
|
||||
'eventbookingtypeslots.eventslot' ) ) ) );
|
||||
if ( $eventbookingtype_data[ 'success' ] ) {
|
||||
return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $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' ] );
|
||||
default:
|
||||
return 'cannot handle these products yet';
|
||||
if ( !$product_data[ 'success' ] ) {
|
||||
return 'error while fetching the contents of your shopping cart!';
|
||||
}
|
||||
|
||||
$shoppingcart_data = fulcrm_shoppingcart_get_session_cart( $create = true );
|
||||
if ( !$shoppingcart_data[ 'success' ] ) {
|
||||
return 'error while fetching information about this product!';
|
||||
}
|
||||
|
||||
$hook_results = module_invoke_all( 'fulcrm_shoppingcart_pre_add_to_cart', $shoppingcart_data[ 'data' ], $person_data[ 'data' ], $product_data[ 'data' ] );
|
||||
foreach ( $hook_results as $hook_result )
|
||||
return $hook_result;
|
||||
|
||||
switch ( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ? fulcrm_apiv2_url_to_type( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ) : null ) {
|
||||
case 'eventbookingtype':
|
||||
$eventbookingtype_data = fulcrm_apiv2_GET( $product_data[ 'data' ][ 'content_object' ][ 'url' ],
|
||||
$query = array( 'expand' => implode( ',', array( 'event',
|
||||
'person_ddatacollection',
|
||||
'eventbooking_ddatacollection',
|
||||
'eventbookingtypeslots',
|
||||
'eventbookingtypeslots.eventslot' ) ) ) );
|
||||
if ( !$eventbookingtype_data[ 'success' ] ) {
|
||||
return 'error while fetching information about your booking!';
|
||||
}
|
||||
|
||||
return 'ok!';
|
||||
} else {
|
||||
return 'error adding item to shopping cart';
|
||||
return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $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' ] );
|
||||
default:
|
||||
return 'cannot handle these products yet';
|
||||
}
|
||||
return 'ok!';
|
||||
} else {
|
||||
drupal_not_found();
|
||||
}
|
||||
@ -622,6 +656,10 @@ function fulcrm_shoppingcart_coupon( $transaction_id, $hmac ) {
|
||||
function fulcrm_shoppingcart_checkout() {
|
||||
$cart = fulcrm_shoppingcart_get_session_cart( false );
|
||||
if ( $cart && array_key_exists( 'url', $cart ) ) {
|
||||
$hook_results = module_invoke_all( 'fulcrm_shoppingcart_pre_cart_to_transaction', $cart );
|
||||
foreach ( $hook_results as $hook_result )
|
||||
return $hook_result;
|
||||
|
||||
$transaction_data = fulcrm_apiv2_POST( $cart[ 'url' ] . 'transaction/', array(), array( 'expand' => implode( ',', array( 'd' ) ) ) );
|
||||
if ( $transaction_data[ 'success' ] ) {
|
||||
$hmac = fulcrm_crypto_object_id_hmac( 'transaction', $transaction_data[ 'data' ][ 'id' ] );
|
||||
@ -638,6 +676,9 @@ function fulcrm_shoppingcart_checkout() {
|
||||
'paymentitems',
|
||||
) ) ) );
|
||||
if ( $transaction_data2[ 'success' ] ) {
|
||||
$hook_results = module_invoke_all( 'fulcrm_shoppingcart_post_cart_to_transaction', $transaction_data2[ 'data' ] );
|
||||
foreach ( $hook_results as $hook_result )
|
||||
return $hook_result;
|
||||
return theme( 'fulcrm_shoppingcart_transaction_checkout', array( 'transaction' => $transaction_data2[ 'data' ],
|
||||
'use_coupon_url' => fulcrm_shoppingcart_coupon_url( $transaction_data[ 'data' ][ 'id' ] ),
|
||||
) );
|
||||
@ -651,18 +692,23 @@ function fulcrm_shoppingcart_checkout() {
|
||||
|
||||
function fulcrm_shoppingcart_checkout_success( $transaction_id, $hmac ) {
|
||||
if ( fulcrm_crypto_check_object_id_hmac( 'transaction', $transaction_id, $hmac ) ) {
|
||||
$transaction_data = fulcrm_apiv2_GET( 'transaction/' . $transaction_id . '/', $query = array( 'expand' => implode( ',', array( 'd',
|
||||
'lineitems',
|
||||
'lineitems.d',
|
||||
'lineitems.content_object',
|
||||
'mailshots',
|
||||
'mailshots.campaign',
|
||||
'paymentitems',
|
||||
'paymentitems.d',
|
||||
) ) ) );
|
||||
$transaction_data = fulcrm_apiv2_GET( 'transaction/' . $transaction_id . '/',
|
||||
$query = array( 'expand' => implode( ',', array( 'd',
|
||||
'lineitems',
|
||||
'lineitems.d',
|
||||
'lineitems.content_object',
|
||||
'mailshots',
|
||||
'mailshots.campaign',
|
||||
'paymentitems',
|
||||
'paymentitems.d',
|
||||
) ) ) );
|
||||
if ( $transaction_data[ 'success' ] ) {
|
||||
if ( $transaction_data[ 'data' ][ 'completed' ] )
|
||||
if ( $transaction_data[ 'data' ][ 'completed' ] ) {
|
||||
$hook_results = module_invoke_all( 'fulcrm_shoppingcart_transaction_success', $transaction_data[ 'data' ] );
|
||||
foreach ( $hook_results as $hook_result )
|
||||
return $hook_result;
|
||||
drupal_set_message( t('Thank you for your order.'), 'status' );
|
||||
}
|
||||
return theme( 'fulcrm_shoppingcart_transaction_complete', array( 'transaction' => $transaction_data[ 'data' ] ) );
|
||||
} else {
|
||||
drupal_set_message( t('Although your transaction appears to have completed successfully, there has been a problem fetching the full transaction data.'), 'error' );
|
||||
@ -672,6 +718,23 @@ function fulcrm_shoppingcart_checkout_success( $transaction_id, $hmac ) {
|
||||
|
||||
function fulcrm_shoppingcart_checkout_failure( $transaction_id, $hmac ) {
|
||||
if ( fulcrm_crypto_check_object_id_hmac( 'transaction', $transaction_id, $hmac ) ) {
|
||||
$transaction_data = fulcrm_apiv2_GET( 'transaction/' . $transaction_id . '/',
|
||||
$query = array( 'expand' => implode( ',', array( 'd',
|
||||
'lineitems',
|
||||
'lineitems.d',
|
||||
'lineitems.content_object',
|
||||
'mailshots',
|
||||
'mailshots.campaign',
|
||||
'paymentitems',
|
||||
'paymentitems.d',
|
||||
) ) ) );
|
||||
if ( $transaction_data[ 'success' ] ) {
|
||||
$hook_results = module_invoke_all( 'fulcrm_shoppingcart_transaction_failure', $transaction_data[ 'data' ] );
|
||||
} else {
|
||||
$hook_results = module_invoke_all( 'fulcrm_shoppingcart_transaction_failure', NULL );
|
||||
}
|
||||
foreach ( $hook_results as $hook_result )
|
||||
return $hook_result;
|
||||
return 'failure';
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user