Search Orders By Ip Address

Any way to search admin orders by ip address. on 3.06 or 4.24



Thanks

John

I have checked the fn_get_orders function and it does not have such an ability

hi John,



Please create the following files with code:


  1. app/addons/my_changes/func.php

```php



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

function fn_my_changes_get_orders($params, $fields, $sortings, &$condition, $join, $group)
{
if (!empty($params['ip_address'])) {
$condition .= db_quote(" AND ?:orders.ip_address LIKE ?l", "%". $params['ip_address'] ."%" );
}

return true;
}
```

2. app/addons/my_changes/init.php```php


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

fn_register_hooks(
'get_orders'
); ```

3. design/backend/templates/addons/my_changes/hooks/orders/advanced_search.pre.tpl

```php


{__("ip_address")}




```

Then install "My changes" addon (if not installed) and clear template cache
Let us know if it helps.

Best regards,
WSA team

If you know the IP address (dot notation) you can do:


$ipint = ip2long($ip_addr]);
$orders = db_get_row("SELECT * FROM ?:orders where ip_address=?i", $ipint);


$orders will contain all the orders that were placed by $ip_addr (I.e. 92.139.32.45).

[quote name='Damir (WSA-team)' timestamp='1435004217' post='219985']

hi John,



Please create the following files with code:


  1. app/addons/my_changes/func.php

```php



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

function fn_my_changes_get_orders($params, $fields, $sortings, &$condition, $join, $group)
{
if (!empty($params['ip_address'])) {
$condition .= db_quote(" AND ?:orders.ip_address LIKE ?l", "%". $params['ip_address'] ."%" );
}

return true;
}
```

2. app/addons/my_changes/init.php```php


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

fn_register_hooks(
'get_orders'
); ```

3. design/backend/templates/addons/my_changes/hooks/orders/advanced_search.pre.tpl

```php


{__("ip_address")}




```

Then install "My changes" addon (if not installed) and clear template cache
Let us know if it helps.

Best regards,
WSA team
[/quote]

Thanks Damir I did the files, created the directories, and cleared template and cache but still nothing Im afraid

John

ip_address is store in order as a long, not a dot-notated-string. So you need to convert the IP address to a long before doing the query and it should be '=' not 'LIKE'

hi John,


[quote]Thanks Damir I did the files, created the directories, and cleared template and cache but still nothing Im afraid[/quote]



Please check the status of 'My changes' addon. It should be 'active'. If this does not help please provide us the temporary FTP access, our specialists can check it.



NOTE: this solution work fine for 4.2.4 version. If you need the same functionality for 3.0.6 please contact us.




[quote]

ip_address is store in order as a long, not a dot-notated-string. So you need to convert the IP address to a long before doing the query and it should be '=' not 'LIKE'

[/quote]

It depends on the search query:

For strict search, sign “=” is used.

For partial match (e.g. all IPs started with “127.”), “LIKE” operator should be used.



Which one you use?



best regards,

WSA team

As far as I can see, the IP addresses are also encoded in some cases. Please check the fn_ip_to_db function

Like is for strings, but ip_address in the cscart_orders table is varbinary(4) and is stored as a long so using any ip-octet notation will fail.

[quote]Like is for strings, but ip_address in the cscart_orders table is varbinary(4) and is stored as a long so using any ip-octet notation will fail. [/quote]



'LIKE' is used for common string types, but type “varbinary” works fine too with 'LIKE' so please check it.



best regards,

WSA team

May work, but bad practice, since by definition a varbinary can contain any binary data and that could be quite difficult to specify in a query. I can loop through a string in php by doing $string[suffix] too (this casts the string to an array), but the proper way is to use $string{suffix} (which notates that it is a string index). The former may work, but the latter is the correct and supported way to do so.



But my main point is that the data is not stored in the ip_address field as an octet (173.245.48.14) but instead as a long integer (I.e. 2918526990)

Hence I'm not sure what you would search for with a LIKE unless you had already converted the ip_address to a long using ip2long() and then searched for some subset of that integer value. But if you know the integer value, why use LIKE?

by default in cs-cart 4.2.4 IP address in “cscart_orders” is stored in format xxx.xxx.xxx.xxx. That is why we offered to use “LIKE”.



best regards,

WSA team

Interesting… The MVE version I have here (4.2.4 - the only 4.2.4 edition I currently have installed here) uses a long integer (actually hex notation). V3 sites used the dot-notation.



So my 4.2.4 and 4.3.x sites use decimal and yours uses dot-notation? I find that a little difficult to believe since it would significantly impact any search to have the same version using two different formats. When I look at the source, it uses fn_ip_to_db() which changes it from whatever format it is in (IPV4 or IPV6) to the relevant hex encoded value of 32bit (IPV4) or 128bit (IPV6). Then for display, it converts it back.