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)
-   -   Include search by SKU into basic search in v4 (https://forum.x-cart.com/showthread.php?t=8664)

finestshops 07-28-2004 07:26 PM

Include search by SKU into basic search in v4
 
Hi there,

v4 has some nice features and some not-finished business. Why would x-men include search by SKU/product code in advanced search when this is one of the main search fields people are looking for rpoducts in a lot of industries (auto, computers and etc? Here is the simple mod to search by sku from the main search box:

search.php

change:

Code:

                if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["extra_fields"])) {

to

Code:

                if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["by_productcode"]) && empty($data["extra_fields"])) {

after

Code:

                if (!empty($data["by_fulldescr"]))
                        $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$data["substring"]."%'";


add

Code:

                if (!empty($data["by_productcode"]))
                        $condition[] = "$sql_tbl[products].productcode LIKE '%".$data["substring"]."%'";


skin1/customer/search.tpl

after

Code:

<INPUT type="hidden" name="posted_data[by_fulldescr]" value="Y">     

add

Code:

<INPUT type="hidden" name="posted_data[by_productcode]" value="Y">     

skin1/customer/main/search_result.tpl

after

Code:

<TD width="5"><INPUT type="checkbox" name="posted_data[by_fulldescr]"{if $search_prefilled eq "" or $search_prefilled.by_fulldescr} checked{/if}></TD><TD nowrap>{$lng.lbl_det_description}</TD>

add

Code:

<TD width="5"><INPUT type="checkbox" name="posted_data[by_productcode]"{if $search_prefilled eq "" or $search_prefilled.by_productcode} checked{/if}></TD><TD nowrap>{$lng.lbl_sku}</TD>

Enjoy :wink:

nhraracer241 09-02-2004 09:25 AM

Anyone used this on version 3.5._?

finestshops 09-02-2004 09:41 AM

Quote:

Originally Posted by nhraracer241
Anyone used this on version 3.5._?


It's completely different in v3.5. I believe there is a solution on this forum
to do the same in v3.5.

Check: http://forum.x-cart.com/viewtopic.php?t=5971

nhraracer241 09-02-2004 10:01 AM

Thanks. I found a fix for this that Boomer had posted. Works great!

sonichart 11-06-2004 08:58 PM

Is it possible to have TWO boxes on the main page? Search ProdID and Search SKU ??

mffowler 11-11-2004 06:06 AM

I don't seem to find search.php in /customer? It is in the root directory and /includes, but different than this example.

Can you point me in the right direction, so that SKU can come up in the search and advanced?

Thanks,

Mike

QVS 11-29-2004 05:11 PM

thanks for the mod :) worked perfectly 8)

QVS 11-29-2004 05:14 PM

Quote:

Originally Posted by mffowler
I don't seem to find search.php in /customer? It is in the root directory and /includes, but different than this example.

Can you point me in the right direction, so that SKU can come up in the search and advanced?

Thanks,

Mike


yeh use the one in includes ;)

sstillwell@aerostich.com 12-03-2004 09:01 AM

This is a great mod!!!!

Xcart should take note and realize this should be standard operating procedure.

The mod does lack one thing. It will not bring up "variant skus" When using product variants, those skus don't work. No fear, I have an adjustment for the original poster.

include/search.php
After:
Code:

if (!empty($data["by_fulldescr"]))
        $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$data["substring"]."%'";

Add:
Code:

                if (!empty($data["by_productcode"])){
        $condition[] = "$sql_tbl[products].productcode LIKE '%".$data["substring"]."%'";
        if(!empty($active_modules['Product_Options'])) {
                $condition[] = "$sql_tbl[variants].productcode LIKE '%".$data["substring"]."%'";
        }
      }


And all is peaceful in Xcart land once again ;)

PhilJ 12-03-2004 10:25 AM

Fantastic mod, thank you =D>

roblen 12-24-2004 07:29 AM

This works
 
I have been using this mod with great success. I found that if user searches for sku in advanced search no result is found. could advance search use diff. page?

mffowler 01-12-2005 06:20 PM

Search Variants in 4.0.10 Code
 
This is a great mod. I just changed the code to work with 4.0.10. include/search.php now finds variants in a search. Can someone check this to see if it's correct? It does work for me:

include/search.php

