From e386754095fbf1b87f0e37c634c130fc97249e37 Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Thu, 7 Apr 2016 16:51:19 +0100 Subject: [PATCH] start to show mailshots related to transaction --- fulcrm_shoppingcart.module | 47 ++++++++++++++++--- ..._shoppingcart_transaction_mailshot.tpl.php | 11 +++++ ...shoppingcart_transaction_mailshots.tpl.php | 8 ++++ 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 fulcrm_shoppingcart_transaction_mailshot.tpl.php create mode 100644 fulcrm_shoppingcart_transaction_mailshots.tpl.php diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index af64a78..c5e86b3 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -84,6 +84,12 @@ function fulcrm_shoppingcart_theme( $existing, $type, $theme, $path ) { 'fulcrm_shoppingcart_transaction_item' => array( 'variables' => array( 'item' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_transaction_item', ), + 'fulcrm_shoppingcart_transaction_mailshots' => array( 'variables' => array( 'transaction' => null ), // data returned from fulcrm API + 'template' => 'fulcrm_shoppingcart_transaction_mailshots', + ), + 'fulcrm_shoppingcart_transaction_mailshot' => array( 'variables' => array( 'mailshot' => null ), // data returned from fulcrm API + 'template' => 'fulcrm_shoppingcart_transaction_mailshot', + ), ); } @@ -414,12 +420,12 @@ function fulcrm_shoppingcart_checkout() { $transaction_data2 = fulcrm_apiv2_PATCH( $transaction_data[ 'data' ][ 'url' ], $transaction_push, $query = array( 'expand' => implode( ',', array( 'd', - 'lineitems', - 'lineitems.d', - 'lineitems.content_object', + // 'lineitems', + // 'lineitems.d', + // 'lineitems.content_object', // XXX 'lineitems.content_object.d', - 'paymentitems', - 'paymentitems.d', + // 'paymentitems', + // 'paymentitems.d', ) ) ) ); if ( $transaction_data2[ 'success' ] ) { return theme( 'fulcrm_shoppingcart_transaction_checkout', array( 'transaction' => $transaction_data2[ 'data' ] ) ); @@ -432,9 +438,36 @@ function fulcrm_shoppingcart_checkout() { } function fulcrm_shoppingcart_checkout_success( $transaction_id, $hmac ) { - return 'success'; + 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' ] ) { + if ( $transaction_data[ 'data' ][ 'completed' ] ) + drupal_set_message( t('Thank you for your order.'), 'status' ); + + $rval = ''; + + if ( $transaction_data[ 'data' ][ 'mailshots' ] ) + $rval .= theme( 'fulcrm_shoppingcart_transaction_mailshots', array( 'transaction' => $transaction_data[ 'data' ] ) ); + + $rval .= '
' . print_r( $transaction_data[ 'data' ], 1 ) . '
'; // XXX debug + + return $rval; + } else { + drupal_set_message( t('Although your transaction appears to have completed successfully, there has been a problem fetching the full transaction data.'), 'error' ); + } + } } function fulcrm_shoppingcart_checkout_failure( $transaction_id, $hmac ) { - return 'failure'; + if ( fulcrm_crypto_check_object_id_hmac( 'transaction', $transaction_id, $hmac ) ) { + return 'failure'; + } } diff --git a/fulcrm_shoppingcart_transaction_mailshot.tpl.php b/fulcrm_shoppingcart_transaction_mailshot.tpl.php new file mode 100644 index 0000000..beafa1f --- /dev/null +++ b/fulcrm_shoppingcart_transaction_mailshot.tpl.php @@ -0,0 +1,11 @@ +
  • + format( '\s\e\n\t \o\n j/M/Y \a\t ga' ); + ?> + $v ): ?> + view + +
  • diff --git a/fulcrm_shoppingcart_transaction_mailshots.tpl.php b/fulcrm_shoppingcart_transaction_mailshots.tpl.php new file mode 100644 index 0000000..b56c92e --- /dev/null +++ b/fulcrm_shoppingcart_transaction_mailshots.tpl.php @@ -0,0 +1,8 @@ +
    +

    Emails about your Transaction

    + +