Zen Cart Logo
Forums / General Questions / How do I add an order field to the admin orders page?

How do I add an order field to the admin orders page?

Views: 693

Results 1 to 5 of 5
4 Jun 2015, 8:37 AM
#1
izar74 avatar

izar74

Zen Follower

Join Date:
Mar 2009
Location:
Italy
Posts:
155
Plugin Contributions:
0

How do I add an order field to the admin orders page?

Hi,
I'm trying to add a field to the order table and to show It in the admin order page.
I added the field ORDER_FLAG to the database order table as TINYINT(1) (it should only have two values 1 and 0)
The simpliest way i thought is to add some line to the /admin/orders.php

For sure i need the heading:

around line 845 after the <td class="dataTableHeadingContent" align="right"><?php echo TABLE_HEADING_STATUS; ?></td>

I added:

<td class="dataTableHeadingContent" align="center"><?php echo TABLE_ORDER_HEADING_FLAG; ?></td>

I also added the define for the TABLE_ORDER_HEADING_FLAG

Around line 969 after <td class="dataTableContent" align="right"><?php echo $orders->fields['orders_status_name']; ?></td>

I would have something like this:

<td class="dataTableContent" align="center"><?php echo ($orders->fields['ORDER_FLAG'] == 1 ? 'x' : ''); ?></td>

The point is to show a "X" after the "Status" column on the admin order page for the orders that have the field ORDER_FLAG set to 1.

The code part where the field is modified and populated is already done and working, my problem is only to shown it in the admin order page.

The edit of /admin/order.php work but it shown nothing, for sure miss a call, any help would be appreciated :smile:

Zencart ver 1.54
PHP 5.3.3
Mysql 5.1.73

4 Jun 2015, 1:40 PM
#2
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How do I add an order field to the admin orders page?

Couple things: typically (by convention) variables that are fully capitalized are constants. Does not mean that causes a problem here. Next convention (at least with ZC) is to populate fields with names that are all in lower case. ('order_flag' instead of 'ORDER_FLAG')

The part that is more than likely the issue is retrieving the new field from the database to be used as desired. So whatever function is being called to assign data to $orders or a separate function/query yet to be written needs to retrieve your new field. This is primarily addressed in the includes/classes/order.php file. But you could do an independent query to obtain your data from the orders table(s).

4 Jun 2015, 5:36 PM
#3
izar74 avatar

izar74

Zen Follower

Join Date:
Mar 2009
Location:
Italy
Posts:
155
Plugin Contributions:
0

Re: How do I add an order field to the admin orders page?

mc12345678:

Couple things: typically (by convention) variables that are fully capitalized are constants. Does not mean that causes a problem here. Next convention (at least with ZC) is to populate fields with names that are all in lower case. ('order_flag' instead of 'ORDER_FLAG')

Thank You Mc, you are always kind :smile:.

Sorry for the capitalized name, really it was only meant to point out the name of the variable and the field... in my database and in the file it is in lowercase.

The part that is more than likely the issue is retrieving the new field from the database to be used as desired. So whatever function is being called to assign data to $orders or a separate function/query yet to be written needs to retrieve your new field. This is primarily addressed in the includes/classes/order.php file. But you could do an independent query to obtain your data from the orders table(s).

Hmmm that's the point, just to be sure, is the includes/classes/order.php or is the admin/includes/classes/order.php the right file? Or both :ohmy:

Thanks again

(Strange i did't find any informations on something like this... there are a lot of informations on how to add and retrive field for customers or products but not for the orders... just a thought)

4 Jun 2015, 5:59 PM
#4
izar74 avatar

izar74

Zen Follower

Join Date:
Mar 2009
Location:
Italy
Posts:
155
Plugin Contributions:
0

Re: How do I add an order field to the admin orders page?

I did IT!! :P

First you need not to edit any ../class/order.php file, simply find the lines in /admin/orders.php:

// eof: search orders or orders_products
$new_fields = ", o.customers_company, o.customers_email_address, o.customers_street_address, o.delivery_company, o.delivery_name, o.delivery_street_address, o.billing_company, o.billing_name, o.billing_street_address, o.payment_module_code, o.shipping_module_code, o.ip_address ";

and add the field you need to be searched at the end, for me it is:

// eof: search orders or orders_products
    $new_fields = ", o.customers_company, o.customers_email_address, o.customers_street_address, o.delivery_company, o.delivery_name, o.delivery_street_address, o.billing_company, o.billing_name, o.billing_street_address, o.payment_module_code, o.shipping_module_code, o.ip_address, o.ORDER_FLAG ";

:D

p.s. I know i know.. the convention!!! sorry but i can't edit the previous post so i keep it uppercase to be consistent :lol:

4 Jun 2015, 6:53 PM
#5
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: How do I add an order field to the admin orders page?

izar74:

Thank You Mc, you are always kind :smile:.

Sorry for the capitalized name, really it was only meant to point out the name of the variable and the field... in my database and in the file it is in lowercase.

Hmmm that's the point, just to be sure, is the includes/classes/order.php or is the admin/includes/classes/order.php the right file? Or both :ohmy:

Thanks again

(Strange i did't find any informations on something like this... there are a lot of informations on how to add and retrive field for customers or products but not for the orders... just a thought)

Thought the second use might have been for emphasis, but wasn't sure. (At least others coming here now know.)

Sorry about that, I've had the store side on my mind. Yes as you discovered, admin side of things for how you were trying to use your new lowercase (:) ) field.

Glad you figured it out!