VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: caesarsk on June 15, 2018, 17:31:55 PM

Title: VM search plugin - problem with language special char (ľ,š,č,ť...)
Post by: caesarsk on June 15, 2018, 17:31:55 PM
Hi all,

I have a little problem with the VM search module.

Situation:
- I have product with title "čelenka"
- when my search string is "čelenka", module find him - this is ok
- but when I try "celenka" (č - c), module can not find the product

My question is:
- this is standard situation?
- when no, is problem with language settings? Shop language is slovak, but VM was installed in the EN language (I think)
- it is necessary to modify the search plugin?

thx
Title: Re: VM search plugin - problem with language special char (ľ,š,č,ť...)
Post by: caesarsk on June 17, 2018, 01:15:46 AM
ok, I found solution. (J v3.8.8 + VM v3.2.14)

1. go to /plugins/search/ and duplicate (and rename e.g. virtuemartMod) folder "virtuemart"

2. rename files virtuemart.php and virtuemart.xml to e.g. virtuemartMod.php and virtuemartMod.xml

3. open virtuemartMod.xml and rename:
from
<filename plugin="virtuemart">virtuemart.php</filename>
to
<filename plugin="virtuemartMod">virtuemartMod.php</filename>

4. open virtuemartMod.php rename class:
from
class plgSearchVirtuemart extends JPlugin
to
class plgSearchVirtuemartMod extends JPlugin

5. modily switch function about line 103 like this

Quoteswitch ($phrase) {
         case 'exact':
            $wheres2 = array();
            // product_sku should be exact match
            $text = $db->quote("%$text%", TRUE);
            $wheres2[] = "p.product_sku LIKE $text";
            $wheres2[] = "a.product_name COLLATE utf8_general_ci LIKE $text";
            $wheres2[] = "b.$category_field COLLATE utf8_general_ci LIKE $text";
            if ($search_product_s_description)
               $wheres2[] = "a.product_s_desc COLLATE utf8_general_ci LIKE $text";
            if ($search_product_description)
               $wheres2[] = "a.product_desc COLLATE utf8_general_ci LIKE $text";
            if ($search_customfields)
               $wheres2[] = "(cf.customfield_value LIKE $text $customfield_ids_condition)";
            $where = '(' . implode (') OR (', $wheres2) . ')';
            break;
         case 'all':
         case 'any':
         default:
            $words = explode (' ', $text);
            $wheres = array();
            foreach ($words as $word) {
               $wheres2 = array();
               // product_sku should be exact match
          $word = $db->quote("%$word%", TRUE);
               $wheres2[] = "p.product_sku LIKE $word";               
               $wheres2[] = "a.product_name COLLATE utf8_general_ci LIKE $word";
               $wheres2[] = "b.$category_field COLLATE utf8_general_ci LIKE $word";
               if ($search_product_s_description)
                  $wheres2[] = "a.product_s_desc COLLATE utf8_general_ci LIKE $word";
               if ($search_product_description)
                  $wheres2[] = "a.product_desc COLLATE utf8_general_ci LIKE $word";
               if ($search_customfields)
                  $wheres2[] = "(cf.customfield_value LIKE $word $customfield_ids_condition)";

               $wheres[] = implode (' OR ', $wheres2);
            }
            $where = '(' . implode (($phrase == 'all' ? ') AND (' : ') OR ('), $wheres) . ')';
            break;
      }

@milbo, it would not be bad to add COLLATE option to VM search.
Title: Re: VM search plugin - problem with language special char (ľ,š,č,ť...)
Post by: Milbo on June 18, 2018, 20:12:13 PM
yes, quite easy todo, just some work. The param needs to be added to the xml and needs language keys and translation.