Last active
December 14, 2015 17:59
-
-
Save Tetsuro/5125588 to your computer and use it in GitHub Desktop.
Script for Limiting Storefront Search to Certain Product Types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" charset="utf-8"> | |
//<![CDATA[ | |
// Including jQuery conditionnally. | |
if (typeof jQuery === 'undefined') { | |
document.write({{ "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" | script_tag | json }}); | |
document.write('<script type="text/javascript">jQuery.noConflict();<\/script>'); | |
} | |
//]]> | |
</script> | |
<script> | |
jQuery(function() { | |
var query; | |
var selection = ""; //We need to assign an empty string, otherwise it'll look for 'undefined' | |
var text; | |
var option; | |
jQuery('#product_type').change(function() { | |
option = jQuery("#product_type").val(); | |
if(option == ""){ | |
selection = ""; | |
} | |
else{ | |
selection = "product_type:" + jQuery("#product_type").val(); | |
} | |
}); | |
jQuery("#top-search-submit").click(function(e) { | |
text = jQuery("#top-search-input").val(); | |
query = selection+ " " + text; | |
jQuery("#param").val(query); | |
}); | |
}); | |
</script> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment