diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index 682345d..c76f754 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -68,7 +68,8 @@ function fulcrm_shoppingcart_get_session_cart( $create = true ) { if ( array_key_exists( 'fulcrm_shoppingcart_id', $_SESSION ) ) { $api_data = fulcrm_apiv2_GET( 'shoppingcart/' . $_SESSION[ 'fulcrm_shoppingcart_id' ] . '/', $query = array( 'expand' => implode( ',', array( 'shoppingitems', - 'shoppingitems.content_object' ) ) ) ); + 'shoppingitems.content_object', + 'shoppingitems.product' ) ) ) ); if ( $api_data[ 'success' ] ) { if ( ( $api_data[ 'data' ][ 'completed' ] === null ) && ( $api_data[ 'data' ][ 'abandoned' ] === null ) ) { return $api_data[ 'data' ]; @@ -101,7 +102,52 @@ function fulcrm_shoppingcart_buy_url( $product_id ) { } function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_state ) { - + $product_id = fulcrm_crypto_get_object_id_form_value( 'product', $form_state[ 'values' ][ 'product_id_hmac' ] ); + $eventbookingtype_id = fulcrm_crypto_get_object_id_form_value( 'eventbookingtype', $form_state[ 'values' ][ 'eventbookingtype_id_hmac' ] ); + + $person_id = NULL; + $person_uuid = NULL; + if ( array_key_exists( 'person_id_hmac', $form_state[ 'values' ] ) ) + $person_id = fulcrm_crypto_get_object_id_form_value( 'person', $form_state[ 'values' ][ 'person_id_hmac' ] ); + if ( array_key_exists( 'person_uuid_hmac', $form_state[ 'values' ] ) ) + $person_uuid = fulcrm_crypto_get_object_id_form_value( 'person.uuid', $form_state[ 'values' ][ 'person_uuid_hmac' ] ); + + $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, + ), + ), + ), + ) ); + } + + // $cart[ 'd' ][ 'fulcrm' ][ 'person' ] = array( $uuid => array() ); + // $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $uuid; + + $item = array( 'shoppingcart' => $cart[ 'url' ], + 'product' => fulcrm_apiv2_make_url( 'product', $product_id ), + 'quantity' => 1.0, + 'd' => array( 'fulcrm' => array( 'eventbooking' => array( 'eventbooking' => array( 'foo' => 'bar', + ), + // 'eventslotbookings' => array( $part => $slot ) + // 'person' => $uuid, + ), + ), + ), + ); + + $api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item ); + if ( $api_data[ 'success' ] ) { + drupal_set_message( t('Added to shopping cart.'), '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_eventbookingtype_form( $form, &$form_state, $person, $eventbookingtype, $product ) { @@ -117,6 +163,18 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $pe '#markup' => '