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() {
|
function fulcrm_shoppingcart_menu() {
|
||||||
/*
|
/*
|
||||||
$items[ 'admin/config/services/fulcrm' ] = array( 'page callback' => 'system_admin_menu_block_page',
|
$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.related_to.d',
|
||||||
'related_to_person2persons.relationship',
|
'related_to_person2persons.relationship',
|
||||||
) ) ) );
|
) ) ) );
|
||||||
|
if ( !$person_data[ 'success' ] ) {
|
||||||
|
return 'error while fetching your details!';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$person_data = array( 'data' => array() );
|
$person_data = array( 'data' => array() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $product_data[ 'success' ] ) {
|
if ( !$product_data[ 'success' ] ) {
|
||||||
switch ( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ? fulcrm_apiv2_url_to_type( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ) : null ) {
|
return 'error while fetching the contents of your shopping cart!';
|
||||||
case 'eventbookingtype':
|
}
|
||||||
$eventbookingtype_data = fulcrm_apiv2_GET( $product_data[ 'data' ][ 'content_object' ][ 'url' ],
|
|
||||||
$query = array( 'expand' => implode( ',', array( 'event',
|
$shoppingcart_data = fulcrm_shoppingcart_get_session_cart( $create = true );
|
||||||
'person_ddatacollection',
|
if ( !$shoppingcart_data[ 'success' ] ) {
|
||||||
'eventbooking_ddatacollection',
|
return 'error while fetching information about this product!';
|
||||||
'eventbookingtypeslots',
|
}
|
||||||
'eventbookingtypeslots.eventslot' ) ) ) );
|
|
||||||
if ( $eventbookingtype_data[ 'success' ] ) {
|
$hook_results = module_invoke_all( 'fulcrm_shoppingcart_pre_add_to_cart', $shoppingcart_data[ 'data' ], $person_data[ 'data' ], $product_data[ 'data' ] );
|
||||||
return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person_data[ 'data' ], $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] );
|
foreach ( $hook_results as $hook_result )
|
||||||
}
|
return $hook_result;
|
||||||
break;
|
|
||||||
case null:
|
switch ( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ? fulcrm_apiv2_url_to_type( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ) : null ) {
|
||||||
return drupal_get_form( 'fulcrm_shoppingcart_buy_generic_product_form', $person_data[ 'data' ], $product_data[ 'data' ] );
|
case 'eventbookingtype':
|
||||||
default:
|
$eventbookingtype_data = fulcrm_apiv2_GET( $product_data[ 'data' ][ 'content_object' ][ 'url' ],
|
||||||
return 'cannot handle these products yet';
|
$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!';
|
return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person_data[ 'data' ], $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] );
|
||||||
} else {
|
break;
|
||||||
return 'error adding item to shopping cart';
|
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 {
|
} else {
|
||||||
drupal_not_found();
|
drupal_not_found();
|
||||||
}
|
}
|
||||||
@ -622,6 +656,10 @@ function fulcrm_shoppingcart_coupon( $transaction_id, $hmac ) {
|
|||||||
function fulcrm_shoppingcart_checkout() {
|
function fulcrm_shoppingcart_checkout() {
|
||||||
$cart = fulcrm_shoppingcart_get_session_cart( false );
|
$cart = fulcrm_shoppingcart_get_session_cart( false );
|
||||||
if ( $cart && array_key_exists( 'url', $cart ) ) {
|
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' ) ) ) );
|
$transaction_data = fulcrm_apiv2_POST( $cart[ 'url' ] . 'transaction/', array(), array( 'expand' => implode( ',', array( 'd' ) ) ) );
|
||||||
if ( $transaction_data[ 'success' ] ) {
|
if ( $transaction_data[ 'success' ] ) {
|
||||||
$hmac = fulcrm_crypto_object_id_hmac( 'transaction', $transaction_data[ 'data' ][ 'id' ] );
|
$hmac = fulcrm_crypto_object_id_hmac( 'transaction', $transaction_data[ 'data' ][ 'id' ] );
|
||||||
@ -638,6 +676,9 @@ function fulcrm_shoppingcart_checkout() {
|
|||||||
'paymentitems',
|
'paymentitems',
|
||||||
) ) ) );
|
) ) ) );
|
||||||
if ( $transaction_data2[ 'success' ] ) {
|
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' ],
|
return theme( 'fulcrm_shoppingcart_transaction_checkout', array( 'transaction' => $transaction_data2[ 'data' ],
|
||||||
'use_coupon_url' => fulcrm_shoppingcart_coupon_url( $transaction_data[ 'data' ][ 'id' ] ),
|
'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 ) {
|
function fulcrm_shoppingcart_checkout_success( $transaction_id, $hmac ) {
|
||||||
if ( fulcrm_crypto_check_object_id_hmac( 'transaction', $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',
|
$transaction_data = fulcrm_apiv2_GET( 'transaction/' . $transaction_id . '/',
|
||||||
'lineitems',
|
$query = array( 'expand' => implode( ',', array( 'd',
|
||||||
'lineitems.d',
|
'lineitems',
|
||||||
'lineitems.content_object',
|
'lineitems.d',
|
||||||
'mailshots',
|
'lineitems.content_object',
|
||||||
'mailshots.campaign',
|
'mailshots',
|
||||||
'paymentitems',
|
'mailshots.campaign',
|
||||||
'paymentitems.d',
|
'paymentitems',
|
||||||
) ) ) );
|
'paymentitems.d',
|
||||||
|
) ) ) );
|
||||||
if ( $transaction_data[ 'success' ] ) {
|
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' );
|
drupal_set_message( t('Thank you for your order.'), 'status' );
|
||||||
|
}
|
||||||
return theme( 'fulcrm_shoppingcart_transaction_complete', array( 'transaction' => $transaction_data[ 'data' ] ) );
|
return theme( 'fulcrm_shoppingcart_transaction_complete', array( 'transaction' => $transaction_data[ 'data' ] ) );
|
||||||
} else {
|
} else {
|
||||||
drupal_set_message( t('Although your transaction appears to have completed successfully, there has been a problem fetching the full transaction data.'), 'error' );
|
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 ) {
|
function fulcrm_shoppingcart_checkout_failure( $transaction_id, $hmac ) {
|
||||||
if ( fulcrm_crypto_check_object_id_hmac( 'transaction', $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';
|
return 'failure';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user