Mooseman
Advanced Member
166 Posts |
Posted - 06/17/2020 : 09:32:05
Within search.php...
If the user search is successful I want a custom message to display above the search returns, but only if there are matches to the search.
Thank you
|
dbdave
ECT Moderator
USA
10276 Posts |
Posted - 06/17/2020 : 12:14:26
Hi Mooseman, I though the code Marshall suggested would do that. Did you try it?
https://www.ecommercetemplates.com/support/topic.asp?TOPIC_ID=112973
Thanks, David
|
Mooseman
Advanced Member
166 Posts |
Posted - 06/17/2020 : 14:14:40
No it's not what am after and mentioned that in the last part of that thread.
It was clear in that post I had not done a good job explaining what I want which is why I resubmitted the post more clearly phrased and to the point.
Reiterating...
Within search.php... If the user search is successful I want a custom message to display above the search returns, but only if there are matches to the search.
Any help would be appreciated.
|
dbdave
ECT Moderator
USA
10276 Posts |
Posted - 06/17/2020 : 14:39:27
Hi, I have an idea that might work. I'll check it out later this evening...
David
|
dbdave
ECT Moderator
USA
10276 Posts |
Posted - 06/17/2020 : 18:56:30
Hi Mooseman, sorry I didn't understand what you were after, but I have something for you.. The nice thing is the cart has a message that shows when no results are found and that message is wrapped in a <div> with a class. With Javascript, it's quite easy to check to see if it exists, and if not, we know some results were returned... Drumroll please...... Here is a nice solution. In the search.php page (this will work for .asp versions of the cart too), you just add a line of html just before the include line that calls up the results, and after that line, you add some javascript like so... <div id="srchmsg"></div> <?php include "vsadmin/inc/incsearch.php" ?> <script> if (document.getElementsByClassName('nosearchresults')[0] == null) { document.getElementById('srchmsg').innerHTML = 'This is a message shows when results are found'; } </script> Of course change the "This is a message shows when results are found" message there to whatever you like. It's also possible to show the term they searched for and to replace this message with something different when no results are returned. We can even hide or replace the "Sorry, no products matched your search" message if needed. You can see a demo here - (No results found) https://www.floridasurpluswarehouse.com/dev/search.php?pg=1&stext=ddd (Yes results found) https://www.floridasurpluswarehouse.com/dev/search.php?pg=1&stext=monitor Thanks, David
Edited by - dbdave on 06/17/2020 18:56:51
|
Mooseman
Advanced Member
166 Posts |
Posted - 06/18/2020 : 11:20:05
Hi Dave,
Thank you for the suggestion. I see in the example URLs that it works fine, but is not working for me. It must be something specific to the site or page.
The site: www.ceramicfasteners.com Search page: https://www.ceramicfasteners.com/buy/search.php
Your code is in there and already displaying even before any search is made. Is the three red, x-small "xxx" on the right margin.
It remains displayed whether the search is successful, or not.
Results - enter: alumina No results - enter: steel
ETC-related code on this page includes, in order of appearance:
<?php session_cache_limiter('none'); session_save_path("/ -- removed for this post -- /cgi-bin/tmp"); session_start(); ob_start(); ?>
<?php include "vsadmin/db_conn_open.php" ?> <?php include "vsadmin/inc/languagefile.php" ?> <?php include "vsadmin/includes.php" ?> <?php $usecsslayout=FALSE; ?> <?php $orsortby = 2; ?> <?php include "vsadmin/inc/incfunctions.php" ?> <?php $cpdcolumns="id,description,price"; ?> <?php $cpdheaders="Part No.,Description,Price Ea."; ?> <?php $orprodsperpage=5000; ?>
<div id="srchmsg" style="float:right; color:red; font-size:x-small"></div>
<?php include "vsadmin/inc/incsearch.php" ?>
<script> if (document.getElementsByClassName('nosearchresults')[0] == null) { document.getElementById('srchmsg').innerHTML = 'XXX'; } </script>
+++++++++++++++++
Please advise if you need to see something else
Thank you
|
Mooseman
Advanced Member
166 Posts |
Posted - 06/18/2020 : 11:50:16
OOPS... missed this bit of ETC-specific code
Appears in the head:
<script type="text/javascript" src="js/ectcart.js"></script>
|
dbdave
ECT Moderator
USA
10276 Posts |
Posted - 06/18/2020 : 12:50:22
Hi, I didn't test, or take into account that it would show when no search was entered. I think I can fix that, and I'll take a closer look this evening when I get home.
I also see you are using table based layouts there, so the class does not exist. What version of the cart are you on?
Thanks, David
Edited by - dbdave on 06/18/2020 12:52:01
|
Mooseman
Advanced Member
166 Posts |
Posted - 06/18/2020 : 13:02:24
Cart version 7.0.4
|
dbdave
ECT Moderator
USA
10276 Posts |
Posted - 06/18/2020 : 14:07:13
Hi, I am guessing you probably don't want to turn on css layouts for the whole site, as I am sure there would be a bit of tweaking to get things looking right, but maybe we can turn it on for the search page without adverse effects.
As a quick test, can you try this line, before the include line on the search.php page to see how the results look?
<?php $usecsslayout=TRUE;?> <?php include "vsadmin/inc/incsearch.php" ?>
If you don't want to test on the live page, just open the search.php in your editor and save it as search1.php, add the change and load it on the server and navigate to that page to see what search results look like. Having the csslayouts will fix part of the issue your having. From there, I will just need to fix the issue of the message showing with no search was performed.
Thanks, David
|
dbdave
ECT Moderator
USA
10276 Posts |
Posted - 06/18/2020 : 18:01:14
Hi, I have this worked out now. For anyone who has css layouts enabled, to avoid the message when no search is performed, then this is the code <div id="srchmsg"></div> <?php include "vsadmin/inc/incsearch.php" ?> <script> if (document.getElementsByClassName('nosearchresults')[0] == null && '<?php print htmlspecials($stext)?>' != '') { document.getElementById('srchmsg').innerHTML = 'This is a message that shows when results are found'; //change your message here } </script> If you are not using css layouts then you can use the following <div id="srchmsg"></div> <?php include "vsadmin/inc/incsearch.php" ?> <script> var strchek = (document.getElementsByClassName('content')[0].innerText); var reschek = strchek.match(/no products matched your search/g); //string to check for if (reschek == null && '<?php print htmlspecials($stext)?>' != '') { document.getElementById('srchmsg').innerHTML = 'This is a message that shows when results are found'; //change your message here } </script> Technically the code above should work on css and non-css layouts with the only caveat being that you have the content area of the page wrapped in a div with the class "content". Try it out and let me know how you get along. I have the 2nd version running on the test site here (Land on search page with no search performed) https://www.floridasurpluswarehouse.com/dev/search.php (No results found) https://www.floridasurpluswarehouse.com/dev/search.php?pg=1&stext=ddd (Yes results found) https://www.floridasurpluswarehouse.com/dev/search.php?pg=1&stext=monitor Thanks, David
|
Mooseman
Advanced Member
166 Posts |
Posted - 06/19/2020 : 07:21:24
AWESOME!
Using your "non ccs layouts" version work perfectly. To be clear it was this one:
<div id="srchmsg"></div>
<?php include "vsadmin/inc/incsearch.php" ?>
<script> var strchek = (document.getElementsByClassName('content')[0].innerText); var reschek = strchek.match(/no products matched your search/g); //string to check for if (reschek == null && '<?php print htmlspecials($stext)?>' != '') { document.getElementById('srchmsg').innerHTML = 'This is a message that shows when results are found'; //change your message here } </script>
FYI... My page content area NOT being enclosed in a div with the class "content" did not seem to matter!
Go to: https://www.ceramicfasteners.com/buy/search.php
To test, use:
For Results, enter: alumina For No results, enter: steel
Look for red, x-small "XXX" on the right margin to appear ONLY with results.
Thanks again for all your help.
|
dbdave
ECT Moderator
USA
10276 Posts |
Posted - 06/19/2020 : 07:39:09
quote: My page content area NOT being enclosed in a div with the class "content" did not seem to matter!
I check your page before working up that snipplet, and it actually does have the "content" class there. I'm glad I could help out. Thanks, David
|
|
|