3 replies [Last post]
grobot's picture
Offline
Joined: 04/12/2008
Juice: 289
Was this information Helpful?

I want to add a link to the site nav, such that any logged-in user can click through from the regular menu to see their orders.

I was hoping that this would work:

<?php
/**
* implement hook_menu()
*/
function mymodule_menu($may_cache) {
  if ( !
$may_cache ) {
    global
$user ;
    if (
$user->uid ) {
     
$items[] = array(
       
'path' => 'user/'. $user->uid .'/orders',
       
'title' => t('My Orders'),
       
'description' => t('View your order history.'),
       
'callback' => 'uc_order_history',
       
'callback arguments' => array(arg(1)),
       
'access' => true,
       
'type' => MENU_NORMAL_ITEM,
      );
    }
  }
  return
$items ;
}

?>

However, I find that generating the menu entry this way doesn't make it available for inclusion in the menus at ?q=admin/build/menu, which I was hoping to do.

I'd appreciate input on the most correct way to do this.

In the meantime, here's what I did:

<?php
/**
* provide a path which redirects logged-in users to the actual page,
* and non-logged in users there via the login form
*/
function mymodule_my_orders() {
  global
$user ;
  if (
$user->uid ) {
   
drupal_goto( 'user/' . $user->uid . '/orders' ) ;
  } else {
   
drupal_goto( 'user/login', 'destination=my-orders' ) ;
  }
}

/**
* implement hook_menu()
*/
function mymodule_menu($may_cache) {
  if ( !
$may_cache ) {
    global
$user ;
    if (
$user->uid ) {
     
$items[] = array(
       
'path' => 'my-orders',
       
'title' => t('My Orders'),
       
'description' => t('View your order history.'),
       
'callback' => 'mymodule_my_orders',
       
'access' => true,
       
'type' => MENU_NORMAL_ITEM,
      );
    }
  }
}

?>

Giant Robot - for campaign, charity, ngo & online store solutions - www.giantrobot.co.nz

grobot's picture
Offline
Joined: 04/12/2008
Juice: 289
Re: Adding a "My Orders" link in the menu

You can also do a workflow rule to redirect users after login to "My Orders", but that only works after login. Still, it's not a bad addition (if that's what you want).

Giant Robot - for campaign, charity, ngo & online store solutions - www.giantrobot.co.nz

TR
TR's picture
Offline
Bug FinderFAQ ModeratorGetting busy with the Ubercode.
Joined: 11/05/2007
Juice: 3275
'access' => true, means
'access' => true,

means anybody can access anybody else's orders. Probably not a good idea.

<tr>.
czperry's picture
Offline
Joined: 02/24/2010
Juice: 16
Me project for aliases

Have a look at the Me project. It creates aliases that you can use in your menus i.e. user/me/orders

http://drupal.org/project/me