@ -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
'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',
'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,11 +685,11 @@ function fulcrm_shoppingcart_buy_eventbookingtype( $person, $eventbookingtype, $
return drupal_render( $form );
return drupal_render( $form );
}
}
function fulcrm_shoppingcart_buy_donation_product_form_submit( $form, &$form_state ) {
function fulcrm_shoppingcart_buy_donation_form_submit( $form, &$form_state ) {
// fulcrm_shoppingcart_buy_generic_product_form_submit( $form, $form_state );
$product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
$product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
$donation_amount = floatval( $form_state[ 'values' ][ 'donation_amount' ] );
if ( $donation_amount > 0.0 ) {
$person_uuid = NULL;
$person_uuid = NULL;
if ( array_key_exists( 'person', $form_state[ 'fulcrm_shoppingcart' ] ) &&
if ( array_key_exists( 'person', $form_state[ 'fulcrm_shoppingcart' ] ) &&
array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] ) )
array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] ) )
@ -720,6 +723,8 @@ function fulcrm_shoppingcart_buy_donation_product_form_submit( $form, &$form_sta
$item = array( 'shoppingcart' => $cart[ 'url' ],
$item = array( 'shoppingcart' => $cart[ 'url' ],
'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
'product' => fulcrm_apiv2_make_url( 'product', $product_id ),
'quantity' => 1.0,
'quantity' => 1.0,
'item' => 'donation',
'item_net' => $donation_amount,
'd' => array( 'name' => $shoppingitem_name,
'd' => array( 'name' => $shoppingitem_name,
),
),
);
);
@ -727,17 +732,20 @@ function fulcrm_shoppingcart_buy_donation_product_form_submit( $form, &$form_sta
$api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item, $query = array( 'expand' => 'd' ) );
$api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item, $query = array( 'expand' => 'd' ) );
fulcrm_shoppingcart_invalidate_cache();
fulcrm_shoppingcart_invalidate_cache();
if ( $api_data[ 'success' ] ) {
if ( $api_data[ 'success' ] ) {
drupal_set_message( t('Added "%item" to shopping cart.', array( '%item' => $item[ 'd' ][ 'name' ] ) ), 'status' );
drupal_set_message( t('Added your donation to your shopping cart.', array( '%item' => $item[ 'd' ][ 'name' ] ) ), 'status' );
$form_state[ 'redirect' ] = 'fulcrm/cart';
$form_state[ 'redirect' ] = 'fulcrm/cart';
} else {
} 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 {
} 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('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' ][ 'person' ] = $person;
$form_state[ 'fulcrm_shoppingcart' ][ 'product' ] = $product;
$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>',
'#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' ] ) );
drupal_set_title( check_plain( $product[ 'data' ][ 'name' ] ) );
$form[ 'actions' ] = array( '#type' => 'actions' );
$form[ 'actions' ] = array( '#type' => 'actions' );
$form[ 'actions' ][ 'save' ] = array( '#type' => 'submit',
$form[ 'actions' ][ 'save' ] = array( '#type' => 'submit',
'#value' => t('Add to Cart'),
'#value' => t('Add to Cart'),
'#submit' => array( 'fulcrm_shoppingcart_buy_donation_product_ form_submit' ),
'#submit' => array( 'fulcrm_shoppingcart_buy_donation_form_submit' ),
);
);
return $form;
return $form;
@ -763,12 +776,9 @@ function fulcrm_shoppingcart_buy_donation( $person, $product ) {
if ( array_key_exists( 'id', $person ) )
if ( array_key_exists( 'id', $person ) )
$person_id = $person[ 'id' ];
$person_id = $person[ 'id' ];
$fulcrm_shoppingcart_buy_eventbookingtype_form = drupal_get_form( 'fulcrm_shoppingcart_buy_donation_form', $person, $product );
$fulcrm_shoppingcart_buy_donation_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 ) );
$form = drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person, $eventbookingtype, $product );
return theme( 'fulcrm_shoppingcart_buy_donation_page', array( 'product' => $product, 'fulcrm_shoppingcart_buy_donation_form' => $fulcrm_shoppingcart_buy_donation_form ) );
return drupal_render( $form );
}
}
function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_state ) {
function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_state ) {
@ -898,11 +908,13 @@ function _fulcrm_shoppingcart_buy( $product_id ) {
return $hook_result;
return $hook_result;
if ( variable_get( 'fulcrm_shoppingcart_donations', false ) ) {
if ( variable_get( 'fulcrm_shoppingcart_donations', false ) ) {
switch ( $product_data[ 'data' ][ 'id' ] ) {
$checkout_product_id = variable_get( 'fulcrm_shoppingcart_donation_checkout_product', 0 );
case variable_set( 'fulcrm_shoppingcart_donation_checkout_product', '' ):
if ( ( $checkout_product_id > 0 ) && ( $product_data[ 'data' ][ 'id' ] == $checkout_product_id ) )
case variable_set( 'fulcrm_shoppingcart_donation_solicited_product', '' ):
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' ] );
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 ) {
switch ( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ? fulcrm_apiv2_url_to_type( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ) : null ) {