The order history page calls uc_order_history, which gathers data, throws it through theme('table') and theme('pager'), and returns the result... making it impossible to theme the table differently without using hook_menu_alter to override uc_order_history() itself.

We need a theme_order_history function which takes the collection of history data that is currently gathered in uc_order_history, and then outputs it as a table, so that the output can be changed/rethemed.

If I find the time, I'll make a patch.

Comments

tr’s picture

Version: 6.x-2.0-rc7 » 6.x-2.x-dev

Yes, this is definitely needed.

agileware’s picture

+1 for this

tr’s picture

Category: bug » feature
tr’s picture

Issue tags: +Ubercart theme layer

Tagging

tr’s picture

Status: Active » Closed (won't fix)

This is solved for Ubercart 7.x-3.x because the order history page is now a View that can be easily customized and themed. That change isn't going to be backported to 6.x-2.x.

ericbroder’s picture

Another option is to implement an override of theme_table in template.php and adjust this table there. For example:

/**
 * Theme override for theme_table
...
 */
function mytheme_table($header, $rows, $attributes = array(), $caption = NULL) {

  // Remove "Products" column from "My order history" table
  if ($attributes['class'] == 'uc-order-history') {
    unset($header[3]);
    foreach ($rows as $number => $row) {
      unset($rows[$number][3]);
    }
  }

...
}
drupalfever’s picture

I agree that there is no easy way to theme the order history. But, where there is a will, there always is a way.

One thing I cannot say enough is how useful the "devel" module was for me while I was working on this.
The two things I use the most on the "devel" module are:

1) The "dsm()" function to inspect arrays.
2) The "Execute PHP Code" page located at "http://YOUR_DOMAIN/devel/php"

I am going to say it again, this is not an easy solution. This is just a work around.
Here is how I did it:

1) I used the "devel_ themer" module to figure out the name of the template page that would allow me to theme the content of the order history page.

2) I went to my custom theme folder and made a copy of the "page.tpl.php" file. I named the copy as "page-user-order.tpl.php".

3) Then I figured out the current invoice being viewed by the customer by doing the following:

$order_id = arg(3);

4) With a little bit of SQL magic, I retrieved all the information required from the database.

$query = db_query ("
SELECT uop.*, ua.dst AS url 
FROM {uc_order_products} uop LEFT JOIN {url_alias} ua ON SUBSTR(ua.src, 6, 6) = uop.nid 
WHERE order_id = '%d' ", $order_id);

$products = array();
while ($prod = db_fetch_array($query)) {
  $data = unserialize($prod['data']);
  $prod['data'] = $data;
  $products[] = $prod;
}

5) With the $products array at hand I can recreate the table with the content of the current order. What I need to do now is to remove the list of products that is currently there. I can do that with a little bit of PHP:

//Here I will search for the "DIV" tag that indicates the beginning of the region with 
//the products description. Remember, this may be different on your theme. You can
//figure it out by checking the HTML of the order history page with Firefox's "Firebug".
$pattern = '#\<div class="order-pane abs-left" id="order-pane-products"\>#';

//Here we will split the HTML from the $content variable right where the products listing begins.
$matches = preg_split($pattern, $content);

//I am saving whatever came before the products table on an array that I decided to call "$part".
$part = array();
$part[] = $matches[0];

//Now I am going to split the second half of the first split at the "DIV" tag 
//that comes right after the list of products.
$pattern = '#\<div class="order-pane abs-left" id="order-pane-line_items"\>#';
$matches = preg_split($pattern, $matches[1]);

//I am saving all the HTML that comes after the list of products on my "$part" array.
//Don't forget to put back the "DIV" tag that was removed on the split process.
$part[] = '<div class="order-pane abs-left" id="order-pane-line_items">' . $matches[1];

6) Now you can do a simple loop and generate a table with the order content like so:


//This line is not necessary but is very useful. The "dsm" function will only  
//work if you have the "devel" module enabled on your website.
dsm($products);

$html = '
<div class="order-pane abs-left" id="order-pane-products">
  <table>
    <thead>
      <tr>
        <th>
          Product Description
        </th>
      </tr>
      <tr>
        <th>
          Qty.
        </th>
      </tr>
      <tr>
        <th>
          Price
        </th>
      </tr>
    </thead>
    <tbody>';

$class = 'odd';
foreach ($products as $prdct) {
  $html .= "
      <tr class='{$class}'>
        <td>
          <a href='{$prdct['url']}'>
            {$prdct['title']}
          </a>
        </td>
      </tr>
      <tr>
        <td>
          {$prdct['qty']}&times;
        </td>
      </tr>
      <tr>
        <td>
          ${$prdct['price']}
        </td>
      </tr>";
  
  $class = ($class == 'odd')? 'even': 'odd';
}

$html .= "
    </tbody>
  </table>
</div>";

The above example of how to generate the HTML is overly simplified. You will also have to loop through the attributes array if there are any attributes set for your products.

7) Now, the only thing left to do is to put all the HTML segments back together like so:

$content = $part[0] . $html . $part[1];

I told you it was not an easy solution for this problem. However, it worked for me.

I hope that this little article will help the next Drupal developer looking for answers.

MakeOnlineShop’s picture

Hello,

Still no easy way ?

Thanks.