handle generic products
This commit is contained in:
		@ -357,6 +357,75 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe
 | 
				
			|||||||
    return $form;
 | 
					    return $form;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_state ) {
 | 
				
			||||||
 | 
					    $product_id = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $person_id = NULL;
 | 
				
			||||||
 | 
					    $person_uuid = NULL;
 | 
				
			||||||
 | 
					    if ( array_key_exists( 'id', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
				
			||||||
 | 
					        $person_id = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'id' ];
 | 
				
			||||||
 | 
					    if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
				
			||||||
 | 
					        $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( array_key_exists( 'shoppingcart', $form_state[ 'fulcrm_shoppingcart' ] ) )
 | 
				
			||||||
 | 
					        $cart = $form_state[ 'fulcrm_shoppingcart' ][ 'shoppingcart' ];
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        $cart = fulcrm_shoppingcart_get_session_cart();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if ( is_array( $cart ) ) {
 | 
				
			||||||
 | 
					        if ( $person_uuid ) {
 | 
				
			||||||
 | 
					            $api_data = fulcrm_apiv2_PATCH( $cart[ 'url' ], 
 | 
				
			||||||
 | 
					                                            array( 'd' => array( 'fulcrm' => array( 'transaction' => array( 'person' => $person_uuid,
 | 
				
			||||||
 | 
					                                                                                                            ),
 | 
				
			||||||
 | 
					                                                                                    'person' => array( $person_uuid => array() ),
 | 
				
			||||||
 | 
					                                                                                    ),
 | 
				
			||||||
 | 
					                                                                 ),
 | 
				
			||||||
 | 
					                                                   ),
 | 
				
			||||||
 | 
					                                            $query = array( 'expand' => 'd' ) );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $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' ) );
 | 
				
			||||||
 | 
					        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' );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $form_state[ 'fulcrm_shoppingcart' ][ 'shoppingcart' ] = $cart;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function fulcrm_shoppingcart_buy_generic_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>',
 | 
				
			||||||
 | 
					                                      );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    $form[ 'actions' ] = array( '#type' => 'actions' );
 | 
				
			||||||
 | 
					    $form[ 'actions' ][ 'save' ] = array( '#type' => 'submit',
 | 
				
			||||||
 | 
					                                          '#value' => t('Add to Cart'),
 | 
				
			||||||
 | 
					                                          '#submit' => array( 'fulcrm_shoppingcart_buy_generic_product_form_submit' ),
 | 
				
			||||||
 | 
					                                          );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return $form;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
 | 
					function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
 | 
				
			||||||
    global $user;
 | 
					    global $user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -392,7 +461,7 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ( $product_data[ 'success' ] ) {
 | 
					        if ( $product_data[ 'success' ] ) {
 | 
				
			||||||
            switch ( fulcrm_apiv2_url_to_type( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ) ) {
 | 
					            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' ],
 | 
				
			||||||
                                                           $query = array( 'expand' => implode( ',', array( 'event',
 | 
					                                                           $query = array( 'expand' => implode( ',', array( 'event',
 | 
				
			||||||
@ -404,6 +473,8 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
 | 
				
			|||||||
                    return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person_data[ 'data' ], $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] );
 | 
					                    return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person_data[ 'data' ], $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] );
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					            case null:
 | 
				
			||||||
 | 
					                return drupal_get_form( 'fulcrm_shoppingcart_buy_generic_product_form', $person_data[ 'data' ], $product_data[ 'data' ] );
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                return 'cannot handle these products yet';
 | 
					                return 'cannot handle these products yet';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user