X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Custom Search Redirects (https://forum.x-cart.com/showthread.php?t=32368)

UPRJon 07-06-2007 04:10 PM

Custom Search Redirects
 
Basically this will allow you to customize where a search word goes on your site.

If someone searches for "Free Ground Shipping", you can redirect them them to a custom page if you wanted.

In /include/search.php:

FIND:

Code:

#
        # Update the session $search_data variable from $posted_data
        #
        if (!empty($posted_data)) {
                $need_advanced_options = false;
                foreach ($posted_data as $k=>$v) {
                        if (!is_array($v) && !is_numeric($v))
                                $posted_data[$k] = stripslashes($v);

                        if (in_array($k, $advanced_options) && $v !== "")
                                $need_advanced_options = true;
                }

                # Update the search statistics
                if ($posted_data["substring"]) {
                        db_query("INSERT INTO $sql_tbl[stats_search] (search, date) VALUES ('".addslashes($posted_data["substring"])."', '".time()."')");
                }


AFTER, ADD:

Code:


$surprise_array = array(
                        array("keyword" => "help me for the love of god",       
                                        "url"        => "home.php"),
                        array("keyword" => "charlie the unicorn",       
                                        "url"        => "pages.php?pageid=5"),
                        array("keyword" => "gift certificate",       
                                        "url"        => "product.php?id=16")        ,
                        array("keyword" => "free shipping",       
                                        "url"        => "pages.php?pageid=5")       
        );
       
        $i=0;
       
        foreach ($surprise_array as $k) {
       
                        if (strtolower($posted_data["substring"]) == $surprise_array[$i]["keyword"]) {
                                $url_go =  $surprise_array[$i]["url"];
                        }
                        $i++;
        }

        if($url_go){
                func_header_location($url_go);
        }


Basically add or change the "keyword" and "url" in the $surprise_array.

Tested in 4.1.7


All times are GMT -8. The time now is 05:44 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.