PDA

View Full Version : I need to sort out the customer orders by one particular attribute



dan1234
12-12-2011, 12:22 PM
I added an attribute to each product, "Is this a gift?", selections are Yes and No. I have made up a duplicate Customers/orders.php page in admin, calling it gift_list.php. My idea is to have this page show only the orders where the attribute Yes was selected. I have added the code

$gift_query = tep_db_query("select orders_id, products_options_values from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " where orders_id = '" . (int)$oID . "'");

and edited the code


if (isset($oInfo) && is_object($oInfo) && ($orders['orders_id'] == $oInfo->orders_id)) {
echo '

to read

if (isset($oInfo) && is_object($oInfo) && ($orders['orders_id'] == $oInfo->orders_id) && $gift_query['products_options_values'] == 'Yes') {
echo '

It did not work at all. I'm not sure I added the db query in the right place and if the addition to the above line makes any sense at all. How can I get this page to just display those orders that have selected the Yes attribute?

Thanks for your help,

Dan

Luxoria
12-15-2011, 11:18 PM
in orders.php (or whatever file you want)

find...


$orders_query_raw = "select o.orders_id, o.customers_name, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, o.fedex_tracking, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s where o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and s.orders_status_id = '" . (int)$status . "' and ot.class = 'ot_total' " . (!is_null($search_query)?$search_query:''). " order by o.orders_id DESC";

and change it to...


$orders_query_raw = "select g.orders_id, g.products_options_values, g.products_options, o.orders_id, o.customers_name, o.payment_method, o.date_purchased, o.last_modified, o.currency, o.currency_value, s.orders_status_name, o.fedex_tracking, ot.text as order_total from " . TABLE_ORDERS . " o left join " . TABLE_ORDERS_TOTAL . " ot on (o.orders_id = ot.orders_id), " . TABLE_ORDERS_STATUS . " s, " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " g where g.orders_id = o.orders_id and g.products_options_values = 'Yes' and g.products_options = 'Is this a gift?' and o.orders_status = s.orders_status_id and s.language_id = '" . (int)$languages_id . "' and ot.class = 'ot_total' " . (!is_null($search_query)?$search_query:''). " order by o.orders_id DESC";


This manually filters out all the orders that do not have products with a 'products_options_values' of 'Yes'.

You will need to change 'Is this a gift?' in the code to the name of the 'products_options' you are targeting. (but according to your provided data this should work straight out)

I confirmed this code to work with my database using 'products_options' and 'products_options_values' that are found in my database.

Also, if you want to use this filter along with either the Search by ID or status filter functionality, you must modify the queries in the same IF THEN chain. (around line 609 and 615)

Good luck, have fun. =)

dan1234
12-16-2011, 02:41 PM
It works perfect! Thanks so much!

Dan