find
Code:

      if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["extra_fields"])) {
change to:
Code:

      if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["by_productcode"]) && empty($data["extra_fields"])) {
find
Code:

if (!empty($data["by_fulldescr"])) {
                        if($current_area == 'C' || $current_area == 'P') {
                                $condition[] = "IF($sql_tbl[products_lng].full_descr IS NOT NULL AND $sql_tbl[products_lng].full_descr != '', $sql_tbl[products_lng].full_descr, $sql_tbl[products].fulldescr) LIKE '%".$data["substring"]."%'";
                        } else {
                                $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$data["substring"]."%'";
                        }
                }

change to:
Code:

if (!empty($data["by_fulldescr"])) {
                        if($current_area == 'C' || $current_area == 'P') {
                                $condition[] = "IF($sql_tbl[products_lng].full_descr IS NOT NULL AND $sql_tbl[products_lng].full_descr != '', $sql_tbl[products_lng].full_descr, $sql_tbl[products].fulldescr) LIKE '%".$data["substring"]."%'";
                        if (!empty($data["by_productcode"])){
                        $condition[] = "$sql_tbl[products].productcode LIKE '%".$data["substring"]."%'";
                if(!empty($active_modules['Product_Options'])) {
                    $condition[] = "$sql_tbl[variants].productcode LIKE '%".$data["substring"]."%'";
                }
              }
                        } else {
                                $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$data["substring"]."%'";
                        }
                }


I don't know PHP and wouldn't even call myself a developer. Just a lowly store owner who wants a "search" that works. Can anyone out there tell me if this is correct or what should be modified? It works fine for me and finds variants in a search, but it was trial and error as the original and subsequent code on this post weren't compatible w/ 4.0.10 - categories didn't show up in search (admin).

If you use this, be sure to backup - I only said it works for me, but maybe it could be checked by someone?

Thanks,

Mike

SkullHead 04-26-2005 12:01 PM

mffowler


I typed in the numbers of the sku but not the letters "sku" and it worked great! :D

ReubenJLau 05-09-2005 12:57 PM

Great mod! works for me! (see version below)

Billgray 05-12-2005 09:39 AM

Tried and failed to do this.
 
I am one of those who would rather buy a mod. I not a programmer and dont want to be, I run a business and I am short on time, can anyone recommend a mod that searches by sku, I have 20000 products and on our website xcart 4.13 and the search is crap.

Recommendations please.

I think this cart is great and simple. Got 20,000 products and 7,000 cats and only being using it for 4 days.

MOD IN SEARCH PLEASE. Or if someone wants to write one even better let me know the cost.

Bill Gray

shan 05-13-2005 06:36 AM

Re: Tried and failed to do this.
 
Quote:

Originally Posted by Billgray
I am one of those who would rather buy a mod. I not a programmer and dont want to be, I run a business and I am short on time, can anyone recommend a mod that searches by sku, I have 20000 products and on our website xcart 4.13 and the search is crap.

Recommendations please.

I think this cart is great and simple. Got 20,000 products and 7,000 cats and only being using it for 4 days.

MOD IN SEARCH PLEASE. Or if someone wants to write one even better let me know the cost.

Bill Gray


The notes here will help you do this or if you need it done for you then hire someone to go under the hood and do the coding

dannyrus 09-19-2005 04:14 PM

Great Mod, took 5 minutes if that... Thanks alot for posting it!!

Mr Bob 11-01-2005 03:51 PM

I implemented the mod, as well as the changes in the replies (to work for all SKUs, including variants), and it doesn't show any results for any product SKUs.

I am running the version is my sig.

Mr Bob 11-05-2005 04:00 PM

Seems like all you have to do is add the input box to the search form.

Code:

<INPUT type="hidden" name="posted_data[by_productcode]" value="Y" />

chyldofsun 12-12-2005 11:25 AM

Re: Include search by SKU into basic search in v4
 
[quote="27stars"]Hi there,

v4 has some nice features and some not-finished business. Why would x-men include search by SKU/product code in advanced search when this is one of the main search fields people are looking for rpoducts in a lot of industries (auto, computers and etc? Here is the simple mod to search by sku from the main search box:

search.php

change:

Code:

                if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["extra_fields"])) {

to

Code:

                if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["by_productcode"]) && empty($data["extra_fields"])) {


I have version 4.0.17 and the search.php code is different. Is ther an update to this mod?

Here is my code:

#
# $Id: search.php,v 1.2.2.3 2005/01/14 12:07:30 max Exp $
#

require "./auth.php";
define("GET_ALL_CATEGORIES", true);
require $xcart_dir."/include/categories.php";

if($active_modules["Manufacturers"])
include $xcart_dir."/modules/Manufacturers/customer_manufacturers.php";

$tmp=strstr($QUERY_STRING, "$XCART_SESSION_NAME=");
if (!empty($tmp))
$QUERY_STRING=ereg_replace("$XCART_SESSION_NAME=([0-9a-zA-Z]*)", "", $QUERY_STRING);

if(!empty($active_modules['SnS_connector']) && $REQUEST_METHOD == 'POST') {
if($simple_search == 'Y') {
func_generate_sns_action("SiteSearch");
} else {
func_generate_sns_action("AdvancedSearch");
}
}

x_session_register("search_data");
$search_data["products"]["forsale"] = "Y";
include $xcart_dir."/include/search.php";

if (!empty($QUERY_STRING)) {
$location[] = array(func_get_langvar_by_name("lbl_search_results "), "");
$smarty->assign("main","search");
}
else {
$location[] = array(func_get_langvar_by_name("lbl_advanced_searc h"), "");
$smarty->assign("main","advanced_search");
}

# Assign the current location line
$smarty->assign("location", $location);

func_display("customer/home.tpl",$smarty);
?>


Thanks!

bdg 01-11-2006 12:29 PM

Quote:

Originally Posted by sstillwell@aerostich.com
This is a great mod!!!!

Xcart should take note and realize this should be standard operating procedure.

The mod does lack one thing. It will not bring up "variant skus" When using product variants, those skus don't work. No fear, I have an adjustment for the original poster.

include/search.php
After:
Code:

if (!empty($data["by_fulldescr"]))
        $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$data["substring"]."%'";

Add:
Code:

                if (!empty($data["by_productcode"])){
        $condition[] = "$sql_tbl[products].productcode LIKE '%".$data["substring"]."%'";
        if(!empty($active_modules['Product_Options'])) {
                $condition[] = "$sql_tbl[variants].productcode LIKE '%".$data["substring"]."%'";
        }
      }


And all is peaceful in Xcart land once again ;)


