Mod: Search Orders By Zip/postcode

By default when using search in cs-cart admin you can search for orders by order_id, email and cname (customer name).

We needed to add ability to search by post code (zip code) as well.

Here is what you need to do to achieve this:



add hooks to:

app/addons/my_changes/init.php

```php

if (!defined('BOOTSTRAP')) { die('Access denied'); }

fn_register_hooks(
'get_orders',
'create_pages_condition_pre'
);
```

add functions to:
[b]app/addons/my_changes/func.php[/b]
```php
if (!defined('BOOTSTRAP')) { die('Access denied'); }

function fn_my_changes_create_pages_condition_pre(&$params, $lang_code){
if (!empty($params['q'])) {
$params['postcode'] = $params['q'];
// if you would like to add customer's 'company' name to the search query uncomment line below:
//$params['company'] = $params['q'];
}
}

function fn_my_changes_get_orders($params, $fields, $sortings, &$condition, $join, $group){

if (!empty($params['postcode'])) {
$condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (0 OR (?:orders.s_zipcode LIKE ?l OR ?:orders.b_zipcode LIKE ?l))", "%".trim($params['postcode'])."%", "%".trim($params['postcode'])."%");
}
// if you would like to add customer's 'company' name to the search query uncomment lines below:

// if (!empty($params['company'])) {
// $condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (?:orders.company LIKE ?l)", "%".trim($params['company'])."%");
// }

}
```

modify search schema:
[b]app/addons/my_changes/schemas/search/schema.post.php[/b]
```php
if (AREA == 'A') {
$scheme['orders']['action_link'] .= '&postcode=%search%';
// if you would like to add customer's 'company' to the search query uncomment line below:
// $scheme['orders']['action_link'] .= '&company=%search%';
}
return $scheme;
```

And that should be it!
Now you can type part or full postcode (zipcode) into main search and it should find all orders with given postcode in billing or shipping address.

I hope this helps someone.

thanks raff, using 4.2.2, did all of this and nothings shows up, also cleared the cache.

[quote name='hinger' timestamp='1412339957' post='193335']

thanks raff, using 4.2.2, did all of this and nothings shows up, also cleared the cache.

[/quote]



It might be daft suggestion, but try disabling the my_changes addon, than enabling it again.

cs-cart needs to register hooks, this might force it to do so.

I also run 4.2.2

Did that and same result.

Screen Shot 2014-10-03 at 15.24.42.png

[quote name='hinger' timestamp='1412346636' post='193348']

Did that and same result.

[/quote]



This mod will not give you any additional search fields in advanced search.

It is designed to utilise the search field on the main toolbar (the one next to 'Quick Menu')



you could however add specific search fields (post code or company) to the side menu by hooking into side search template



for example:

create hook tpl file in:

design/backend/templates/addons/my_changes/hooks/orders/search_form.tpl

```php


{__("zip_postal_code")}


```

this mod is designed to modify behaviour of the main search field (next to 'Quick Menu')

as per picture in attachment

search.jpg

got it, works great and this will save us a lot of time when dealing with customers by phone.



thanks again for making it available to the community.

How can I add the search to include the staff notes, is this possible?



Thank you

Joe

[quote name='gasngrills' timestamp='1422063262' post='203327']

How can I add the search to include the staff notes, is this possible?



Thank you

Joe

[/quote]



I figured it out , thank you so much for this great addon.



Joe

This mod is no longer working after upgrade to 4.3.1, is there any modifications that need to be done to make it work again?



Thank you

Joe

[quote name='gasngrills' timestamp='1432050213' post='214979']

This mod is no longer working after upgrade to 4.3.1, is there any modifications that need to be done to make it work again?



Thank you

Joe

[/quote]



I have manged to get this working again on 4.3.1



I changed this : app/addons/my_changes/init.php

```php

if (!defined('BOOTSTRAP')) { die('Access denied'); }
fn_register_hooks(
'get_orders',
'create_pages_condition_pre'
);
```

To:
```php
if (!defined('BOOTSTRAP')) { die('Access denied'); }
fn_register_hooks(
'get_orders',
'create_orders_condition_pre'
);
```

And Changed This :[b]app/addons/my_changes/func.php[/b]
```php
if (!defined('BOOTSTRAP')) { die('Access denied'); }
function fn_my_changes_create_pages_condition_pre(&$params, $lang_code){
if (!empty($params['q'])) {
$params['postcode'] = $params['q'];
// if you would like to add customer's 'company' name to the search query uncomment line below:
//$params['company'] = $params['q'];
}
}
function fn_my_changes_get_orders($params, $fields, $sortings, &$condition, $join, $group){
if (!empty($params['postcode'])) {
$condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (0 OR (?:orders.s_zipcode LIKE ?l OR ?:orders.b_zipcode LIKE ?l))", "%".trim($params['postcode'])."%", "%".trim($params['postcode'])."%");
}
// if you would like to add customer's 'company' name to the search query uncomment lines below:
// if (!empty($params['company'])) {
// $condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (?:orders.company LIKE ?l)", "%".trim($params['company'])."%");
// }
}
```

To:
```php
if (!defined('BOOTSTRAP')) { die('Access denied'); }
function fn_my_changes_create_orders_condition_pre(&$params, $lang_code){
if (!empty($params['q'])) {
$params['postcode'] = $params['q'];
// if you would like to add customer's 'company' name to the search query uncomment line below:
//$params['company'] = $params['q'];
}
}
function fn_my_changes_get_orders($params, $fields, $sortings, &$condition, $join, $group){
if (!empty($params['postcode'])) {
$condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (0 OR (?:orders.s_zipcode LIKE ?l OR ?:orders.b_zipcode LIKE ?l))", "%".trim($params['postcode'])."%", "%".trim($params['postcode'])."%");
}
// if you would like to add customer's 'company' name to the search query uncomment lines below:
// if (!empty($params['company'])) {
// $condition .= db_quote(" " . (isset($params["compact"]) ? "OR" : "AND") . " (?:orders.company LIKE ?l)", "%".trim($params['company'])."%");
// }
}
```

Changed This: [b]app/addons/my_changes/schemas/search/schema.post.php[/b]
```php
if (AREA == 'A') {
$scheme['orders']['action_link'] .= '&postcode=%search%';
// if you would like to add customer's 'company' to the search query uncomment line below:
// $scheme['orders']['action_link'] .= '&company=%search%';
}
return $scheme;
```

To:
```php
if (AREA == 'A') {
$schema['orders']['action_link'] .= '&postcode=%search%';
// if you would like to add customer's 'company' to the search query uncomment line below:
// $schema['orders']['action_link'] .= '&company=%search%';
}
return $schema;
```

Works with no issue