array( 'title' => t('Administer fulcrm shopping cart'), 'description' => t('Perform main installation/administration tasks for fulcrm shopping cart.'), ), ); } function fulcrm_shoppingcart_menu() { /* $items[ 'admin/config/services/fulcrm' ] = array( 'page callback' => 'system_admin_menu_block_page', 'file' => 'system.admin.inc', 'file path' => drupal_get_path('module', 'system'), 'title' => 'fulcrm', 'description' => 'Configuration integration with fulcrm.org.', 'position' => 'right', 'access callback' => 'user_access', 'access arguments' => array('access administration pages'), ); */ $items[ 'admin/config/services/fulcrm/shoppingcart' ] = array( 'page callback' => 'fulcrm_shoppingcart_admin', 'file' => 'fulcrm_shoppingcart.admin.inc', 'title' => 'fulcrm Shopping Cart', 'description' => 'Configure Shopping Cart for fulcrm.org.', 'access callback' => 'user_access', 'access arguments' => array('administer fulcrm shoppingcart'), ); $items[ 'fulcrm/buy/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_buy', 'page arguments' => array(2,3), 'type' => MENU_CALLBACK, 'access callback' => 'user_access', 'access arguments' => array('access content'), ); $items[ 'fulcrm/cart' ] = array( 'page callback' => 'fulcrm_shoppingcart_cart', 'type' => MENU_CALLBACK, 'access callback' => 'user_access', 'access arguments' => array('access content'), ); $items[ 'fulcrm/checkout' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout', 'type' => MENU_CALLBACK, 'access callback' => 'user_access', 'access arguments' => array('access content'), ); return $items; } function fulcrm_shoppingcart_theme( $existing, $type, $theme, $path ) { return array( 'fulcrm_shoppingcart_cart' => array( 'variables' => array( 'shoppingcart' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_cart', ), 'fulcrm_shoppingcart_cart_items' => array( 'variables' => array( 'shoppingitems' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_cart_items', ), 'fulcrm_shoppingcart_cart_item' => array( 'variables' => array( 'shoppingitem' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_cart_item', ), ); } function fulcrm_shoppingcart_get_session_cart( $create = true ) { global $user; drupal_session_start(); 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.d', 'shoppingitems.content_object', 'shoppingitems.product' ) ) ) ); if ( $api_data[ 'success' ] ) { if ( ( $api_data[ 'data' ][ 'completed' ] === null ) && ( $api_data[ 'data' ][ 'abandoned' ] === null ) ) { return $api_data[ 'data' ]; } } } if ( $create ) { $person_url = null; if ( !user_is_anonymous() ) { $person_id = fulcrm_webhook_get_pk_for_entity_type( 'user', $user->uid, 'person' ); if ( $person_id ) $person_url = fulcrm_apiv2_make_url( 'person', $person_id ); } $cart_data = array( 'person' => $person_url, 'd' => array( 'fulcrm_testing_data' => 'this is a test' ) ); $api_data = fulcrm_apiv2_POST( 'shoppingcart/', $cart_data ); if ( $api_data[ 'success' ] ) { $_SESSION[ 'fulcrm_shoppingcart_id' ] = $api_data[ 'data' ][ 'id' ]; return $api_data[ 'data' ]; } } } function fulcrm_shoppingcart_buy_url( $product_id ) { $hmac = fulcrm_crypto_object_id_hmac( 'product', $product_id ); return url( 'fulcrm/buy/' . $product_id . '/' . $hmac ); } function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_state ) { // $person_d = fulcrm_collection_form_values_to_d( 'person', $form_state[ 'values' ] ); $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, ), 'person' => array( $person_uuid => array() ), ), ), ), $query = array( 'expand' => 'd' ) ); } // $cart[ 'd' ][ 'fulcrm' ][ 'person' ] = array( $uuid => array() ); // $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $uuid; foreach ( $form_state[ 'values' ][ 'ticket_for_persons' ] as $ticket_for_person ) { $person_uuid = fulcrm_crypto_get_object_id_form_value( 'person.uuid', $ticket_for_person ); if ( $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' => $person_uuid, ), ), 'name' => $form_state[ 'values' ][ 'shoppingitem_name' ], ), ); $api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item, $query = array( 'expand' => 'd' ) ); 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 ) { $form = array(); $form[ 'title_event' ] = array( '#type' => 'markup', '#markup' => '