Nice work! I've tried your version as well as the original up top but I can't seem to find any difference in functionality? Clue?

davidsaldana 01-15-2006 08:42 PM

Anybody get this working for 4.016. The code is different than the original post.

vulcan-works 01-16-2006 11:42 AM

For people using 4.0.16 and higher this works for me

In /include/search.php
Add:
Code:

if (!empty($data["by_productcode"])){
        $condition[] = "$sql_tbl[products].productcode LIKE '%".$data["substring"]."%'";
        if(!empty($active_modules['Product_Options'])) {
            $condition[] = "$sql_tbl[variants].productcode LIKE '%".$data["substring"]."%'";
        }
      }


AFTER:
Code:

if (!empty($data["by_fulldescr"])) {
                        if($current_area == 'C' || $current_area == 'P') {
                                $condition[] = "IF($sql_tbl[products_lng].full_descr IS NOT NULL AND $sql_tbl[products_lng].full_descr != '', $sql_tbl[products_lng].full_descr, $sql_tbl[products].fulldescr) LIKE '%".$data["substring"]."%'";
                        } else {
                                $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$data["substring"]."%'";
                        }
                }


and do rest as in the other posts on here :)

jedak 01-24-2006 08:41 PM

Great mod. Thanks, but I 'm having one problem for some reason the sku check box isn't checked by default. So customer have to enter the SKU then after no results are found then they can check the SKU checkbox and searh again to get the product. Any help would be appreciated.

Zak 02-04-2006 09:13 AM

I ran into the same problem on a version 4.11 with the sku box having to be checked after returning no results. I finally figured out that you have to edit the product search form to include the sku input.

Open skin1/customer/search.tpl and find:

<FORM method="POST" action="search.php" name="productsearchform">
<INPUT type="hidden" name="simple_search" value="Y">
<INPUT type="hidden" name="mode" value="search">
<INPUT type="hidden" name="posted_data[by_title]" value="Y">
<INPUT type="hidden" name="posted_data[by_shortdescr]" value="Y">
<INPUT type="hidden" name="posted_data[by_fulldescr]" value="Y">

And add:
<INPUT type="hidden" name="posted_data[by_productcode]" value="Y">

Hope this helps...

manningbrothers 02-06-2006 07:57 AM

I am not seeing Product.php or include/
 
Can someone help - Im trying to track down the locations of these files but do not see Product.php or a directory called include...is this the name of the main directory or is it found for instance in the Customer menu?

Sheffield_Tiger 03-09-2006 02:55 AM

Re: Search Variants in 4.0.10 Code
 
Quote:

Originally Posted by manningbrothers
Can someone help - Im trying to track down the locations of these files but do not see Product.php or a directory called include...is this the name of the main directory or is it found for instance in the Customer menu?


Are you looking in the X-cart webmaster mode, or accesing your site through your ftp client?

The include directory is in the root of your x-cart installation..

so
http://www.mysite.com/include
-or-
http://www.mysite.com/store/include

depending on how and where you chose to install the X-Cart files



Quote:

