some work towards getting donations to be buyable
This commit is contained in:
		@ -65,7 +65,7 @@ function fulcrm_shoppingcart_admin_form( $form, &$form_state ) {
 | 
				
			|||||||
    if ( $product_data[ 'success' ] ) {
 | 
					    if ( $product_data[ 'success' ] ) {
 | 
				
			||||||
      if ( $product_data[ 'data' ][ 'results' ] ) {
 | 
					      if ( $product_data[ 'data' ][ 'results' ] ) {
 | 
				
			||||||
        foreach ( $product_data[ 'data' ][ 'results' ] as $product ) {
 | 
					        foreach ( $product_data[ 'data' ][ 'results' ] as $product ) {
 | 
				
			||||||
          $products[ $product[ 'url' ] ] = $product[ 'name' ];
 | 
					          $products[ $product[ 'id' ] ] = $product[ 'name' ];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
 | 
				
			|||||||
@ -81,6 +81,11 @@ function fulcrm_shoppingcart_menu() {
 | 
				
			|||||||
                                     'access callback' => 'user_access',
 | 
					                                     'access callback' => 'user_access',
 | 
				
			||||||
                                     'access arguments' => array('access content'),
 | 
					                                     'access arguments' => array('access content'),
 | 
				
			||||||
                                     );
 | 
					                                     );
 | 
				
			||||||
 | 
					    $items[ 'fulcrm/donate' ] = array( 'page callback' => 'fulcrm_shoppingcart_donate',
 | 
				
			||||||
 | 
					                                       'type' => MENU_CALLBACK,
 | 
				
			||||||
 | 
					                                       'access callback' => 'user_access',
 | 
				
			||||||
 | 
					                                       'access arguments' => array('access content'),
 | 
				
			||||||
 | 
					                                       );
 | 
				
			||||||
    $items[ 'fulcrm/checkout' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout',
 | 
					    $items[ 'fulcrm/checkout' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout',
 | 
				
			||||||
                                         'type' => MENU_CALLBACK,
 | 
					                                         'type' => MENU_CALLBACK,
 | 
				
			||||||
                                         'access callback' => 'user_access',
 | 
					                                         'access callback' => 'user_access',
 | 
				
			||||||
@ -677,6 +682,95 @@ 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 ) {
 | 
				
			||||||
 | 
					    // fulcrm_shoppingcart_buy_generic_product_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();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $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,
 | 
				
			||||||
 | 
					                                     ),
 | 
				
			||||||
 | 
					                       );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $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';
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fulcrm_shoppingcart_buy_donation_product_form( $form, &$form_state, $person, $product ) {
 | 
				
			||||||
 | 
					    $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] = $person;
 | 
				
			||||||
 | 
					    $form_state[ 'fulcrm_shoppingcart' ][ 'product' ] = $product;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $form = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $form[ 'title_product' ] = array( '#type' => 'markup',
 | 
				
			||||||
 | 
					                                      '#markup' => '<h3>' . check_plain( $product[ 'name' ] ) . '</h3>',
 | 
				
			||||||
 | 
					                                      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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' ),
 | 
				
			||||||
 | 
					                                          );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return $form;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fulcrm_shoppingcart_buy_donation( $person, $product ) {
 | 
				
			||||||
 | 
					   $person_id = NULL;
 | 
				
			||||||
 | 
					    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 ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $form = drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person, $eventbookingtype, $product );
 | 
				
			||||||
 | 
					    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 ) {
 | 
				
			||||||
    $product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
 | 
					    $product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -751,10 +845,7 @@ function fulcrm_shoppingcart_buy_generic_product_form( $form, &$form_state, $per
 | 
				
			|||||||
    return $form;
 | 
					    return $form;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
 | 
					function _fulcrm_shoppingcart_buy( $product_id ) {
 | 
				
			||||||
    global $user;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if ( fulcrm_crypto_check_object_id_hmac( 'product', $product_id, $hmac ) ) {
 | 
					 | 
				
			||||||
    $product_data = fulcrm_apiv2_GET( 'product/' . $product_id . '/',
 | 
					    $product_data = fulcrm_apiv2_GET( 'product/' . $product_id . '/',
 | 
				
			||||||
                                      $query = array( 'expand' => implode( ',', array( 'content_object',
 | 
					                                      $query = array( 'expand' => implode( ',', array( 'content_object',
 | 
				
			||||||
                                                                                       'selector_object',
 | 
					                                                                                       'selector_object',
 | 
				
			||||||
@ -806,6 +897,14 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
 | 
				
			|||||||
    foreach ( $hook_results as $hook_result )
 | 
					    foreach ( $hook_results as $hook_result )
 | 
				
			||||||
        return $hook_result;
 | 
					        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', '' ):
 | 
				
			||||||
 | 
					            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 ) {
 | 
				
			||||||
    case 'eventbookingtype':
 | 
					    case 'eventbookingtype':
 | 
				
			||||||
        $eventbookingtype_data = fulcrm_apiv2_GET( $product_data[ 'data' ][ 'content_object' ][ 'url' ],
 | 
					        $eventbookingtype_data = fulcrm_apiv2_GET( $product_data[ 'data' ][ 'content_object' ][ 'url' ],
 | 
				
			||||||
@ -829,6 +928,14 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
 | 
				
			|||||||
        return 'cannot handle these products yet';
 | 
					        return 'cannot handle these products yet';
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    return 'ok!';
 | 
					    return 'ok!';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
 | 
				
			||||||
 | 
					    global $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( fulcrm_crypto_check_object_id_hmac( 'product', $product_id, $hmac ) ) {
 | 
				
			||||||
 | 
					        return _fulcrm_shoppingcart_buy( $product_id );
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        drupal_not_found();
 | 
					        drupal_not_found();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -963,6 +1070,15 @@ function fulcrm_shoppingcart_coupon( $transaction_id, $hmac ) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fulcrm_shoppingcart_donate() {
 | 
				
			||||||
 | 
					    if ( variable_get( 'fulcrm_shoppingcart_donations', false ) ) {
 | 
				
			||||||
 | 
					        $product_id = variable_get( 'fulcrm_shoppingcart_donation_solicited_product', null );
 | 
				
			||||||
 | 
					        if ( $product_id )
 | 
				
			||||||
 | 
					            return _fulcrm_shoppingcart_buy( $product_id );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return drupal_goto( 'fulcrm/checkout' );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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 ) ) {
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user