Site and Admin - search by Product Code? v4.0.2

Is it possible to modify Search to include product codes? I'd Product Names and Product Codes to be searchable. Primary interest would be for the public store but admin would nice as well.



Appears code modification was required in v3 and older. Can't find any data for v4 - [url=“CS-Cart Documentation — CS-Cart 4.15.x documentation”]CS-Cart Documentation — CS-Cart 4.15.x documentation

Hi Grafis,


  1. enable My Changes addon
  2. add to [color=#ff0000]app/addons/my_changes/init.php[/color]```php

<?php
if (!defined('BOOTSTRAP')) { die('Access denied'); }
fn_register_hooks(
'additional_fields_in_search'
);
```
3. add to [color=#ff0000]app/addons/my_changes/func.php[/color]```php
<?php
if (!defined('BOOTSTRAP')) { die('Access denied'); }
function fn_my_changes_additional_fields_in_search($params, $fields, $sortings, $condition, $join, $sorting, $group_by, &$tmp, $piece, $having){
$tmp .= db_quote(" OR products.product_code LIKE ?l", '%' . $piece . '%');
} ```
4. clear cache from backend [color=#ff0000]?cc&ctpl[/color]
5. have fun
6. repeat step 5 :D

---
Valentin
[color=#808080][size=2]part of hungryweb.net[/size][/color]

Hello Vali,



I tried to do this on version 4.1.2 and it`s not working ([color=#000000]Hook fn_my_changes_additional_fields_in_search is not callable ). [/color]

[color=#000000]Can you help me fix that? [/color]



[color=#000000]Thank You![/color]

Hi,

I have update the tutorial :D

#replace```php


function fn_hw_additional_fields_in_search

#with```php
<br />
function fn_my_changes_additional_fields_in_search<br />

```<br />
<br />
---<br />
Valentin<br />
[color=#808080][size=2]part of hungryweb.net[/size][/color]

Hi,



I have no error now, but it is not find my product when i search by product code.

Our work around for this was to put the product code in the “Search words:” for all of our items. Now when we do a search it always pulls up.

This is a good ideea, but I allready have a few thousands products …

Also today i implement to a customer and works perfect ;)


function fn_my_changes_additional_fields_in_search($params, $fields, $sortings, $condition, $join, $sorting, $group_by, &$tmp, $piece, $having){ 
```<br />
<br />
[color=#ff0000]&[/color][color=#ff0000]$tmp[/color] make the difference, please try<br />
<br />
---<br />
Valentin<br />
[color=#808080][size=2]part of hungryweb.net[/size][/color]

Alternative if you don't mind core modifications…



/apps/functions/fn.catalog.php



Find:


$tmp = db_quote("(descr1.search_words LIKE ?l)", '%' . $piece . '%'); // check search words

if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?l", '%' . $piece . '%');
}




Replace with:


$tmp = db_quote("(descr1.search_words LIKE ?l)", '%' . $piece . '%'); // check search words

if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR descr1.product LIKE ?l", '%' . $piece . '%');
}
if ($params['pname'] == 'Y') {
$tmp .= db_quote(" OR products.product_code LIKE ?l", '%' . $piece . '%');
}

A free add-on is available for download, please follow [url=“Free Addon: Search Products By Product Code - Third-Party Add-ons - CS-Cart Community Forums”]Free Addon: Search Products By Product Code - Third-Party Add-ons - CS-Cart Community Forums





Valentin

[color=#808080][size=2]part of hungryweb.net[/size][/color]