Originally Posted by mffowler
This is a great mod. I just changed the code to work with 4.0.10. include/search.php now finds variants in a search. Can someone check this to see if it's correct? It does work for me:

include/search.php

find
Code:

      if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["extra_fields"])) {
change to:
Code:

      if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["by_productcode"]) && empty($data["extra_fields"])) {
find
Code:

if (!empty($data["by_fulldescr"])) {
                        if($current_area == 'C' || $current_area == 'P') {
                                $condition[] = "IF($sql_tbl[products_lng].full_descr IS NOT NULL AND $sql_tbl[products_lng].full_descr != '', $sql_tbl[products_lng].full_descr, $sql_tbl[products].fulldescr) LIKE '%".$data["substring"]."%'";
                        } else {
                                $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$data["substring"]."%'";
                        }
                }

change to:
Code:

if (!empty($data["by_fulldescr"])) {
                        if($current_area == 'C' || $current_area == 'P') {
                                $condition[] = "IF($sql_tbl[products_lng].full_descr IS NOT NULL AND $sql_tbl[products_lng].full_descr != '', $sql_tbl[products_lng].full_descr, $sql_tbl[products].fulldescr) LIKE '%".$data["substring"]."%'";
                        if (!empty($data["by_productcode"])){
                        $condition[] = "$sql_tbl[products].productcode LIKE '%".$data["substring"]."%'";
                if(!empty($active_modules['Product_Options'])) {
                    $condition[] = "$sql_tbl[variants].productcode LIKE '%".$data["substring"]."%'";
                }
              }
                        } else {
                                $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$data["substring"]."%'";
                        }
                }


I don't know PHP and wouldn't even call myself a developer. Just a lowly store owner who wants a "search" that works. Can anyone out there tell me if this is correct or what should be modified? It works fine for me and finds variants in a search, but it was trial and error as the original and subsequent code on this post weren't compatible w/ 4.0.10 - categories didn't show up in search (admin).

If you use this, be sure to backup - I only said it works for me, but maybe it could be checked by someone?

Thanks,

Mike


Thanks Mike. After playing around with a few of the suggested changes, and climbing the walls from frustration at the poor X-Cart search (after only using it for 2 days), this did the trick. Spot on!

manningbrothers 03-09-2006 06:04 AM

thanks so much - i forgot i left this post up here and figured it out...have a great day

chrisollar 03-28-2006 12:24 PM

version 4.0.18 gold sku search
 
Quote:

mffowler
include/search.php

find
Code:

if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["extra_fields"])) {

change to:
Code:

if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["by_productcode"]) && empty($data["extra_fields"])) {

Was able to find and use this code (using ftp) but not find the second half of any of the other codes posted. I was able to make the skin mod but never shows up. (I figure that it won't show without other necessary changes.) We have over 30,000 products and our client wants to be able to search by sku. The only thing that happens in search is when we search by generic "calendar" or "post its" etc. not by SKU. Please help a frustrated user! Thanks!

chamberinternet 12-01-2006 04:07 AM

Re: Include search by SKU into basic search in v4
 
This is now supported within v4.1.x ... i didnt need to make any modifications to the php code...

It even searches the Product Variant SKU's too.

Regards

Shafiq :sK

big pine kenny 01-09-2007 04:31 AM

Re: Include search by SKU into basic search in v4
 
I have version 4.1.4 and I type in sku # and it says no product found and takes me to advanced menu and I can check sku and it will bring it up. Is there anyway to do that with out the extra steps?

delsurf 01-15-2007 09:41 PM

Re: Include search by SKU into basic search in v4
 
In 4.1.x just place the following in /skin1/customer/search.tpl

<input type="hidden" name="posted_data[by_sku]" value="Y" />

jfilardo 03-26-2007 07:52 AM

Re: Include search by SKU into basic search in v4
 
Would it be possible for someone to consolidate the code changes necessary in each of the files and templates into one reply. I'm getting very confused trying to figure out what needs to changed in which template to make this mod work in 4.0.19

I would like to be able to add the ability to search the sku/productcode, as well as any 'Extra Fields' in the Product Details page that have been set to show.

Thanks for any help.
J.

jeff819 03-27-2007 08:57 AM

Re: Include search by SKU into basic search in v4
 
I would also like to have the necessary code changes posted into one reply. I have tried different pieces of code throughout this post, but I am still unable to search by SKU in version 4.0.

Thanks,
Jeff

MMANOR 05-17-2007 06:42 PM

Re: Include search by SKU into basic search in v4
 
Hey All,

I have asked a lot of questions, but never have been able to offer any advice. Well now I have a chance too. For those that have version 4.0.19, I was able to get the solution on how to have the main page search also search by sku. You weren't able to do this before, I through extensive searching I was unable to find the answer in the forums. So I spent 25 points (of the 200 we get) and was able to get the fix. It is:

Quote:

If you want to search by SKU from the main page of the store, you should modify the /customer/search.tpl template file eg. via Admin Zone -> 'Edit templates' section and add this code
---
<input type="hidden" name="posted_data[by_sku]" value="on">
---

just after this line:

---
<input type="hidden" name="posted_data[by_shortdescr]" value="Y" />
---

Also please add this code to the /include/search.php:

--
if (!empty($data["by_sku"])) {
if($current_area == 'C' || $current_area == 'P') {
$condition[] = "$sql_tbl[products].productcode LIKE '%".$data["substring"]."%'";
}
}
--

Eg. just after:

--
if (!empty($data["by_shortdescr"])) {
if($current_area == 'C' || $current_area == 'P') {
$condition[] = "IF($sql_tbl[products_lng].descr IS NOT NULL AND $sql_tbl[products_lng].descr != '', $sql_tbl[produ
} else {
$condition[] = "$sql_tbl[products].descr LIKE '%".$data["substring"]."%'";
}
}
--

After this everything should work fine.


shipmerchant 08-31-2007 01:05 PM

Re: Include search by SKU into basic search in v4
 
Quote:

Originally Posted by jedak
Great mod. Thanks, but I 'm having one problem for some reason the sku check box isn't checked by default. So customer have to enter the SKU then after no results are found then they can check the SKU checkbox and searh again to get the product. Any help would be appreciated.


Hi,

Has anyone been able to get this to work on V4.1.8 site? I would appreciate it greatly, dont know why this kind of stuff does not come as a standard.

Regards

MoonDog 09-01-2007 02:58 PM

Re: Include search by SKU into basic search in v4
 
shipmerchant,

In v4.1.8 all you have to do is go to your skin1/customer/search.tpl file and add the following code:

Code:


<input type="hidden" name="posted_data[by_sku]" value="Y" />


after this line of code:

Code:


<input type="hidden" name="posted_data[by_shortdescr]" value="Y" />


and that's it.

You can now do a basic search of SKU numbers and the SKU checkbox is also checked.

Or you can just replace your search.tpl code with the one below (the added line of code is in blue):

Code:


{* $Id: search.tpl,v 1.9.2.1 2006/11/27 14:28:38 max Exp $ *}
<form method="post" action="search.php" name="productsearchform">
<input type="hidden" name="simple_search" value="Y" />
<input type="hidden" name="mode" value="search" />
<input type="hidden" name="posted_data[by_title]" value="Y" />
<input type="hidden" name="posted_data[by_shortdescr]" value="Y" />
<input type="hidden" name="posted_data[by_sku]" value="Y" />
<input type="hidden" name="posted_data[by_fulldescr]" value="Y" />
<input type="hidden" name="posted_data[including]" value="all" />
<table cellpadding="0" cellspacing="0"> 
<tr>
 <td class="TopLabel" style="padding-left: 20px; padding-right: 5px;">{$lng.lbl_search}:</td>
 <td valign="middle"><input type="text" name="posted_data[substring]" size="16" value="{$search_prefilled.substring|escape}" /></td>
 <td valign="middle" style="padding-left: 5px; padding-right: 20px;"><a href="javascript: document.productsearchform.submit();">{include file="buttons/search_head.tpl"}</a></td>
 <td><a href="search.php"><u>{$lng.lbl_advanced_search}</u></a></td>
</tr>
</table>
</form>


- MoonDog -

shipmerchant 09-01-2007 03:08 PM

Re: Include search by SKU into basic search in v4
 
MoonDog,

Thanks so much for you help!

It worked as expected!!!!

Regards.

Vacman 09-02-2007 09:43 AM

Re: Include search by SKU into basic search in v4
 
You folks might also want to check out the Smart Search mod. This add-on is absolutely the best search engine mod for XCart I have found yet.

Automatically do the following to each search query [except advanced searches].
Enable Similar Search Phrases (Other close search terms and AutoCorrect words are displayed at the bottom of each search).
Enable the Did You Mean feature to display close matching queries when there are no results.
Enable Query Expansion when there are less than five results of full-text searches (Similar Search Terms).
Include singular and plural forms of each word in the search query.
Combine words - example: Mc Donald will also search for McDonald. (This can be resource intensive.)
Tag Cloud - Displays a visual design of the most popular words found in the description(s) of the search results.

Just search for Smart Search in the forums.


All times are GMT -8. The time now is 01:06 PM.

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