[Virtuemart] Customize Order List - adding extra column

In this post, I am going explain on how to add an extra column in Virtuemart Administrator Order List page. (Note that, in this example, I'm going to add a new address_1 column).

Note: Please refer to my previous post on "adding search keywords" for the SQL query code for the other fields that you want.

Getting Started.

In /administrator/components/com_virtuemart/html/order.order_list.php

locate this section, around line 27. Then add "address_1" into the line, as below.
//$list .= "first_name, last_name FROM #__{vm}_orders, #__{vm}_order_user_info WHERE ";
// This is the modified line.
$list .= "first_name, last_name, address_1 FROM #__{vm}_orders, #__{vm}_order_user_info WHERE ";


After that, locate this section, as usual and note that "Address_1" is already the added column.
$columns = Array(  "#" => "width=\"20\"", 
     "<input type=\"checkbox\" name=\"toggle\" value=\"\" onclick=\"checkAll(".$checklimit.")\" />" => "width=\"20\"",
     $VM_LANG->_('PHPSHOP_ORDER_LIST_ID') => '',
     $VM_LANG->_('PHPSHOP_ORDER_PRINT_NAME') => '',
     // This is you "address_1" column header,
     'Address_1' => '',
     $VM_LANG->_('PHPSHOP_ORDER_LIST_PRINT_LABEL') => '',
     $VM_LANG->_('PHPSHOP_ORDER_LIST_TRACK') => '',
     $VM_LANG->_('PHPSHOP_ORDER_LIST_VOID_LABEL') => '',
     $VM_LANG->_('PHPSHOP_CHECK_OUT_THANK_YOU_PRINT_VIEW') => '',
     $VM_LANG->_('PHPSHOP_ORDER_LIST_CDATE') => '',
     $VM_LANG->_('PHPSHOP_ORDER_LIST_MDATE') => '',
     $VM_LANG->_('PHPSHOP_ORDER_LIST_STATUS') => '',
     $VM_LANG->_('PHPSHOP_UPDATE') => '',
     $VM_LANG->_('PHPSHOP_ORDER_LIST_TOTAL') => '',
     $VM_LANG->_('E_REMOVE') => "width=\"5%\""
    );
$listObj->writeTableHeader( $columns );

As you can see, those are the column headers for the table, and the last line is the function to print out all the column headers.

Then, you will need to locate this section of code, and add $db->f('address_1'); as below:
$tmp_cell = $db->f('first_name').' '.$db->f('last_name');
 if( $perm->check('admin') && defined('_VM_IS_BACKEND')) {
  $url = $_SERVER['PHP_SELF']."?page=admin.user_form&amp;user_id=". $db->f("user_id");
  $tmp_cell = '<a href="'.$sess->url( $url ).'">'.$tmp_cell.'</a>';
 }
 
 $listObj->addCell( $tmp_cell );

 // This will print "address_1" column, which is placed afer the "Name" column
 $tmp_cell = $db->f('address_1');
 $listObj->addCell( $tmp_cell );

Note: The ordering of the the print cell function (i.e. the $listObj->addCell( $tmp_cell ); ) is important, as you wouldn't want to jumble up the different fields.

Thats all. Hope this help :)

Comments

  1. oh my god u are amazing
    thnx
    can you add the products in this list???

    ReplyDelete
  2. @mezo You can add these line to include the order_item_name/vendor_id in the search:

    $list .= "vendor_id, #__{vm}_order_item.order_item_name, ";

    $list .= "JOIN #__{vm}_order_item ON #__{vm}_orders.order_id=#__{vm}_order_item.order_id WHERE ";


    and locate similar lines to the following, and add these (keyword filter) in between the lines:

    $q .= "OR order_item_name LIKE '%$keyword%' ";
    $q .= "OR order_item_name LIKE '%$keyword%' ";

    Hope it helps.

    Tell me if you find the above explanation is not clear.

    ReplyDelete
  3. can u give me more details please
    thank you for your help

    ReplyDelete
  4. This imformation is a great help. Try to keep your imformation. I and other people need to understand about it. Thank you !

    ReplyDelete
  5. $list  = "SELECT #__{vm}_orders.order_id,order_status, #__{vm}_orders.cdate,#__{vm}_orders.mdate,order_total,order_currency,#__{vm}_orders.user_id, ";
    $list .= "first_name, last_name, vendor_name FROM #__{vm}_vendor, #__{vm}_orders, #__{vm}_order_user_info WHERE ";
    $count = "SELECT count(*) as num_rows FROM #__{vm}_orders, #__{vm}_order_user_info WHERE ";

    BAD TABLE!!!! ALL vendors insert? help my? please
    roooma@ipnet.kiev.ua

    ReplyDelete
  6. I like this direction. My question is how can this be done to show a attribute. For example I have a greeting card website where a customer can choose a writing style for their message to be hand written in the card for them and I would like this style to carry over and be a column in the order list and show up in each order details. Hope that makes sense.

    Kindest Regards,
    Jeremy

    ReplyDelete
  7. Bing Han, Can you help me with the below post? Thank you.

    ReplyDelete
  8. Hey, so sorry for the late reply. Was busy with project deadlines these few days.

    I guess the above guide more or less points you to the direction of adding new fields. So now you just need to display it in the order details page?

    I'll see if I can look into it (hopefully come up with a guide) next week. On a trip this weekend.

    ReplyDelete
  9. Bing,


    Thank you for your help. I just want to display attribute in the Order List that way as my handwriters are going in to check the orders they can see which one is theirs without having to click into the order to see the attribute selection.


    I guess just let me know. my email is jeremy@revolutionwebstudios.com


    Thank you,
    Jeremy

    ReplyDelete
  10. Hi Bing Han Goh,


    My name is anoop, I am customizing the backend of virtuemart 2.06. In the order list we can see Filter Name: Go Reset Order Status: these two fields ,
    I need to add an additional fields to select the order by date . I searched all the files , but didnt found, displayDefaultViewSearch function in the vmview.php page. which page i have to edit if i have to add another filter to it . please reply . anoop@wsdtech.com

    ReplyDelete
  11. I love that you outlined the codes for adding extra column in Virtuemart Customize Order list in such a clear, concise way.

    ReplyDelete
  12. Hello BIng Han Goh,

    tnanks for the information.

    I'd like to add an extra column in Virtuemart Administrator Order List page with the product image. How can I do it?

    Thanks for the help.

    I have already the column, but I can't figure out how to show the image.

    ReplyDelete

Post a Comment

Popular posts from this blog

[Azure Websites PHP] Cross Domain request results in blank response page after Preflight HTTP OPTIONS

[Magento] Create Contact Form with Dynamic Recipient