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' => '

' . check_plain( $product[ 'name' ] ) . '

', ); + $form[ 'product_id_hmac' ] = array( '#type' => 'hidden', + '#value' => fulcrm_crypto_object_id_form_value( 'product', $product[ 'id' ] ) ); + $form[ 'eventbookingtype_id_hmac' ] = array( '#type' => 'hidden', + '#value' => fulcrm_crypto_object_id_form_value( 'eventbookingtype', $eventbookingtype[ 'id' ] ) ); + + if ( array_key_exists( 'id', $person ) ) { + $form[ 'person_id_hmac' ] = array( '#type' => 'hidden', + '#value' => fulcrm_crypto_object_id_form_value( 'person', $person[ 'id' ] ) ); + $form[ 'person_uuid_hmac' ] = array( '#type' => 'hidden', + '#value' => fulcrm_crypto_object_id_form_value( 'person.uuid', $person[ 'uuid' ] ) ); + } + if ( array_key_exists( 'id', $person ) ) $persons = array( fulcrm_crypto_object_id_hmac( 'person', $person[ 'id' ] ) => 'myself' ); else diff --git a/fulcrm_shoppingcart_cart.tpl.php b/fulcrm_shoppingcart_cart.tpl.php index fa898e2..60d8b0d 100644 --- a/fulcrm_shoppingcart_cart.tpl.php +++ b/fulcrm_shoppingcart_cart.tpl.php @@ -10,7 +10,7 @@ - $cart[ 'shoppingitems' ] ) ); ?> + $cart[ 'shoppingitems' ] ) ); ?> diff --git a/fulcrm_shoppingcart_item.tpl.php b/fulcrm_shoppingcart_cart_item.tpl.php similarity index 70% rename from fulcrm_shoppingcart_item.tpl.php rename to fulcrm_shoppingcart_cart_item.tpl.php index b925394..d0cfa13 100644 --- a/fulcrm_shoppingcart_item.tpl.php +++ b/fulcrm_shoppingcart_cart_item.tpl.php @@ -1,5 +1,5 @@ - + diff --git a/fulcrm_shoppingcart_cart_items.tpl.php b/fulcrm_shoppingcart_cart_items.tpl.php new file mode 100644 index 0000000..529344d --- /dev/null +++ b/fulcrm_shoppingcart_cart_items.tpl.php @@ -0,0 +1,5 @@ + + + + $item ) ); ?> + diff --git a/fulcrm_shoppingcart_items.tpl.php b/fulcrm_shoppingcart_items.tpl.php deleted file mode 100644 index 346bff5..0000000 --- a/fulcrm_shoppingcart_items.tpl.php +++ /dev/null @@ -1,3 +0,0 @@ - - $item ) ); ?> -