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), '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.content_object' ) ) ) ); 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( $product_id ) { $api_data = fulcrm_apiv2_GET( 'product/' . $product_id . '/', $query = array( 'expand' => implode( ',', array( 'content_object', 'selector_object' ) ) ) ); return print_r( $api_data, 1 ); } function fulcrm_shoppingcart_cart() { $cart = fulcrm_shoppingcart_get_session_cart( false ); return theme( 'fulcrm_shopping_cart', array( 'cart' => $cart ) ); } function fulcrm_shoppingcart_checkout() { $cart = fulcrm_shoppingcart_get_session_cart( false ); return print_r( $cart, 1 ); }