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/remove/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_remove', 'page arguments' => array(3,4), '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'), ); $items[ 'fulcrm/checkout/success/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout_success', 'page arguments' => array(3,4), 'type' => MENU_CALLBACK, 'access callback' => 'user_access', 'access arguments' => array('access content'), ); $items[ 'fulcrm/checkout/failure/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout_failure', 'page arguments' => array(3,4), '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', ), 'fulcrm_shoppingcart_transaction_checkout' => array( 'variables' => array( 'transaction' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_transaction_checkout', ), 'fulcrm_shoppingcart_transaction_items' => array( 'variables' => array( 'items' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_transaction_items', ), 'fulcrm_shoppingcart_transaction_item' => array( 'variables' => array( 'item' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_transaction_item', ), 'fulcrm_shoppingcart_transaction_complete' => array( 'variables' => array( 'transaction' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_transaction_complete', ), 'fulcrm_shoppingcart_transaction_mailshots' => array( 'variables' => array( 'transaction' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_transaction_mailshots', ), 'fulcrm_shoppingcart_transaction_mailshot' => array( 'variables' => array( 'mailshot' => null ), // data returned from fulcrm API 'template' => 'fulcrm_shoppingcart_transaction_mailshot', ), ); } 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' ]; } } else { if ( $api_data[ 'code' ] === 404 ) unset( $_SESSION[ 'fulcrm_shoppingcart_id' ] ); } } 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_remove_url( $shoppingitem_id ) { $hmac = fulcrm_crypto_object_id_hmac( 'shoppingitem', $shoppingitem_id ); return url( 'fulcrm/cart/remove/' . $shoppingitem_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 = $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'id' ]; $eventbookingtype_id = $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ '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' ) ); } foreach ( $form_state[ 'values' ][ 'ticket_for_persons' ] as $ticket_for_person ) { if ( $ticket_for_person === 'myself' ) { $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ]; $person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'name' ]; } else { $person_uuid = fulcrm_crypto_get_object_id_form_value( 'person.uuid', $ticket_for_person ); if ( $person_uuid ) $person_name = $form_state[ 'fulcrm_shoppingcart' ][ 'persons' ][ $person_uuid ][ 'name' ]; } $shoppingitem_name = ( $form_state[ 'fulcrm_shoppingcart' ][ 'product' ][ 'name' ] . ', ' . $person_name . "\r\n" . $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'name' ] . "\r\n" . $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'event' ][ 'name' ] ); $eventslotbookings = array(); if ( array_key_exists( 'eventbookingtypeslots', $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ] ) ) { foreach ( $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'eventbookingtypeslots' ] as $eventbookingtypeslots ) { $eventpart_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'eventpart' ] ); $eventslot_id = fulcrm_apiv2_url_to_pk( $eventbookingtypeslots[ 'eventslot' ][ 'url' ] ); if ( array_key_exists( $eventpart_id, $eventslotbookings ) ) drupal_set_message( 'XXX cannot yet cope with multiple choice event slot bookings; defaulting to first.', 'warning' ); $eventslotbookings[ $eventpart_id ] = $eventslot_id; } } else { drupal_set_message( 'XXX no eventbookingtypeslots to choose from?', 'warning' ); } 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(), 'eventslotbookings' => $eventslotbookings, 'person' => $person_uuid, ), ), '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_eventbookingtype_form( $form, &$form_state, $person, $eventbookingtype, $product ) { $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] = $person; $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ] = $eventbookingtype; $form_state[ 'fulcrm_shoppingcart' ][ 'product' ] = $product; $form = array(); $form[ 'title_event' ] = array( '#type' => 'markup', '#markup' => '