now able to make a donation via the one-off donation page

master
Marek Isalski 5 years ago
parent a89aa9d62a
commit 83803d6dd1

@ -10,8 +10,8 @@ function fulcrm_shoppingcart_admin_form_submit( $form, &$form_state ) {
variable_set( 'fulcrm_shoppingcart_experience', $form_state[ 'values' ][ 'experience' ] );
variable_set( 'fulcrm_shoppingcart_donations', $form_state[ 'values' ][ 'donation_enabled' ] );
variable_set( 'fulcrm_shoppingcart_donation_checkout_product', $form_state[ 'values' ][ 'donation_checkout_product' ] );
variable_set( 'fulcrm_shoppingcart_donation_solicited_product', $form_state[ 'values' ][ 'donation_solicited_product' ] );
variable_set( 'fulcrm_shoppingcart_donation_checkout_product', intval( $form_state[ 'values' ][ 'donation_checkout_product' ] ) );
variable_set( 'fulcrm_shoppingcart_donation_solicited_product', intval( $form_state[ 'values' ][ 'donation_solicited_product' ] ) );
drupal_set_message( t('Settings saved.'), 'status' );
}

@ -156,6 +156,9 @@ function fulcrm_shoppingcart_theme( $existing, $type, $theme, $path ) {
'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',
),
'fulcrm_shoppingcart_buy_donation_page' => array( 'variables' => array( 'product' => null, 'fulcrm_shoppingcart_buy_donation_form' => null ), // data returned from fulcrm API
'template' => 'fulcrm_shoppingcart_buy_donation_page',
),
);
}
@ -682,62 +685,67 @@ function fulcrm_shoppingcart_buy_eventbookingtype( $person, $eventbookingtype, $
return drupal_render( $form );
}
function fulcrm_shoppingcart_buy_donation_product_form_submit( $form, &$form_state ) {
// fulcrm_shoppingcart_buy_generic_product_form_submit( $form, $form_state );
function fulcrm_shoppingcart_buy_donation_form_submit( $form, &$form_state ) {
$product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
$person_uuid = NULL;
if ( array_key_exists( 'person', $form_state[ 'fulcrm_shoppingcart' ] ) &&
array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] ) )
$person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
$cart = fulcrm_shoppingcart_get_session_cart();
if ( is_array( $cart ) ) {
if ( $person_uuid ) {
$patch = FALSE;
if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array( 'uuid' => $person_uuid );
$patch = TRUE;
}
if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_uuid;
$patch = TRUE;
}
if ( $patch ) {
$api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ], array( 'd' => $cart[ 'd' ] ),
$query = array( 'expand' => 'd' ) );
fulcrm_shoppingcart_invalidate_cache();
$donation_amount = floatval( $form_state[ 'values' ][ 'donation_amount' ] );
if ( $donation_amount > 0.0 ) {
$person_uuid = NULL;
if ( array_key_exists( 'person', $form_state[ 'fulcrm_shoppingcart' ] ) &&
array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] ) )
$person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
$cart = fulcrm_shoppingcart_get_session_cart();
if ( is_array( $cart ) ) {
if ( $person_uuid ) {
$patch = FALSE;
if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array( 'uuid' => $person_uuid );
$patch = TRUE;
}
if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_uuid;
$patch = TRUE;
}
if ( $patch ) {
$api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ], array( 'd' => $cart[ 'd' ] ),
$query = array( 'expand' => 'd' ) );
fulcrm_shoppingcart_invalidate_cache();
}
}
}
$shoppingitem_name = ( $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] );
$shoppingitem_name = ( $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] );
$item = array( 'shoppingcart' => $cart[ 'url' ],
'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
'quantity' => 1.0,
'd' => array( 'name' => $shoppingitem_name,
),
);
$item = array( 'shoppingcart' => $cart[ 'url' ],
'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
'quantity' => 1.0,
'item' => 'donation',
'item_net' => $donation_amount,
'd' => array( 'name' => $shoppingitem_name,
),
);
$api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item, $query = array( 'expand' => 'd' ) );
fulcrm_shoppingcart_invalidate_cache();
if ( $api_data[ 'success' ] ) {
drupal_set_message( t('Added "%item" to shopping cart.', array( '%item' => $item[ 'd' ][ 'name' ] ) ), 'status' );
$form_state[ 'redirect' ] = 'fulcrm/cart';
$api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item, $query = array( 'expand' => 'd' ) );
fulcrm_shoppingcart_invalidate_cache();
if ( $api_data[ 'success' ] ) {
drupal_set_message( t('Added your donation to your shopping cart.', array( '%item' => $item[ 'd' ][ 'name' ] ) ), 'status' );
$form_state[ 'redirect' ] = 'fulcrm/cart';
} else {
drupal_set_message( t('There was a problem adding your donation to your shopping cart.'), 'error' );
}
} else {
drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
drupal_set_message( t('There was a problem adding your donation to your shopping cart.'), 'error' );
}
} else {
drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
drupal_set_message( t('No donation added.'), 'warning' );
}
}
function fulcrm_shoppingcart_buy_donation_product_form( $form, &$form_state, $person, $product ) {
function fulcrm_shoppingcart_buy_donation_form( $form, &$form_state, $person, $product ) {
$form_state[ 'fulcrm_shoppingcart' ][ 'person' ] = $person;
$form_state[ 'fulcrm_shoppingcart' ][ 'product' ] = $product;
@ -747,12 +755,17 @@ function fulcrm_shoppingcart_buy_donation_product_form( $form, &$form_state, $pe
'#markup' => '<h3>' . check_plain( $product[ 'name' ] ) . '</h3>',
);
$form[ 'donation_amount' ] = array( '#type' => 'textfield',
'#title' => 'Donation Amount (' . $product[ '_price' ][ 'currency' ] . ')',
'#default_value' => sprintf( "%.2f", $product[ '_price' ][ 'item_net' ] ),
);
drupal_set_title( check_plain( $product[ 'data' ][ 'name' ] ) );
$form[ 'actions' ] = array( '#type' => 'actions' );
$form[ 'actions' ][ 'save' ] = array( '#type' => 'submit',
'#value' => t('Add to Cart'),
'#submit' => array( 'fulcrm_shoppingcart_buy_donation_product_form_submit' ),
'#submit' => array( 'fulcrm_shoppingcart_buy_donation_form_submit' ),
);
return $form;
@ -763,12 +776,9 @@ function fulcrm_shoppingcart_buy_donation( $person, $product ) {
if ( array_key_exists( 'id', $person ) )
$person_id = $person[ 'id' ];
$fulcrm_shoppingcart_buy_eventbookingtype_form = drupal_get_form( 'fulcrm_shoppingcart_buy_donation_form', $person, $product );
return theme( 'fulcrm_shoppingcart_buy_donation', array( 'fulcrm_shoppingcart_buy_donation_form' => $fulcrm_shoppingcart_buy_donation_form ) );
$fulcrm_shoppingcart_buy_donation_form = drupal_get_form( 'fulcrm_shoppingcart_buy_donation_form', $person, $product );
$form = drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person, $eventbookingtype, $product );
return drupal_render( $form );
return theme( 'fulcrm_shoppingcart_buy_donation_page', array( 'product' => $product, 'fulcrm_shoppingcart_buy_donation_form' => $fulcrm_shoppingcart_buy_donation_form ) );
}
function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_state ) {
@ -898,11 +908,13 @@ function _fulcrm_shoppingcart_buy( $product_id ) {
return $hook_result;
if ( variable_get( 'fulcrm_shoppingcart_donations', false ) ) {
switch ( $product_data[ 'data' ][ 'id' ] ) {
case variable_set( 'fulcrm_shoppingcart_donation_checkout_product', '' ):
case variable_set( 'fulcrm_shoppingcart_donation_solicited_product', '' ):
$checkout_product_id = variable_get( 'fulcrm_shoppingcart_donation_checkout_product', 0 );
if ( ( $checkout_product_id > 0 ) && ( $product_data[ 'data' ][ 'id' ] == $checkout_product_id ) )
return fulcrm_shoppingcart_buy_donation( $person_data[ 'data' ], $product_data[ 'data' ] );
$solicited_product_id = variable_get( 'fulcrm_shoppingcart_donation_solicited_product', 0 );
if ( ( $solicited_product_id > 0 ) && ( $product_data[ 'data' ][ 'id' ] == $solicited_product_id ) )
return fulcrm_shoppingcart_buy_donation( $person_data[ 'data' ], $product_data[ 'data' ] );
}
}
switch ( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ? fulcrm_apiv2_url_to_type( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ) : null ) {

@ -0,0 +1 @@
<?php print render( $fulcrm_shoppingcart_buy_donation_form ); ?>

@ -1,5 +1,5 @@
<tr>
<td><span class="pull-right"><a class="btn btn-xs btn-danger" title="Remove from cart" href="<?php print fulcrm_shoppingcart_remove_url( $item[ 'id' ] ); ?>"><span class="glyphicon glyphicon-trash"></span></a></span><?php if ( array_key_exists( 'name', $item[ 'd' ] ) ) print nl2br( check_plain( $item[ 'd' ][ 'name' ] ) ); else print check_plain( $item[ 'product' ][ 'name' ] ); ?></td>
<td class="text-right"><?php print check_plain( $item[ 'quantity' ] ); ?></td>
<td class="text-right"><?php print ( ( array_key_exists( 'format_item_gross', $item[ 'product' ][ '_price' ] ) && $item[ 'product' ][ '_price' ][ 'format_item_gross' ] ) ? check_plain( $item[ 'product' ][ '_price' ][ 'format_item_gross' ] ) : t('free') ); ?></td>
<td class="text-right"><?php print ( ( array_key_exists( 'format_total', $item[ '_price' ] ) && $item[ '_price' ][ 'format_total' ] ) ? check_plain( $item[ '_price' ][ 'format_total' ] ) : t('free') ); ?></td>
</tr>

Loading…
Cancel
Save