0

I am writing 2 modules, one dependent on the other and both extend the user profile page. The first one is order_history and the other one order_details. The concept is order_history pulls out a list of all orders and order_details displays only 1 order but with details.

Now the problems are:

  1. I am able to access http://localhost/drupal/user/1/order_history and I get the table. But when I click on the link, I am taken to http://localhost/drupal/user/1/1001.
  2. When I directly put the url http://localhost/drupal/user/1/order_history/1001, I see the order_history table but not the message.

Can't figure out what's wrong with the code. Please point to the right direction.

So here is the code for both:

order_history.module

function order_history_menu(){
    $items = array();
    $items['user/%user/order_history'] = array(
        'title'             =>  'Order History', 
        'page callback'     =>  'drupal_get_form', 
        'page arguments'    =>  array('order_history_form'), 
        'access arguments'  =>  array('access order history'),
        'type'              =>  MENU_LOCAL_TASK,
        );
    return $items;
}

function order_history_form($form) {
    $output_form='<div class="form-wrapper">
<table style="width:100%;">
    <thead>
        <tr>
            <th>Order Number</th>
            <th>Order Date</th>
            <th>Order Status</th>
            <th>Amount</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <a href="1001">1001</a>
            </td>
            <td>2014-04-01</td>
            <td>Shipped by seller</td>
            <td>$468.89</td>
        </tr>
    </tbody>
</table>
</div>';

    $form['order_history'] = array(
                    '#type' => 'markup',
                    '#title' => t('Order History'),
                    '#markup' => drupal_render($output_form),
            );
    return $form;
}

order_details.module :

function order_details_menu(){
    $items = array();
    $items['user/%user/order_history/%order_number'] = array(
        'title'             =>  'Order Details', 
        'page callback'     =>  'order_details', 
        'page arguments'    =>  array('%user','%order_number'), 
        'access arguments'  =>  array('access order details'),
        'type'              =>  MENU_LOCAL_TASK,
        );
    return $items;
}

function order_details($user, $order_number){
    drupal_set_message('Response from order details.');
}
6
  • Where are you rendering the link? I don't see that in your code.
    – Craig
    Commented Apr 11, 2014 at 14:57
  • Do you have a function called order_number_load or order_number_to_arg? (necessary for putting %order_number in the item path). If you don't then you should just be using %. See this page on Dynamic argument replacement.
    – Felix Eve
    Commented Apr 11, 2014 at 15:52
  • Just wondering, why two modules instead of one that handle the orders? Also order/%oid and order/history would look better, but it's just a personal preference i guess
    – Astrayus
    Commented Apr 11, 2014 at 16:39
  • @Craig - I thought drupal_set_message() would auto render.
    – Srihari
    Commented Apr 13, 2014 at 10:59
  • @FelixEve - Thanks for letting me know that. Would add the _load as well as _to_arg hook implementations.
    – Srihari
    Commented Apr 13, 2014 at 11:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.