Neuigkeiten
  • Die modified eCommerce Shopsoftware ist kostenlos, aber nicht umsonst.
    Spenden
  • Damit wir die modified eCommerce Shopsoftware auch zukünftig kostenlos anbieten können:
    Spenden
  • Thema: MODUL: jQuery Autocomplete (ähnlich Ajax Search Suggest, IntelliSearch)

    karsta.de

    • Experte
    • Beiträge: 3.156
    Ich danke euch beiden.
    Habe die autocomplete.php noch mal bearbeitet und endlich funktionierts. Habe allerdings noch ein Problem mit den Umlauten. Die Kategorien werden korrekt angezeigt, aber die Produkte nicht.
    Da der Artikelstamm neue, also in utf8 und alte Artikel im iso Format in der Datenbank hat, ist mir nicht klar wie man das jetzt umsetzt. ISO wandelt er korrekt mittels utf8_encode um. Aktualisiere ich jetzt einen Artikel wird der natürlich in utf8 gespeichert und da werden nun die Umlaute zerhackt dargestellt. Nehme ich utf8_encode komplett aus dem Script funktioniert die Suche für Artikel mit Umlauten nicht mehr.

    Hier nun die angepasst autocomplete.php mit der zumindest schon mal die richtigen Kategorie und Produktvorschläge angezeigt werden.

    Code: PHP  [Auswählen]
    <?php
    /* -----------------------------------------------------------------------------------------
       jQuery Autocomplete

       Changelog:
       2011-04-18: Soundex/Koelner search in category-names by TechWay
       2011-04-19: NEW LINK DEFINITION by web28 www.rpa-com.de
       2011-04-19: products_short_description added by TechWay
       2011-04-20: NEW option SHOW_PRODUCT_IMAGE and function productImage, products/categoriesLink by web28 www.rpa-com.de
       2011-04-21: noimage.gif if no products_image, cleaned short_description (no html-tags), products_price added by TechWay
       2011-04-22: NEW functions handling, NEW option SHOW_PRODUCT_PRICE  by web28 www.rpa-com.de

       Released under the GNU General Public License
       ---------------------------------------------------------------------------------------*/


    //The settings you can change:
    $searchConfig = array(
            'USE_SUMA_LINKS' => false,                                      // Would you like SUMA Links? Possible values: true / false. Standard: true
            'SEARCH_IN_PRODUCTS_NAME' => true,                              // Would you like to search in the product names? Possible values: true / false. Standard: true
            'SEARCH_IN_PRODUCTS_KEYWORDS' => true,                  // Would you like to search in the product keywords? Possible values: true / false. Standard: true
            'SEARCH_IN_PRODUCTS_DESCRIPTION' => true,               // Would you like to search in the product description? Possible values: true / false. Standard: true
            'SEARCH_IN_PRODUCTS_SHORT_DESCRIPTION' => true, // Would you like to search in the product short description? Possible values: true / false. Standard: true
            'SEARCH_IN_CATEGORY_NAMES' => true,                             // Would you like to search in the category names? Possible values: true / false. Standard: true
            'SEARCH_IN_CATEGORY_DESCRIPTION' => true,               // Would you like to search in the category names? Possible values: true / false. Standard: true
            'SEARCH_IN_PRODUCTS_MODEL' => false,                    // Would you like to search in the products model? Possible values: true / false. Standard: false
            'SEARCH_IN_PRODUCTS_EAN' => false,                              // Would you like to search in the products ean? Possible values: true / false. Standard: false
            'SHOW_PRODUCT_IMAGE' => true,                                   // Would you like to show products_image? Possible values: true / false. Standard: false
            'SHOW_PRODUCT_PRICE' => false,                                  // Would you like to show products_price? Possible values: true / false. Standard: false
            'SHOW_PRODUCT_DESC' => true,                                    // Would you like to show products_short_description? Possible values: true / false. Standard: false
            'PRODUCT_DESC_MAX_LENGTH' => 100,                               // Max length of products_short_description. Possible values: INTEGER, Standard: 100
            'SUBSTRING_COUNT' => 50,                                                // Length of results in the list (signs). Possible values: INT from 1 to 256. Standard: 40
            'SUBSTRING_FINALIZER' => ' ...',                                // Signs after a word is cutted in the suggestlist. Possible values: Any String. Standard: ' ...'
            'PRODUCT_RESULT_COUNT' => 10,                                   // How many found products should be displayed? Possible values: INT from 1 to 256. Standard: 10
            'CATEGORY_RESULT_COUNT' => 5,                                   // How many found categories should be displayed? Possible values: INT from 1 to 256. Standard: 5
            'SHOW_CATEGORY_WITH_PRODUCT' => true,                   // Would you like to show the category name in the product result like "category => productname" Possible values: true / false. Standard: false
            'GROUP_RESULTS' => true,                                                // Would you like to group the results by the category_name? Possible values: true / false. Standard: true
            'SEVERAL_KEYWORDS_AND' => true,                                 // Search for several keywords with AND-logic. Possible values: true / false. Standard: true
            'SOUNDEX_SEARCH_PRODUCT_NAMES' => true,                 // Would you like to search for keyword with soundex-method (sounds like) Possible values: true / false. Standard: false
            'SOUNDEX_SEARCH_CATEGORY_NAMES' => true,                // Would you like to search for keyword with soundex-method (sounds like) Possible values: true / false. Standard: false
            'KOELNER_PHONETIK_PRODUCT_NAMES' => true,               // Would you like to search for keyword with koelner-method (sounds like) Possible values: true / false. Standard: false
            'KOELNER_PHONETIK_CATEGORY_NAMES' => true,              // Would you like to search for keyword with koelner-method (sounds like) Possible values: true / false. Standard: false
            'FILTER_LINKED_PRODUCTS' => true                                // Would you like to show the linked products only one time? Possible values: true / false. Standard: true
            );

    //Settings END

    chdir('../../');
    include('includes/application_top.php');

    $languages_id = $_SESSION['languages_id'];

    $coded_term = utf8_encode(rawurldecode($_GET['term']));  //de- and encoding http get string to work with utf-8 enabled shop 2014-10-10 by hard-one

    $ent_keyword = trim(htmlentities($coded_term)); //exchanged $_GET('term') with variable 2014-10-10 by hard-one
    if (!strlen($ent_keyword)) {
            unset($searchConfig);
            return json_encode(array());
    }
    $ent_keyword = ($ent_keyword != $coded_term) ? addslashes($ent_keyword) : false; //exchanged $_GET('term') 2014-10-10 by hard-one

    $mysqli = new mysqli($server=DB_SERVER, $username=DB_SERVER_USERNAME, $password=DB_SERVER_PASSWORD, $database=DB_DATABASE);
    //$keyword = mysqli_real_escape_string($coded_term); //2014-10-10 by hard-one $keyword = mysql_real_escape_string(urldecode($_GET['term']));
    $keyword = mysqli_real_escape_string($mysqli, $coded_term);

    $keyword = str_replace(array('%', '_'), array('\%', '\_'), $keyword);
    $ent_keyword = str_replace(array('%', '_'), array('\%', '\_'), $ent_keyword);

    //initialize array for results
    $return_arr = array();
    $num_rows_cat=0;

    $str_group_by = "";
    if ($searchConfig['FILTER_LINKED_PRODUCTS'] == 1) {
            $str_group_by = " GROUP BY p.products_id ";
    }

    //BOF - Search in category_name ################################################
    if ($searchConfig['SEARCH_IN_CATEGORY_NAMES'] == 1 || $searchConfig['SEARCH_IN_CATEGORY_DESCRIPTION'] == 1){
            $where_str_cat = " AND ( ";
            $firstCatItem = true;

            if ($searchConfig['SEARCH_IN_CATEGORY_NAMES'] == 1 ) {
                    !$firstCatItem ? $where_str_cat.=" OR " : false;
                    if($searchConfig['SEVERAL_KEYWORDS_AND'] == 1) {
                            $temp_ary = explode(' ', $keyword);
                            $temp_ary2 = array();
                            for ( $i = 0; $i < count($temp_ary); ++$i )
                            {
                                    $temp_ary2[] = " cd.categories_name LIKE '%" . $temp_ary[$i] . "%' ";
                            }
                            if ( count($temp_ary2) > 0 )
                            {
                                    $where_str_cat.= ' ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                            }

                            if ($ent_keyword)
                            {
                                    $temp_ary = explode(' ', $ent_keyword);
                                    $temp_ary2 = array();
                                    for ( $i = 0; $i < count($temp_ary); ++$i )
                                    {
                                            $temp_ary2[] = " cd.categories_name LIKE '%" . $temp_ary[$i] . "%' ";
                                    }
                                    if ( count($temp_ary2) > 0 )
                                    {
                                            $where_str_cat.= ' OR ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                                    }
                            }

                    } else {
                            $where_str_cat .= "cd.categories_name LIKE '%" . $keyword . "%' ";
                            $where_str_cat .= ($ent_keyword) ? "OR cd.categories_name LIKE ('%".$ent_keyword."%') " : '';
                    }
                    $firstCatItem=false;
            }

            if ($searchConfig['SEARCH_IN_CATEGORY_DESCRIPTION'] == 1 ) {
                    !$firstCatItem ? $where_str_cat.=" OR " : false;
                    if($searchConfig['SEVERAL_KEYWORDS_AND'] == 1) {
                            $temp_ary = explode(' ', $keyword);
                            $temp_ary2 = array();
                            for ( $i = 0; $i < count($temp_ary); ++$i )
                            {
                                    $temp_ary2[] = " cd.categories_description LIKE '%" . $temp_ary[$i] . "%' ";
                            }
                            if ( count($temp_ary2) > 0 )
                            {
                                    $where_str_cat.= ' ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                            }

                            if ($ent_keyword)
                            {
                                    $temp_ary = explode(' ', $ent_keyword);
                                    $temp_ary2 = array();
                                    for ( $i = 0; $i < count($temp_ary); ++$i )
                                    {
                                            $temp_ary2[] = " cd.categories_description LIKE '%" . $temp_ary[$i] . "%' ";
                                    }
                                    if ( count($temp_ary2) > 0 )
                                    {
                                            $where_str_cat.= ' OR ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                                    }
                            }

                    } else {
                            $where_str_cat .= "cd.categories_name LIKE '%" . $keyword . "%' ";
                            $where_str_cat .= ($ent_keyword) ? "OR cd.categories_name LIKE ('%".$ent_keyword."%') " : '';
                    }
                    $firstCatItem=false;
            }

            $where_str_cat .= " ) ";

      //Build SQL-Query for category-search
      $group_check = ''; //DokuMan - 2010-02-28 - set undefined variable group_check
      if (GROUP_CHECK == 'true') {
        $group_check = " AND p.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
        $group_check_c = " AND c.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
        } else {
          unset ($group_check);
          unset ($group_check_c);
      }  
      //BOF - web28 - 2011-04-22 - NEW SQL QUERY and change $where_str to %s
      $sql_str_cat = "SELECT cd.categories_id,
                             cd.categories_name
                        FROM "
    .TABLE_CATEGORIES." c
                  INNER JOIN "
    .TABLE_CATEGORIES_DESCRIPTION." cd
                          ON c.categories_id = cd.categories_id
                       WHERE cd.language_id = '"
    .(int)$languages_id."'
                       "
    .$group_check_c."
                         AND c.categories_status = '1'
                             %s
                    ORDER BY cd.categories_name
                       LIMIT 0,"
    .$searchConfig['CATEGORY_RESULT_COUNT'];
      //EOF - web28 - 2011-04-22 - NEW SQL QUERY and change $where_str to %s

            $fetch_cat = xtc_db_query(sprintf($sql_str_cat,$where_str_cat)); //web28 - 2011-04-22 - using sprintf
            $num_rows_cat = mysqli_num_rows($fetch_cat);

      while ($row_cat = xtc_db_fetch_array($fetch_cat)) {  
        getCatReturnArray($row_cat,TEXT_AUTOCOMPLETE_CATEGORIES); //web28 - 2011-04-22 - New function handling
      }

            //Soundex Category Names
            if ($num_rows_cat == 0 && $searchConfig['SOUNDEX_SEARCH_CATEGORY_NAMES'] == 1) {

                    $where_str_cat = " AND ( soundex_match('".$keyword."', cd.categories_name, ' ') = 1 ) ";    

                    $fetch_cat = xtc_db_query(sprintf($sql_str_cat,$where_str_cat)); //web28 - 2011-04-22 - using sprintf
                    $num_rows_cat = mysqli_num_rows($fetch_cat);

        while ($row_cat = xtc_db_fetch_array($fetch_cat)) {
          getCatReturnArray($row_cat,TEXT_AUTOCOMPLETE_SOUNDEX); //web28 - 2011-04-22 - New function handling
        }
            }

            //Koelner Phonetik category names
            if ($num_rows_cat == 0 && $searchConfig['KOELNER_PHONETIK_CATEGORY_NAMES'] == 1) {

                    $where_str_cat = " AND ( koelner_match('".$keyword."', cd.categories_name, ' ') = 1 ) ";    

                    $fetch_cat = xtc_db_query(sprintf($sql_str_cat,$where_str_cat)); //web28 - 2011-04-22 - using sprintf
                    $num_rows_cat = mysqli_num_rows($fetch_cat);

        while ($row_cat = xtc_db_fetch_array($fetch_cat)) {
          getCatReturnArray($row_cat,TEXT_AUTOCOMPLETE_SOUNDEX); //web28 - 2011-04-22 - New function handling
        }
            }
    }
    //EOF - Search in category_name ################################################


    //BOF - Search for products ####################################################
    $where_str = " AND ( ";
    $firstItem = true;

    //Search in products_name
    if($searchConfig['SEARCH_IN_PRODUCTS_NAME'] == 1) {
            !$firstItem ? $where_str.=" OR " : false;
            if($searchConfig['SEVERAL_KEYWORDS_AND'] == 1) {
                    $temp_ary = explode(' ', $keyword);
                    $temp_ary2 = array();
                    for ( $i = 0; $i < count($temp_ary); ++$i )
                    {
                            $temp_ary2[] = " pd.products_name LIKE '%" . $temp_ary[$i] . "%' ";
                    }
                    if ( count($temp_ary2) > 0 )
                    {
                            $where_str.= ' ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                    }

                    if ($ent_keyword)
                    {
                            $temp_ary = explode(' ', $ent_keyword);
                            $temp_ary2 = array();
                            for ( $i = 0; $i < count($temp_ary); ++$i )
                            {
                                    $temp_ary2[] = " pd.products_name LIKE '%" . $temp_ary[$i] . "%' ";
                            }
                            if ( count($temp_ary2) > 0 )
                            {
                                    $where_str.= ' OR ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                            }
                    }

            } else {
                    $where_str .= "pd.products_name LIKE '%" . $keyword . "%' ";
                    $where_str .= ($ent_keyword) ? "OR pd.products_name LIKE ('%".$ent_keyword."%') " : '';
            }
            $firstItem=false;
    }

    //Search in products_keywords
    if($searchConfig['SEARCH_IN_PRODUCTS_KEYWORDS'] == 1) {
            !$firstItem ? $where_str.=" OR " : false;
            if($searchConfig['SEVERAL_KEYWORDS_AND'] == 1) {
                    $temp_ary = explode(' ', $keyword);
                    $temp_ary2 = array();
                    for ( $i = 0; $i < count($temp_ary); ++$i )
                    {
                            $temp_ary2[] = " pd.products_keywords LIKE '%" . $temp_ary[$i] . "%' ";
                    }
                    if ( count($temp_ary2) > 0 )
                    {
                            $where_str.= ' ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                    }

                    if ($ent_keyword)
                    {
                            $temp_ary = explode(' ', $ent_keyword);
                            $temp_ary2 = array();
                            for ( $i = 0; $i < count($temp_ary); ++$i )
                            {
                                    $temp_ary2[] = " pd.products_keywords LIKE '%" . $temp_ary[$i] . "%' ";
                            }
                            if ( count($temp_ary2) > 0 )
                            {
                                    $where_str.= ' OR ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                            }
                    }

            } else {
                    $where_str .= "OR pd.products_keywords LIKE '%" . $keyword . "%' ";
                    $where_str .= ($ent_keyword) ? "OR pd.products_keywords LIKE ('%".$ent_keyword."%') " : '';
            }
            $firstItem=false;
    }

    //Search in products_description
    if ($searchConfig['SEARCH_IN_PRODUCTS_DESCRIPTION'] == 1) {
            !$firstItem ? $where_str.=" OR " : false;
            if($searchConfig['SEVERAL_KEYWORDS_AND'] == 1) {
                    $temp_ary = explode(' ', $keyword);
                    $temp_ary2 = array();
                    for ( $i = 0; $i < count($temp_ary); ++$i )
                    {
                            $temp_ary2[] = " pd.products_description LIKE '%" . $temp_ary[$i] . "%' ";
                    }
                    if ( count($temp_ary2) > 0 )
                    {
                            $where_str.= ' ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                    }


                    if ($ent_keyword)
                    {
                            $temp_ary = explode(' ', $ent_keyword);
                            $temp_ary2 = array();
                            for ( $i = 0; $i < count($temp_ary); ++$i )
                            {
                                    $temp_ary2[] = " pd.products_description LIKE '%" . $temp_ary[$i] . "%' ";
                            }
                            if ( count($temp_ary2) > 0 )
                            {
                                    $where_str.= ' OR ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                            }
                    }

            } else {
                    $where_str .= "OR pd.products_description LIKE '%" . $keyword . "%' ";
                    $where_str .= ($ent_keyword) ? "OR pd.products_description LIKE ('%".$ent_keyword."%') " : '';
            }
            $firstItem=false;
    }

    //Search in products_short_description
    if ($searchConfig['SEARCH_IN_PRODUCTS_SHORT_DESCRIPTION'] == 1) {
            !$firstItem ? $where_str.=" OR " : false;
            if($searchConfig['SEVERAL_KEYWORDS_AND'] == 1) {
                    $temp_ary = explode(' ', $keyword);
                    $temp_ary2 = array();
                    for ( $i = 0; $i < count($temp_ary); ++$i )
                    {
                            $temp_ary2[] = " pd.products_short_description LIKE '%" . $temp_ary[$i] . "%' ";
                    }
                    if ( count($temp_ary2) > 0 )
                    {
                            $where_str.= ' ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                    }

                    if ($ent_keyword)
                    {
                            $temp_ary = explode(' ', $ent_keyword);
                            $temp_ary2 = array();
                            for ( $i = 0; $i < count($temp_ary); ++$i )
                            {
                                    $temp_ary2[] = " pd.products_short_description LIKE '%" . $temp_ary[$i] . "%' ";
                            }
                            if ( count($temp_ary2) > 0 )
                            {
                                    $where_str.= ' OR ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                            }
                    }

            } else {
                    $where_str .= "OR pd.products_short_description LIKE '%" . $keyword . "%' ";
                    $where_str .= ($ent_keyword) ? "OR pd.products_short_description LIKE ('%".$ent_keyword."%') " : '';
            }
            $firstItem=false;
    }

    //Search in products_model
    if ($searchConfig['SEARCH_IN_PRODUCTS_MODEL'] == 1) {
            !$firstItem ? $where_str.=" OR " : false;
            if($searchConfig['SEVERAL_KEYWORDS_AND'] == 1) {
                    $temp_ary = explode(' ', $keyword);
                    $temp_ary2 = array();
                    for ( $i = 0; $i < count($temp_ary); ++$i )
                    {
                            $temp_ary2[] = " p.products_model LIKE '%" . $temp_ary[$i] . "%' ";
                    }
                    if ( count($temp_ary2) > 0 )
                    {
                            $where_str.= ' ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                    }

                    if ($ent_keyword)
                    {
                            $temp_ary = explode(' ', $ent_keyword);
                            $temp_ary2 = array();
                            for ( $i = 0; $i < count($temp_ary); ++$i )
                            {
                                    $temp_ary2[] = " p.products_model LIKE '%" . $temp_ary[$i] . "%' ";
                            }
                            if ( count($temp_ary2) > 0 )
                            {
                                    $where_str.= ' OR ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                            }
                    }

            } else {
                    $where_str .= "OR p.products_model LIKE '%" . $keyword . "%' ";
                    $where_str .= ($ent_keyword) ? "OR p.products_model LIKE ('%".$ent_keyword."%') " : '';
            }
            $firstItem=false;
    }

    //Search in products_ean
    if ($searchConfig['SEARCH_IN_PRODUCTS_EAN'] == 1) {
            !$firstItem ? $where_str.=" OR " : false;
            if($searchConfig['SEVERAL_KEYWORDS_AND'] == 1) {
                    $temp_ary = explode(' ', $keyword);
                    $temp_ary2 = array();
                    for ( $i = 0; $i < count($temp_ary); ++$i )
                    {
                            $temp_ary2[] = " p.products_ean LIKE '%" . $temp_ary[$i] . "%' ";
                    }
                    if ( count($temp_ary2) > 0 )
                    {
                            $where_str.= ' ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                    }

                    if ($ent_keyword)
                    {
                            $temp_ary = explode(' ', $ent_keyword);
                            $temp_ary2 = array();
                            for ( $i = 0; $i < count($temp_ary); ++$i )
                            {
                                    $temp_ary2[] = " p.products_ean LIKE '%" . $temp_ary[$i] . "%' ";
                            }
                            if ( count($temp_ary2) > 0 )
                            {
                                    $where_str.= ' OR ( ' . implode(' AND ', $temp_ary2) . ' ) ';
                            }
                    }

            } else {
                    $where_str .= "OR p.products_ean LIKE '%" . $keyword . "%' ";
                    $where_str .= ($ent_keyword) ? "OR p.products_ean LIKE ('%".$ent_keyword."%') " : '';
            }
            $firstItem=false;
    }


    $where_str.=" ) ";

    //fsk18 lock
            if ($_SESSION['customers_status']['customers_fsk18_display'] == '0') {
                    $fsk_lock = " AND p.products_fsk18 != '1' ";
              } else {
                      unset ($fsk_lock);
              }

    //group check
            if (GROUP_CHECK == 'true') {
                    $group_check = " AND p.group_permission_".$_SESSION['customers_status']['customers_status_id']."=1 ";
              } else {
                      unset ($group_check);
              }

    //Build SQL-Query for products-search
    //BOF web28 - 2011-04-22 - change $where_str to %s
        $sql_str = "SELECT p.products_id,
                                    p.products_model,
                                   -- p.products_ean,
                                                                    p.products_tax_class_id,
                                    p.products_price,
                                    p.products_image,
                                    pd.products_name,
                                    pd.products_short_description,
                                    pd.products_description,
                                    pd.products_keywords,
                                                                    p2c.categories_id,
                                                                    c.categories_status,
                                                                    cd.categories_name
                               FROM "
    .TABLE_PRODUCTS." p
                               JOIN "
    .TABLE_PRODUCTS_DESCRIPTION." pd
                                    ON p.products_id = pd.products_id
                                       AND pd.language_id = "
    .(int)$languages_id."
                                       AND pd.products_name != ''
                                              LEFT JOIN "
    . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = pd.products_id
                                              LEFT JOIN "
    . TABLE_CATEGORIES . " c ON c.categories_id = p2c.categories_id
                                              LEFT JOIN "
    . TABLE_CATEGORIES_DESCRIPTION . " cd
                                                               ON c.categories_id = cd.categories_id
                                                               AND cd.language_id = "
    .(int)$languages_id."
                                              WHERE p.products_status = '1'
                                                                    AND c.categories_status = '1'"

                                                                    .$fsk_lock.$group_check."%s".$str_group_by."
                                             ORDER BY cd.categories_name ASC, pd.products_name ASC
                                             LIMIT 0,"
    .$searchConfig['PRODUCT_RESULT_COUNT'];
      //EOF web28 - 2011-04-22 - change $where_str to %s   

    $fetch = xtc_db_query(sprintf($sql_str,$where_str)); //web28 - 2011-04-22 - using sprintf
    $num_rows = mysqli_num_rows($fetch);
    if ($num_rows > 0)
    {
      while ($row = xtc_db_fetch_array($fetch)) {
        getProdReturnArray($row,false); //web28 - 2011-04-22 - New function handling -> true: use $text_soundex
      }
    }

    //nothing found? try soundex
    if ($num_rows == 0 && $num_rows_cat == 0 && $searchConfig['SOUNDEX_SEARCH_PRODUCT_NAMES'] == 1){

            $where_str = " AND ( soundex_match('".$keyword."', products_name, ' ') = 1 ) ";

            $fetch = xtc_db_query(sprintf($sql_str,$where_str)); //web28 - 2011-04-22 - using sprintf
            $num_rows = mysqli_num_rows($fetch);
     
      while ($row = xtc_db_fetch_array($fetch)) {
        getProdReturnArray($row,true); //web28 - 2011-04-22 - New function handling -> true: use $text_soundex
      }
    }

    //nothing found? try koelner phonetik
    if ($num_rows == 0 && $num_rows_cat == 0 && $searchConfig['KOELNER_PHONETIK_PRODUCT_NAMES'] == 1){

            $where_str = " AND ( koelner_match('".$keyword."', products_name, ' ') = 1 ) ";

            $fetch = xtc_db_query(sprintf($sql_str,$where_str)); //web28 - 2011-04-22 - using sprintf
            $num_rows = mysqli_num_rows($fetch);  
     
      while ($row = xtc_db_fetch_array($fetch)) {
        getProdReturnArray($row,true); //web28 - 2011-04-22 - New function handling -> true: use $text_soundex
      }  
    }
    //EOF - Search for products ####################################################

    unset($searchConfig);
    print json_encode($return_arr);


    //BOF - functions ####################################################

    /**
      * change the global $return_arr -> add categorie entries
      * @param Array $row_cat
      * @param String $text_autocomplete
      * @global $searchConfig
      * @global $text_autocomplete
      * @change global $return_arr
    */

    function getCatReturnArray($row_cat,$text_autocomplete) {
      global $searchConfig, $return_arr;
     
      $str_cat = $row_cat['categories_name'];
      //if string is too long then substr
      if (strlen($str_cat)>$searchConfig['SUBSTRING_COUNT']){
        $str_cat = substr($str_cat, 0, $searchConfig['SUBSTRING_COUNT']) . $searchConfig['SUBSTRING_FINALIZER'];
      }

      $category='';
      if ($searchConfig['GROUP_RESULTS'] == 1){
        $category=$text_autocomplete;
      }

      //append to results array
      //BOF - web28 - 2011-04-18 - NEW categories_link_link
      $return_arr[] = array(
                            'label'     => $str_cat,
                            'link'      => categoriesLink($row_cat['categories_id']),
                            'value'     => $row_cat['categories_id'],
                            'category'  => $category,
                            'desc'      => ''
                           );
      //EOF - web28 - 2011-04-18 - NEW categories_link_link
    }

    /**
      * change the global $return_arr -< add product entries
      * @param Array $row
      * @param Boolean $soundex
      * @global $searchConfig
      * @global $return_arr
      * @global $xtPrice
      * @change global $return_arr
    */

    function getProdReturnArray($row,$text_soundex) {
      global $searchConfig, $return_arr, $xtPrice;
     
      if($searchConfig['SHOW_CATEGORY_WITH_PRODUCT'] == 1) {
        $str = utf8_encode($row['categories_name'] .' => '. $row['products_name']);
      } else {
        $str = utf8_encode($row['products_name']);
      }

      //if string is too long then substr
      if (strlen($str)>$searchConfig['SUBSTRING_COUNT']){
        $str = substr($str, 0, $searchConfig['SUBSTRING_COUNT']) . $searchConfig['SUBSTRING_FINALIZER'];
      }

      $category='';
      if (!$text_soundex) {
        if ($searchConfig['GROUP_RESULTS'] == 1 && !is_null($row['categories_name']) && strlen($row['categories_name']) > 0){
          $category=utf8_encode($row['categories_name']);
        }
      } else {
        if ($searchConfig['GROUP_RESULTS'] == 1){
          $category=utf8_encode(TEXT_AUTOCOMPLETE_SOUNDEX);
        }
      }

      $desc = '';
      if ($searchConfig['SHOW_PRODUCT_DESC'] == 1) {
        $desc = truncateStr($row['products_short_description']);
      }

      $products_price = '';
      if ($searchConfig['SHOW_PRODUCT_PRICE'] == 1) {
        $products_price = $xtPrice->xtcGetPrice($row['products_id'], $format = true, 1, $row['products_tax_class_id'], $row['products_price'], 1); //functionxtcGetPrice in class xtcprice
      }

      //append to results array
      //BOF - web28 - 2011-04-18 - NEW products_link
      $return_arr[] = array(
                            'label'     => $str,
                            'link'      => productLink($row['products_id'], $row['products_name']),
                            'value'     => $row['products_id'],
                            'category'  => $category,
                            'image'     => productImage($row['products_image']),
                            'desc'      => $desc,
                            'price'     => $products_price
                           );
      //BOF - web28 - 2011-04-18 - NEW products_link  
    }

    /**
      * returns a truncate string by defined lenght $searchConfig['PRODUCT_DESC_MAX_LENGTH']
      * @param String $str
      * @global $searchConfig
      * @return String  
    */

    function truncateStr($str) {
      global $searchConfig;
      $str = utf8_encode(strip_tags($str));
      if (strlen($str)>$searchConfig['PRODUCT_DESC_MAX_LENGTH']) {
        $str = substr($str, 0, $searchConfig['PRODUCT_DESC_MAX_LENGTH']) . $searchConfig['SUBSTRING_FINALIZER'];
      }
      return $str;
    }

    /**
      * returns the categories link created by xtc_href_link
      * @param Integer $categories_id
      * @global $searchConfig
      * @return String categories_link
    */

    function categoriesLink($categories_id){
      global $searchConfig;
      $categories_link = xtc_href_link(FILENAME_DEFAULT, 'cPath='.xtc_get_category_path($categories_id), 'NONSSL', false, $searchConfig['USE_SUMA_LINKS']);
      $categories_link = str_replace('&amp;', '&',$categories_link);
      return $categories_link;
    }

    /**
      * returns the product image using the function productImage in class product
      * @param String $image
      * @global $searchConfig
      * @global $product
      * @return String productImage
    */

    function productImage($image){
      global $searchConfig, $product;
      if (!$searchConfig['SHOW_PRODUCT_IMAGE']) {
        return '';
      }
      return $product->productImage($image, 'thumbnail'); //function productImage in class product
    }

    /**
      * returns the product link created by xtc_href_link
      * @param Integer $products_id
      * @param String $products_name
      * @global $searchConfig
      * @return String productLink
    */

    function productLink($products_id, $products_name){
      global $searchConfig;
      $products_link = xtc_href_link(FILENAME_PRODUCT_INFO, xtc_product_link($products_id, $products_name), 'NONSSL', false, $searchConfig['USE_SUMA_LINKS']);
      $products_link = str_replace('&amp;', '&',$products_link);
      return $products_link;
    }

    //BOF - functions ####################################################
    ?>
     

    Wenn das jetzt noch mit den Umlauten korrekt angezeigt wird, ist das eine knaller Suchfunktion. Finde ich. Vorallem schnell.

    BG kgd

    awids

    • Experte
    • Beiträge: 3.803
    • Geschlecht:
    Dann sind wir der Sache ja schon ein ganzes Stückchen näher gekommen. :-) Freut mich, dass ich ein bisschen was dazu beitragen durfte.  :thumbs: Die letzten Fehler lassen sich irgendwie bestimmt auch noch ausbügeln. ;-)

    web28

    • modified Team
    • Beiträge: 9.404
    Das Modul wurde 2011 veröffentlich und dementsprechend ist der Code.

    Vor allem sollten grundsätzlich die DB Funktionen von Modified Shop benutzt werden. Vor allem die DB Verbindung.

    Auch das ist Käse:

    utf8_encode
    htmlentities

    Dafür gibt es shopeigene Funktionen (inc/html_encoding.php)

    Gruss Web28

    @kgd
    Zitat
    Da der Artikelstamm neue, also in utf8 und alte Artikel im iso Format in der Datenbank hat, ist mir nicht klar wie man das jetzt umsetzt. ISO wandelt er korrekt mittels utf8_encode um. Aktualisiere ich jetzt einen Artikel wird der natürlich in utf8 gespeichert und da werden nun die Umlaute zerhackt dargestellt. Nehme ich utf8_encode komplett aus dem Script funktioniert die Suche für Artikel mit Umlauten nicht mehr.

    Entweder alles UTF-8 oder gar nichts!
    Eine 2.0 DB lässt sich auch einfach in UTF-8 umwandeln:
    1. Im ISO Shop die DB exportieren - Ohne Zeichenkodierung 'COLLATE' und 'DEFAULT CHARSET'
    2. Diesen Dump per Notepad ++ in UTF-8 ohne BOM konvertieren.
    3. In der configure.php bei DB_SERVER_CHARSET utf8 eintragen.
    4. Den konvertierten Dump wieder importieren.

    Natürlich alles erst einmal bei einem Testshop ausprobieren.

    Falls es in der DB tatsächlich ISO und UTF-8 gemischt gibt, funktioniert das natürlich auch nicht.
    Bei Artikeln und Kategorien kann man das aber mit meinem Modul EasyPopulate beheben, da hier jeder Datensatz einzeln beim Import bei Bedarf in das richtige Format konvertiert wird.
    Beispiel: Shop ist UFT-8
    Datensatz ISO -> wird in UTF-8 konvertiert
    Datensatz UTF 8 -> keine Konvertierung

    karsta.de

    • Experte
    • Beiträge: 3.156
    So aber nun. Habe es hinbekommen.

    Das mit den Umlauten hat sich genau an dieser Stelle aufgehagen:
    $str = utf8_encode($row['categories_name'] .' => '. $row['products_name']);
    Hatte es auch ohne utf8_encode getestet. Immer das selbe Umlautgehäcksel.
    Bis ich mal ' => ' ersetzt habe gegen einen Bindestrich.

    Man, da muß man aber erst auch mal drauf kommen.

    Hier nun die passende autocomplete.php. Endlich funktionierts. Alle Umlaute werden jetzt korrekt angezeigt. Jetzt kann es gerne auch von anderen getestet werden.

    BG kgd

    edit: nochmal das komplette Paket mit rangehängt

    michaelEberl

    • Mitglied
    • Beiträge: 111
    Hallo funktioniert das auch bei 2.0.2.2 und orginal Responsive Template
    Danke

    karsta.de

    • Experte
    • Beiträge: 3.156
    Es funktioniert vorallem nur unter (bitte in der configure.php nachschauen):
    'DB_MYSQL_TYPE', 'mysqli'
    'DB_SERVER_CHARSET', 'utf8'

    Du meinst sicher das orginal modified eCommerce Responsive Template 2.0.2.2.
    Das habe ich jetzt hier gerade nicht am Start, aber ich habe das ganze unter V2.0.2.2 in meinem eigenen Responsiven Template eingebaut und hat funktioniert. Denke das sollte auch in deinem Template kein Problem sein. Vorallem vorher immer alles sichern. Einbau erfolgt auf eigene Gefahr. Haftung wird nicht übernommen. Die vorhandene Template-Dateien nicht einfach überspielen, sondern vergleichen. (Template-Dateien sind aus dem Standard-Template "tpl_modified" V2.0.2.1. Habe jetzt nicht verglichen, was sich zum Standard-Template V2.0.2.2. geändert hat.)

    Was ich feststellen mußte, die Funktionen aus den sql-Dateien lassen sich nicht einfach so bei Hosteurope über phpMyAdmin übertragen (scheinbar liegt es an der sehr alten phpMyAdmin-Version, Provider kontaktieren könnte helfen). Bei all-inkl und auch bei strato gab es keine Probleme.

    BG kgd

    @web28
    Zitat
    Da der Artikelstamm neue, also in utf8 und alte Artikel im iso Format in der Datenbank hat..

    Hatte mich wahrscheinlich hier falsch ausgedrückt. Die Tabellen sind natürlich alle utf8.

    web28

    • modified Team
    • Beiträge: 9.404
    @kgd

    Zitat
    Hatte mich wahrscheinlich hier falsch ausgedrückt. Die Tabellen sind natürlich alle utf8.

    Das ist egal, wichtig ist das keine Zeichen gemischt enthalten sind.

    @alle

    Das Modul ist sehr alt und sollte nicht benutzt werden! Es müsste komplett überarbeitet werden.

    Im Modified Template tpl_modified und den Responsive Kauftemplates ist ja auch bereits eine Autokompletefunktion bei der Suche implementiert.

    Gruss Web28

    lullifatz

    • Fördermitglied
    • Beiträge: 474
    @web28

    Kannst Du begründen, warum es nicht benutzt werden sollte? Die Suche funktioniert so aber sehr gut.

    karsta.de

    • Experte
    • Beiträge: 3.156
    @web28

    Zitat
    Das ist egal, wichtig ist das keine Zeichen gemischt enthalten sind.

    Dann muß ich jetzt aber die Frage stellen, warum selbst bei einer kompletten Neuinstallation von euch weiterhin alte HTML-Codes verwendet werden. Hier 3 Beispiele:
    shop_configuration -> "einem sp&auml;teren Zeitpunkt"
    content_manager -> "Gesch&auml;ftsf&uuml;hrer:"
    content_manager -> "Mit &bdquo;Mein Schnellkauf&ldquo; k&ouml;nnen Sie Ihre Bestellung"

    Mehr möchte ich jetzt hier nicht zusammentragen.

    Zitat
    Im Modified Template tpl_modified und den Responsive Kauftemplates ist ja auch bereits eine Autokompletefunktion bei der Suche implementiert.

    Das wurde hier auch schon besprochen und ich will auch gar nicht eure Arbeit schlecht machen, aber nach verschiedenen Tests kann die mitgelieferte Autokompletefunktion leider bei der Schnelligkeit für die Anzeige von Suchergebnisse nicht mithalten im Vergleich zu der hier im Modul verwendeten Autocompletefunktion.
    Ansonsten hätte ich mich damit gar nicht weiter aufgehalten und hätte meine Zeit gerne auch mit pay-TV vergeudet.

    BG kgd

    hpzeller

    • Experte
    • Beiträge: 4.129
    • Geschlecht:
    [...]
    Was ich feststellen mußte, die Funktionen aus den sql-Dateien lassen sich nicht einfach so bei Hosteurope über phpMyAdmin übertragen (scheinbar liegt es an der sehr alten phpMyAdmin-Version, Provider kontaktieren könnte helfen). Bei all-inkl und auch bei strato gab es keine Probleme.
    [...]

    Adminer ist eine gute Alternative zu phpMyAdmin, das Programm besteht aus nur einem PHP-Skript welches man einfach ins Webroot des Webservers hochlädt und im Browser aufruft.
    https://www.adminer.org

    Gruss
    Hanspeter

    lohkaes1

    • Schreiberling
    • Beiträge: 460
    @kgd: Danke das du meine "quick & dirty-Lösung" bearbeitet und in eine aktuelle Form gebracht hast  :thumbs: Ich werde das nun die Tage mal in meinem Testshop einbauen und Testen.
    Das Suchmodul ist meiner Meinung nach, was die Geschwindigkeit angeht, aktuell unschlagbar. Wäre doch toll, wenn dieses Modul als Standard in einer zukünftigen Version des Shops vorhanden wäre.

    karsta.de

    • Experte
    • Beiträge: 3.156
    Hier nochmal neu zusammengepackt mit den dazugehörigen Sprachdateien und mit Preisanzeige (da fehlte noch was).

    BG kgd

    @hpzeller
    Danke. Super Sache.

    karsta.de

    • Experte
    • Beiträge: 3.156
    Beim Liveeinsatz gibt es leider noch ein Problem bei eingeschalteten suchmaschinenfreundlichen URLs.
    Suchergebnisse werden dann nur angezeigt, wenn man entweden von der Startseite oder aus der ersten Kategorieebene sucht.

    BG kgd

    lohkaes1

    • Schreiberling
    • Beiträge: 460
    Hallo kgd,

    schau dir hierzu in meiner "quick & dirty-Lösung" die general_bottom.js.php an bzw. vergleich diese mal mit deiner Version. Ich hatte genau das selbe Problem, das nur die Ergebnisse auf der Startseite und der ersten Kategorie angezeigt wurden.

    Viele Grüße

    karsta.de

    • Experte
    • Beiträge: 3.156
    Danke lohkaes1.
    Du verwendest zwar ein abgewandeltes jquery-searchbox.js. Habe es jetzt aber genauso gemacht wie du, dass ich den Inhalt der jquery-searchbox.js direkt in die general_bottom.js.php eingefügt habe und nun funktionierts.

    BG kgd
    1 Antworten
    2710 Aufrufe
    10. April 2012, 01:32:40 von h-h-h
    2 Antworten
    3256 Aufrufe
    12. April 2012, 09:29:29 von werresal
    2 Antworten
    2698 Aufrufe
    29. Mai 2017, 11:36:33 von monnecke
    18 Antworten
    13154 Aufrufe
    21. Dezember 2010, 11:45:08 von plasticman